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
34 def set_language(lang)
37 # We may be on an old installation, so on the first run read non-language-specific larts
38 unless defined?(@oldlart)
39 @oldlart = "#{@bot.botclass}/lart/larts"
40 @oldpraise = "#{@bot.botclass}/lart/praise"
43 @lartfile.replace "#{@bot.botclass}/lart/larts-#{lang}"
44 @praisefile.replace "#{@bot.botclass}/lart/praises-#{lang}"
47 if File.exists? @lartfile
48 IO.foreach(@lartfile) { |line|
51 elsif File.exists? @oldlart
52 IO.foreach(@oldlart) { |line|
56 if File.exists? @praisefile
57 IO.foreach(@praisefile) { |line|
58 @praises << line.chomp
60 elsif File.exists? @oldpraise
61 IO.foreach(@oldpraise) { |line|
62 @praises << line.chomp
69 return unless @changed
70 Dir.mkdir("#{@bot.botclass}/lart") if not FileTest.directory? "#{@bot.botclass}/lart"
71 # TODO implement safe saving here too
72 Utils.safe_save(@lartfile) { |file|
75 Utils.safe_save(@praisefile) { |file|
81 def help(plugin, topic="")
82 "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."
85 def handle_lart(m, params)
86 lart = @larts[get_msg_idx(@larts.length)]
88 m.reply "I dunno any larts"
91 who = params[:who].to_s
95 reason = "for trying to make me lart myself"
97 lart = replace_who lart, who
98 lart << " #{reason}" unless reason.empty?
103 def handle_praise(m, params)
104 praise = @praises[get_msg_idx(@praises.length)]
106 m.reply "I dunno any praises"
109 who = params[:who].to_s
110 reason = params[:why]
111 if who == m.sourcenick
112 params[:why] = "for praising himself"
113 handle_lart(m, params)
116 praise = replace_who praise, who
117 praise << " #{reason}" unless reason.empty?
122 def handle_addlart(m, params)
123 @larts << params[:lart]
128 def handle_rmlart(m, params)
129 @larts.delete params[:lart]
134 def handle_addpraise(m, params)
135 @praises << params[:praise]
140 def handle_rmpraise(m, params)
141 @praises.delete params[:praise]
146 # The following are utils for larts/praises
147 def replace_who(msg, nick)
148 msg.gsub(/<who>/i, "#{nick}")
157 plugin = LartPlugin.new
159 plugin.map "lart *who [*why]", :requirements => { :why => /(?:for|because)\s+.*/ }, :action => :handle_lart
160 plugin.map "praise *who [*why]", :requirements => { :why => /(?:for|because)\s+.*/ }, :action => :handle_praise
162 plugin.map "addlart *lart", :action => :handle_addlart
163 plugin.map "addpraise *praise", :action => :handle_addpraise
165 plugin.map "rmlart *lart", :action => :handle_rmlart
166 plugin.map "rmpraise *praise", :action => :handle_rmpraise