-# Original Author:
-# Michael Brailsford <brailsmt@yahoo.com>
-# aka brailsmt
-# Author: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
-# Purpose: Provide for humorous larts and praises
-# Original Copyright:
-# 2002 Michael Brailsford. All rights reserved.
-# Copyright: 2006 Giuseppe Bilotta. All rights reserved.
-# License: This plugin is licensed under the BSD license. The terms of
-# which follow.
+#-- vim:sw=2:et
+#++
#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
+# :title: lart/praise plugin for rbot
#
-# 1. Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
+# Author:: Michael Brailsford <brailsmt@yahoo.com> aka brailsmt
+# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
#
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
+# Copyright:: (C) 2002 Michael Brailsford. All rights reserved.
+# Copyright:: (C) 2006 Giuseppe Bilotta. All rights reserved.
+#
+# License:: This plugin is licensed under the BSD license. The terms of
+# which follow.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# Purpose:: Provide for humorous larts and praises
class LartPlugin < Plugin
end
def handle_addlart(m, params)
- @larts << params[:lart]
+ @larts << params[:lart].to_s
@changed = true
m.okay
end
def handle_rmlart(m, params)
- @larts.delete params[:lart]
+ @larts.delete params[:lart].to_s
@changed = true
m.okay
end
+ def handle_listlart(m, params)
+ rx = Regexp.new(params[:lart].to_s, true)
+ list = @larts.grep(rx)
+ unless list.empty?
+ m.reply list.join(" | "), :split_at => /\s+\|\s+/
+ else
+ m.reply "no lart found matching #{params[:lart]}"
+ end
+ end
+
def handle_addpraise(m, params)
- @praises << params[:praise]
+ @praises << params[:praise].to_s
@changed = true
m.okay
end
def handle_rmpraise(m, params)
- @praises.delete params[:praise]
+ @praises.delete params[:praise].to_s
@changed = true
m.okay
end
+ def handle_listpraise(m, params)
+ rx = Regexp.new(params[:praise].to_s, true)
+ list = @praises.grep(rx)
+ unless list.empty?
+ m.reply list.join(" | "), :split_at => /\s+\|\s+/
+ else
+ m.reply "no praise found matching #{params[:praise]}"
+ end
+ end
+
# The following are utils for larts/praises
def replace_who(msg, nick)
msg.gsub(/<who>/i, "#{nick}")
plugin.map "rmlart *lart", :action => :handle_rmlart
plugin.map "rmpraise *praise", :action => :handle_rmpraise
+
+plugin.map "listlart *lart", :action => :handle_listlart
+plugin.map "listpraise *praise", :action => :handle_listpraise