1 # Author: Michael Brailsford <brailsmt@yahoo.com>
3 # Purpose: Provide for humorous larts and praises
4 # Copyright: 2002 Michael Brailsford. All rights reserved.
5 # License: This plugin is licensed under the BSD license. The terms of
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 class LartPlugin < Plugin
21 # Keep a 1:1 relation between commands and handlers
23 "lart" => "handle_lart",
24 "praise" => "handle_praise",
25 "addlart" => "handle_addlart",
26 "rmlart" => "handle_rmlart",
27 "addpraise" => "handle_addpraise",
28 "rmpraise" => "handle_rmpraise"
40 #read in the lart and praise files
41 if File.exists? "#{@bot.botclass}/lart/larts"
42 IO.foreach("#{@bot.botclass}/lart/larts") { |line|
46 if File.exists? "#{@bot.botclass}/lart/praises"
47 IO.foreach("#{@bot.botclass}/lart/praises") { |line|
48 @praises << line.chomp
59 Dir.mkdir("#{@bot.botclass}/lart") if not FileTest.directory? "#{@bot.botclass}/lart"
60 File.open("#{@bot.botclass}/lart/larts", "w") { |file|
63 File.open("#{@bot.botclass}/lart/praises", "w") { |file|
71 m.reply "What a crazy fool! Did you mean |help stats?"
75 meth = self.method(@@handlers[m.plugin])
76 meth.call(m) if(@bot.auth.allow?(m.plugin, m.source, m.replyto))
80 def help(plugin, topic="")
81 "Lart: The lart plugin allows you to punish/praise someone in the channel. You can also add new punishments and new praises as well as delete them. For the curious, LART is an acronym for Luser Attitude Readjustment Tool.\nUsage: punish/lart <nick> <reason> -- punishes <nick> for <reason>. The reason is optional.\n praise <nick> <reason> -- praises <nick> for <reason>. The reason is optional.\n mod[lart|punish|praise] [add|remove] -- Add or remove a lart or praise."
84 # The following are command handlers {{{
87 for_idx = m.params =~ /\s+\bfor\b/
89 nick = m.params[0, for_idx]
93 lart = @larts[get_msg_idx(@larts.length)]
95 m.reply "I dunno any larts"
99 lart = replace_who lart, m.sourcenick
100 lart << " for trying to make me lart myself"
102 lart = replace_who lart, nick
103 lart << m.params[for_idx, m.params.length] if for_idx
106 @bot.action m.replyto, lart
111 for_idx = m.params =~ /\s+\bfor\b/
113 nick = m.params[0, for_idx]
117 praise = @praises[get_msg_idx(@praises.length)]
119 m.reply "I dunno any praises"
123 if nick == m.sourcenick
124 praise = @larts[get_msg_idx(@larts.length)]
125 praise = replace_who praise, nick
127 praise = replace_who praise, nick
128 praise << m.params.gsub(/#{nick}/, "")
131 @bot.action m.replyto, praise
135 def handle_addlart(m)
142 @larts.delete m.params
147 def handle_addpraise(m)
153 def handle_rmpraise(m)
154 @praises.delete m.params
160 # The following are utils for larts/praises {{{
162 def replace_who(msg, nick)
163 msg.gsub(/<who>/i, "#{nick}")
173 plugin = LartPlugin.new
174 plugin.register("lart")
175 plugin.register("praise")
177 plugin.register("addlart")
178 plugin.register("addpraise")
180 plugin.register("rmlart")
181 plugin.register("rmpraise")