summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-14 22:00:08 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-14 22:00:08 +0000
commitd29df50ddaf32536b105decefb135a0b86ee937f (patch)
treeeaf5505ba5a8b569aefdb157eff80cf902fe444d /data/rbot
parentad78fb47422664c9ce24a3b62194e42974274af7 (diff)
Modernize/optimize/cleanup a bunch of plugins
Remove some unnecessary plugin.register() calls, replace other by plugin.map() calls. Also use e.g. Array#pick_one instead of ar[rand(ar.length)]
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/autorejoin.rb1
-rw-r--r--data/rbot/plugins/debugger.rb2
-rw-r--r--data/rbot/plugins/excuse.rb8
-rw-r--r--data/rbot/plugins/figlet.rb26
-rw-r--r--data/rbot/plugins/grouphug.rb41
-rw-r--r--data/rbot/plugins/imdb.rb14
-rw-r--r--data/rbot/plugins/insult.rb69
-rw-r--r--data/rbot/plugins/roshambo.rb68
-rw-r--r--data/rbot/plugins/script.rb2
-rw-r--r--data/rbot/plugins/seen.rb16
10 files changed, 118 insertions, 129 deletions
diff --git a/data/rbot/plugins/autorejoin.rb b/data/rbot/plugins/autorejoin.rb
index f057a659..4b657274 100644
--- a/data/rbot/plugins/autorejoin.rb
+++ b/data/rbot/plugins/autorejoin.rb
@@ -19,4 +19,3 @@ class AutoRejoinPlugin < Plugin
end
plugin = AutoRejoinPlugin.new
-plugin.register("autorejoin")
diff --git a/data/rbot/plugins/debugger.rb b/data/rbot/plugins/debugger.rb
index f0ff0c03..2851d6a9 100644
--- a/data/rbot/plugins/debugger.rb
+++ b/data/rbot/plugins/debugger.rb
@@ -120,7 +120,7 @@ end
plugin = DebugPlugin.new
-plugin.register( "debug" )
+
plugin.default_auth( 'start', false )
plugin.default_auth( 'stop', false )
plugin.default_auth( 'dumpstrings', false )
diff --git a/data/rbot/plugins/excuse.rb b/data/rbot/plugins/excuse.rb
index 38e85ad6..ad0e8334 100644
--- a/data/rbot/plugins/excuse.rb
+++ b/data/rbot/plugins/excuse.rb
@@ -459,12 +459,12 @@ class ExcusePlugin < Plugin
def help(plugin, topic="")
"excuse => supply a random excuse"
end
- def privmsg(m)
- excuse = @@excuses[rand(@@excuses.length)]
- m.reply excuse
+
+ def excuse(m, params)
+ m.reply @@excuses.pick_one
end
end
plugin = ExcusePlugin.new
-plugin.register("excuse")
+plugin.map "excuse"
diff --git a/data/rbot/plugins/figlet.rb b/data/rbot/plugins/figlet.rb
index f82288eb..598adfaf 100644
--- a/data/rbot/plugins/figlet.rb
+++ b/data/rbot/plugins/figlet.rb
@@ -4,21 +4,19 @@ MAX_WIDTH=68
class FigletPlugin < Plugin
def help(plugin, topic="")
- "figlet [<message>] => print using figlet"
+ "figlet <message> => print using figlet"
end
- def privmsg(m)
- case m.params
- when nil
- m.reply "incorrect usage: " + help(m.plugin)
- return
- when (/^-/)
- m.reply "incorrect usage: " + help(m.plugin)
- return
- else
- m.reply Utils.safe_exec("/usr/bin/figlet", "-k", "-w", "#{MAX_WIDTH}", "-f", DEFAULT_FONT, m.params)
- return
- end
+
+ def figlet(m, params)
+ message = params[:message].to_s
+ if message =~ /^-/
+ m.reply "the message can't start with a - sign"
+ return
+ end
+ m.reply Utils.safe_exec("/usr/bin/figlet", "-k", "-w", "#{MAX_WIDTH}", "-f", DEFAULT_FONT, message)
+ return
end
end
+
plugin = FigletPlugin.new
-plugin.register("figlet")
+plugin.map "figlet *message"
diff --git a/data/rbot/plugins/grouphug.rb b/data/rbot/plugins/grouphug.rb
index 53fc7f0a..87a7e32c 100644
--- a/data/rbot/plugins/grouphug.rb
+++ b/data/rbot/plugins/grouphug.rb
@@ -6,31 +6,30 @@ require "net/http"
class GrouphugPlugin < Plugin
- def help( plugin, topic="" )
- "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess <number>' for specific one."
+ def help( plugin, topic="" )
+ return "Grouphug plugin. Confess! Usage: 'confess' for random confession, 'confess <number>' for specific one."
+ end
+
+ def confess(m, params)
+ path = "random"
+ path = "confessions/#{params[:num]}" if params[:num]
+ begin
+ data = bot.httputil.get_cached(URI.parse("http://grouphug.us/#{path}"))
+
+ reg = Regexp.new( '(<td class="conf-text")(.*?)(<p>)(.*?)(</p>)', Regexp::MULTILINE )
+ confession = reg.match( data )[4].ircify_html
+ confession = "no confession ##{params[:num]} found" if confession.empty? and params[:num]
+
+ m.reply confession
+ rescue
+ m.reply "failed to connect to grouphug.us"
end
-
- def privmsg( m )
- path = "/random"
- path = "/confessions/#{m.params()}" if m.params()
- begin
- data = bot.httputil.get_cached(URI.parse("http://grouphug.us/#{path}"))
-
- reg = Regexp.new( '(<td class="conf-text")(.*?)(<p>)(.*?)(</p>)', Regexp::MULTILINE )
- confession = reg.match( data )[4]
- confession.gsub!( /<.*?>/, "" ) # Remove html tags
- confession.gsub!( "\t", "" ) # Remove tab characters
-
- @bot.say(m.replyto, confession)
- rescue
- m.reply "failed to connect to grouphug.us"
- end
- end
+ end
end
plugin = GrouphugPlugin.new
-plugin.register("grouphug")
-plugin.register("confess")
+plugin.map "grouphug [:num]", :action => :confess, :requirements => { :num => /\d+/ }
+plugin.map "confess [:num]", :action => :confess, :requirements => { :num => /\d+/ }
diff --git a/data/rbot/plugins/imdb.rb b/data/rbot/plugins/imdb.rb
index 432d0efc..48c49dc3 100644
--- a/data/rbot/plugins/imdb.rb
+++ b/data/rbot/plugins/imdb.rb
@@ -70,16 +70,12 @@ class ImdbPlugin < Plugin
"imdb <string> => search http://www.imdb.org for <string>"
end
- def privmsg(m)
- unless(m.params && m.params.length > 0)
- m.reply "incorrect usage: " + help(m.plugin)
- return
- end
-
+ def imdb(m, params)
+ what = params[:what].to_s
i = Imdb.new(@bot)
- info = i.info(m.params)
+ info = i.info(what)
if !info
- m.reply "Nothing found for #{m.params}"
+ m.reply "Nothing found for #{what}"
return nil
end
m.reply "#{info[1]} : #{info[0]}"
@@ -88,5 +84,5 @@ class ImdbPlugin < Plugin
end
plugin = ImdbPlugin.new
-plugin.register("imdb")
+plugin.map "imdb *what"
diff --git a/data/rbot/plugins/insult.rb b/data/rbot/plugins/insult.rb
index f7217756..0c449654 100644
--- a/data/rbot/plugins/insult.rb
+++ b/data/rbot/plugins/insult.rb
@@ -208,58 +208,53 @@ class InsultPlugin < Plugin
]
def help(plugin, topic="")
- if(plugin == "insult")
- return "insult me|<person> => insult you or <person>"
- elsif(plugin == "msginsult")
- return "msginsult <nick> => insult <nick> via /msg"
- else
- return "insult module topics: msginsult, insult"
- end
+ return "[msg]insult me|<person> => insult you or <person>. msginsult insults in private"
end
- def name
- "insult"
- end
- def privmsg(m)
- suffix=""
- unless(m.params)
- m.reply "incorrect usage: " + help(m.plugin)
- return
- end
- msgto = m.channel
- if(m.plugin =~ /^msginsult$/)
- prefix = "you are "
- if (m.params =~ /^#/)
- prefix += "all "
- end
- msgto = m.params
- suffix = " (from #{m.sourcenick})"
- elsif(m.params =~ /^me$/)
+
+ def insult(m, params)
+ who = params[:who]
+ who = m.sourcenick if ["me", @bot.nick].include?(who)
+
+ priv = params[:priv] || m.plugin == "msginsult"
+
+ case who
+ when /^#/
+ prefix = "you are all "
+ when m.sourcenick
prefix = "you are "
else
- who = m.params
- if (who == @bot.nick)
- who = m.sourcenick
- end
- prefix = "#{who} is "
+ prefix = priv ? "you are " : "#{who} is "
end
+
+ suffix = ""
+
+ if priv
+ msgto = who
+ suffix = " (from #{m.sourcenick})" unless who == m.sourcenick
+ else
+ msgto = m.channel
+ end
+
insult = generate_insult
@bot.say msgto, prefix + insult + suffix
end
+
def generate_insult
- adj = @@adj[rand(@@adj.length)]
+ adj = @@adj.pick_one
adj2 = ""
loop do
- adj2 = @@adj[rand(@@adj.length)]
+ adj2 = @@adj.pick_one
break if adj2 != adj
end
- amt = @@amt[rand(@@amt.length)]
- noun = @@noun[rand(@@noun.length)]
+ amt = @@amt.pick_one
+ noun = @@noun.pick_one
start = "a "
- start = "an " if ['a','e','i','o','u'].include?(adj[0].chr)
+ start = "an " if ['a','e','i','o','u'].include?(adj[0,1])
"#{start}#{adj} #{amt} of #{adj2} #{noun}"
end
end
+
plugin = InsultPlugin.new
-plugin.register("insult")
-plugin.register("msginsult")
+plugin.map "insult :who [:priv]", :action => :insult, :requirements => { :priv => /in private/ }
+plugin.map "msginsult :who", :action => :insult
diff --git a/data/rbot/plugins/roshambo.rb b/data/rbot/plugins/roshambo.rb
index 4f20fb15..7f776c39 100644
--- a/data/rbot/plugins/roshambo.rb
+++ b/data/rbot/plugins/roshambo.rb
@@ -1,54 +1,56 @@
+#-- vim:sw=2:et
+#++
# Play the game of roshambo (rock-paper-scissors)
# Copyright (C) 2004 Hans Fugal
# Distributed under the same license as rbot itself
+
require 'time'
+
class RoshamboPlugin < Plugin
+
def initialize
super
@scoreboard = {}
+ @plays = [:rock, :paper, :scissor]
+ @beats = { :rock => :scissors, :paper => :rock, :scissors => :paper}
end
+
def help(plugin, topic="")
- "roshambo <rock|paper|scissors> => play roshambo"
+ "roshambo <rock|paper|scissors> or rps <rock|paper|scissors> => play roshambo"
end
- def privmsg(m)
+
+ def rps(m, params)
# simultaneity
- choice = choose
+ choice = @plays.pick_one
# init scoreboard
- if (not @scoreboard.has_key?(m.sourcenick) or (Time.now - @scoreboard[m.sourcenick]['timestamp']) > 3600)
- @scoreboard[m.sourcenick] = {'me'=>0,'you'=>0,'timestamp'=>Time.now}
+ if not @scoreboard.has_key?(m.sourcenick) or (Time.now - @scoreboard[m.sourcenick]['timestamp']) > 3600
+ @scoreboard[m.sourcenick] = { 'me' => 0, 'you' => 0, 'timestamp' => Time.now }
end
- case m.params
- when 'rock','paper','scissors'
- s = score(choice,m.params)
- @scoreboard[m.sourcenick]['timestamp'] = Time.now
- myscore=@scoreboard[m.sourcenick]['me']
- yourscore=@scoreboard[m.sourcenick]['you']
- case s
- when 1
- yourscore=@scoreboard[m.sourcenick]['you'] += 1
- m.reply "#{choice}. You win. Score: me #{myscore} you #{yourscore}"
- when 0
- m.reply "#{choice}. We tie. Score: me #{myscore} you #{yourscore}"
- when -1
- myscore=@scoreboard[m.sourcenick]['me'] += 1
- m.reply "#{choice}! I win! Score: me #{myscore} you #{yourscore}"
- end
- else
- m.reply "incorrect usage: " + help(m.plugin)
+ play = params[:play].to_sym
+ s = score(choice, play)
+ @scoreboard[m.sourcenick]['timestamp'] = Time.now
+ myscore=@scoreboard[m.sourcenick]['me']
+ yourscore=@scoreboard[m.sourcenick]['you']
+ case s
+ when 1
+ yourscore = @scoreboard[m.sourcenick]['you'] += 1
+ m.reply "#{choice}. You win. Score: me #{myscore} you #{yourscore}"
+ when 0
+ m.reply "#{choice}. We tie. Score: me #{myscore} you #{yourscore}"
+ when -1
+ myscore = @scoreboard[m.sourcenick]['me'] += 1
+ m.reply "#{choice}! I win! Score: me #{myscore} you #{yourscore}"
end
end
-
- def choose
- ['rock','paper','scissors'][rand(3)]
- end
- def score(a,b)
- beats = {'rock'=>'scissors', 'paper'=>'rock', 'scissors'=>'paper'}
- return -1 if beats[a] == b
- return 1 if beats[b] == a
+
+ def score(a, b)
+ return -1 if @beats[a] == b
+ return 1 if @beats[b] == a
return 0
end
end
+
plugin = RoshamboPlugin.new
-plugin.register("roshambo")
-plugin.register("rps")
+plugin.map "roshambo :play", :action => :rps, :requirements => { :play => /rock|paper|scissors/ }
+plugin.map "rps :play", :action => :rps, :requirements => { :play => /rock|paper|scissors/ }
diff --git a/data/rbot/plugins/script.rb b/data/rbot/plugins/script.rb
index 4509c71b..3976517f 100644
--- a/data/rbot/plugins/script.rb
+++ b/data/rbot/plugins/script.rb
@@ -158,7 +158,7 @@ end
plugin = ScriptPlugin.new
-plugin.register( "script" )
+
plugin.default_auth( 'edit', false )
plugin.default_auth( 'eval', false )
plugin.default_auth( 'echo', false )
diff --git a/data/rbot/plugins/seen.rb b/data/rbot/plugins/seen.rb
index aec5a064..a697d19b 100644
--- a/data/rbot/plugins/seen.rb
+++ b/data/rbot/plugins/seen.rb
@@ -67,20 +67,20 @@ class SeenPlugin < Plugin
ret += Utils.secs_to_string(ago) + " ago, "
end
- case saw.type
- when "PUBLIC"
+ case saw.type.to_sym
+ when :PUBLIC
ret += "saying #{saw.message}"
- when "ACTION"
+ when :ACTION
ret += "doing #{saw.nick} #{saw.message}"
- when "NICK"
+ when :NICK
ret += "changing nick from #{saw.nick} to #{saw.message}"
- when "PART"
+ when :PART
ret += "leaving #{saw.where}"
- when "JOIN"
+ when :JOIN
ret += "joining #{saw.where}"
- when "QUIT"
+ when :QUIT
ret += "quitting IRC (#{saw.message})"
- when "TOPIC"
+ when :TOPIC
ret += "changing the topic of #{saw.where} to #{saw.message}"
end
end