4 # :title: lart/praise plugin for rbot
6 # Author:: Michael Brailsford <brailsmt@yahoo.com> aka brailsmt
7 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
9 # Copyright:: (C) 2002 Michael Brailsford. All rights reserved.
10 # Copyright:: (C) 2006 Giuseppe Bilotta. All rights reserved.
12 # License:: This plugin is licensed under the BSD license. The terms of
15 # Redistribution and use in source and binary forms, with or without
16 # modification, are permitted provided that the following conditions
19 # 1. Redistributions of source code must retain the above copyright notice,
20 # this list of conditions and the following disclaimer.
22 # 2. Redistributions in binary form must reproduce the above copyright
23 # notice, this list of conditions and the following disclaimer in the
24 # documentation and/or other materials provided with the distribution.
26 # Purpose:: Provide for humorous larts and praises
28 class LartPlugin < Plugin
39 def set_language(lang)
42 # We may be on an old installation, so on the first run read non-language-specific larts
43 unless defined?(@oldlart)
44 @oldlart = datafile 'larts'
45 @oldpraise = datafile 'praise'
48 @lartfile.replace(datafile("larts-#{lang}"))
49 @praisefile.replace(datafile("praises-#{lang}"))
52 if File.exists? @lartfile
53 IO.foreach(@lartfile) { |line|
56 elsif File.exists? @oldlart
57 IO.foreach(@oldlart) { |line|
61 if File.exists? @praisefile
62 IO.foreach(@praisefile) { |line|
63 @praises << line.chomp
65 elsif File.exists? @oldpraise
66 IO.foreach(@oldpraise) { |line|
67 @praises << line.chomp
74 return unless @changed
75 Dir.mkdir(datafile) unless FileTest.directory? datafile
76 Utils.safe_save(@lartfile) { |file|
79 Utils.safe_save(@praisefile) { |file|
85 def help(plugin, topic="")
86 "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."
89 def handle_lart(m, params)
90 lart = @larts[get_msg_idx(@larts.length)]
92 m.reply "I dunno any larts"
95 who = params[:who].to_s
102 reason = "for trying to make me lart myself"
104 lart = replace_who lart, who
105 lart << " #{reason}" unless reason.empty?
110 def handle_praise(m, params)
111 praise = @praises[get_msg_idx(@praises.length)]
113 m.reply "I dunno any praises"
116 who = params[:who].to_s
117 reason = params[:why]
118 if who == m.sourcenick || who == "me"
119 params[:who] = m.sourcenick
120 params[:why] = "for praising himself"
121 handle_lart(m, params)
124 praise = replace_who praise, who
125 praise << " #{reason}" unless reason.empty?
130 def handle_addlart(m, params)
131 @larts << params[:lart].to_s
136 def handle_rmlart(m, params)
137 @larts.delete params[:lart].to_s
142 def handle_listlart(m, params)
143 rx = Regexp.new(params[:lart].to_s, true)
144 list = @larts.grep(rx)
146 m.reply list.join(" | "), :split_at => /\s+\|\s+/
148 m.reply "no lart found matching #{params[:lart]}"
152 def handle_addpraise(m, params)
153 @praises << params[:praise].to_s
158 def handle_rmpraise(m, params)
159 @praises.delete params[:praise].to_s
164 def handle_listpraise(m, params)
165 rx = Regexp.new(params[:praise].to_s, true)
166 list = @praises.grep(rx)
168 m.reply list.join(" | "), :split_at => /\s+\|\s+/
170 m.reply "no praise found matching #{params[:praise]}"
174 # The following are utils for larts/praises
175 def replace_who(msg, nick)
176 msg.gsub(/<who>/i, "#{nick}")
185 plugin = LartPlugin.new
187 plugin.map "lart *who [*why]", :requirements => { :why => /(?:for|because)\s+.*/ }, :action => :handle_lart
188 plugin.map "praise *who [*why]", :requirements => { :why => /(?:for|because)\s+.*/ }, :action => :handle_praise
190 plugin.map "addlart *lart", :action => :handle_addlart
191 plugin.map "addpraise *praise", :action => :handle_addpraise
193 plugin.map "rmlart *lart", :action => :handle_rmlart
194 plugin.map "rmpraise *praise", :action => :handle_rmpraise
196 plugin.map "listlart *lart", :action => :handle_listlart
197 plugin.map "listpraise *praise", :action => :handle_listpraise