2 # Michael Brailsford <brailsmt@yahoo.com>
4 # Author: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
5 # Purpose: Provide for humorous larts and praises
7 # 2002 Michael Brailsford. All rights reserved.
8 # Copyright: 2006 Giuseppe Bilotta. All rights reserved.
9 # License: This plugin is licensed under the BSD license. The terms of
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions
16 # 1. Redistributions of source code must retain the above copyright notice,
17 # this list of conditions and the following disclaimer.
19 # 2. Redistributions in binary form must reproduce the above copyright
20 # notice, this list of conditions and the following disclaimer in the
21 # documentation and/or other materials provided with the distribution.
23 class LartPlugin < Plugin
25 # Keep a 1:1 relation between commands and handlers
27 "lart" => "handle_lart",
28 "praise" => "handle_praise",
29 "addlart" => "handle_addlart",
30 "rmlart" => "handle_rmlart",
31 "addpraise" => "handle_addpraise",
32 "rmpraise" => "handle_rmpraise"
48 def set_language(lang)
50 @lartfile = "#{@bot.botclass}/lart/larts-#{lang}"
51 @praisefile = "#{@bot.botclass}/lart/praises-#{lang}"
52 # We may be on an old installation, so on the first run read non-language-specific larts
53 @bulart = "#{@bot.botclass}/lart/larts"
54 @bupraise = "#{@bot.botclass}/lart/praise"
57 if File.exists? @lartfile
58 IO.foreach(@lartfile) { |line|
61 elsif File.exists? @bulart
62 IO.foreach(@bulart) { |line|
66 if File.exists? @praisefile
67 IO.foreach(@praisefile) { |line|
68 @praises << line.chomp
70 elsif File.exists? @bupraise
71 IO.foreach(@bupraise) { |line|
72 @praises << line.chomp
81 return if @lartfile.nil? and @praisefile.nil?
82 Dir.mkdir("#{@bot.botclass}/lart") if not FileTest.directory? "#{@bot.botclass}/lart"
83 # TODO implement safe saving here too
84 Utils.safe_save(@lartfile) { |file|
87 Utils.safe_save(@praisefile) { |file|
94 m.reply "What a crazy fool! Did you mean |help stats?"
98 meth = self.method(@@handlers[m.plugin])
99 meth.call(m) if(@bot.auth.allow?(m.plugin, m.source, m.replyto))
102 def help(plugin, topic="")
103 "Lart: The lart plugin allows you to lart/praise someone in the channel. You can also add new larts and new praises as well as delete them. For the curious, LART is an acronym for Luser Attitude Readjustment Tool. Usage: lart <who> [<reason>] -- larts <who> for <reason>. praise <who> [<reason>] -- praises <who> for <reason>. [add|rm][lart|praise] -- Add or remove a lart or praise."
106 # The following are command handler
109 for_idx = m.params =~ /\s+\bfor\b/
111 nick = m.params[0, for_idx]
115 lart = @larts[get_msg_idx(@larts.length)]
117 m.reply "I dunno any larts"
121 lart = replace_who lart, m.sourcenick
122 lart << " for trying to make me lart myself"
124 lart = replace_who lart, nick
125 lart << m.params[for_idx, m.params.length] if for_idx
128 @bot.action m.replyto, lart
132 for_idx = m.params =~ /\s+\bfor\b/
134 nick = m.params[0, for_idx]
138 praise = @praises[get_msg_idx(@praises.length)]
140 m.reply "I dunno any praises"
144 if nick == m.sourcenick
145 praise = @larts[get_msg_idx(@larts.length)]
146 praise = replace_who praise, nick
148 praise = replace_who praise, nick
149 praise << m.params.gsub("#{nick}", "")
152 @bot.action m.replyto, praise
155 def handle_addlart(m)
161 @larts.delete m.params
165 def handle_addpraise(m)
170 def handle_rmpraise(m)
171 @praises.delete m.params
175 # The following are utils for larts/praises
176 def replace_who(msg, nick)
177 msg.gsub(/<who>/i, "#{nick}")
185 plugin = LartPlugin.new
186 plugin.register("lart")
187 plugin.register("praise")
189 plugin.register("addlart")
190 plugin.register("addpraise")
192 plugin.register("rmlart")
193 plugin.register("rmpraise")