diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2004-10-09 01:51:05 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2004-10-09 01:51:05 +0000 |
commit | 0f3e302547363ea237454dda891ddb5de1be4476 (patch) | |
tree | ec45be24a669ee28b5e2da4ff65e39265a418e0b /contrib/plugins |
initial import of rbot
Diffstat (limited to 'contrib/plugins')
-rw-r--r-- | contrib/plugins/figlet.rb | 20 | ||||
-rw-r--r-- | contrib/plugins/ri.rb | 83 | ||||
-rw-r--r-- | contrib/plugins/stats.rb | 232 | ||||
-rw-r--r-- | contrib/plugins/vandale.rb | 49 |
4 files changed, 384 insertions, 0 deletions
diff --git a/contrib/plugins/figlet.rb b/contrib/plugins/figlet.rb new file mode 100644 index 00000000..ce17fe71 --- /dev/null +++ b/contrib/plugins/figlet.rb @@ -0,0 +1,20 @@ +class FigletPlugin < Plugin + def help(plugin, topic="") + "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", "-f", "mini", m.params) + return + end + end +end +plugin = FigletPlugin.new +plugin.register("figlet") diff --git a/contrib/plugins/ri.rb b/contrib/plugins/ri.rb new file mode 100644 index 00000000..99292f1c --- /dev/null +++ b/contrib/plugins/ri.rb @@ -0,0 +1,83 @@ +# Author: Michael Brailsford <brailsmt@yahoo.com> +# aka brailsmt +# Purpose: To respond to requests for information from the ri command line +# utility. + +class RiPlugin < Plugin + + @@handlers = { + "ri" => "ri_handler", + "msgri" => "msgri_handler" + } + + #{{{ + def initialize + super + @cache = Hash.new + end + #}}} + #{{{ + def privmsg(m) + if not m.params + m.reply "uhmm... whatever" + return + end + + meth = self.method(@@handlers[m.plugin]) + meth.call(m) + end + #}}} + #{{{ + def cleanup + @cache = nil + end + #}}} + #{{{ + def ri_handler(m) + response = "" + if @cache[m.params] + response = @cache[m.params] + else + IO.popen("-") {|p| + if(p) + response = p.readlines.join "\n" + @cache[m.params] = response + else + $stderr = $stdout + exec("ri", m.params) + end + } + @cache[m.params] = response + end + + @bot.say m.sourcenick, response + m.reply "Finished \"ri #{m.params}\"" + end + #}}} + #{{{ + def msgri_handler(m) + response = "" + tell_nick, query = m.params.split() + if @cache[query] + response = @cache[query] + else + IO.popen("-") {|p| + if(p) + response = p.readlines.join "\n" + @cache[m.params] = response + else + $stderr = $stdout + exec("ri", query) + end + } + @cache[query] = response + end + + @bot.say tell_nick, response + m.reply "Finished telling #{tell_nick} about \"ri #{query}\"" + end + #}}} +end +plugin = RiPlugin.new +plugin.register("ri") +plugin.register("msgri") diff --git a/contrib/plugins/stats.rb b/contrib/plugins/stats.rb new file mode 100644 index 00000000..4cafbbe9 --- /dev/null +++ b/contrib/plugins/stats.rb @@ -0,0 +1,232 @@ +# Author: Michael Brailsford <brailsmt@yahoo.com> +# aka brailsmt +# Purpose: Provides the ability to track various tokens that are spoken in a +# channel. +# Copyright: 2002 Michael Brailsford. 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. + +class StatsPlugin < Plugin + + @@commands = { + "stats" => "handle_stats", + "track" => "handle_track", + "untrack" => "handle_untrack", + "listtokens" => "handle_listtokens", + "rmabuser" => "handle_rmabuser" + } + + #{{{ + def initialize + super + @listen = true + @channels = Hash.new + #check to see if a stats token file already exists for this channel... + Dir["#{@bot.botclass}/stats/*"].each { |fname| + channel = File.basename fname + tokens = Hash.new + IO.foreach(fname) { |line| + if line =~ /^(\S+)\s*<=>(.*)/ + tokens[$1] = parse_token_stats $2 + end + } + @channels[channel] = tokens + } + end + #}}} + #{{{ + def cleanup + @channels = nil + end + #}}} + #{{{ + def help(plugin, topic="") + "Stats: The stats plugin tracks various tokens from users in the channel. The tokens are only tracked if it is the only thing on a line.\nUsage: stats <token> -- lists the stats for <token>\n [un]track <token> -- Adds or deletes <token> from the list of tokens\n listtokens -- lists the tokens that are currently being tracked" + end + #}}} + #{{{ + def privmsg(m) + if not m.params and not m.plugin =~ /listtokens/ + m.reply "What a crazy fool! Did you mean |help stats?" + return + end + + meth = self.method(@@commands[m.plugin]) + meth.call(m) + end + #}}} + #{{{ + def save + Dir.mkdir("#{@bot.botclass}/stats") if not FileTest.directory?("#{@bot.botclass}/stats") + #save the tokens to a file... + @channels.each_pair { |channel, tokens| + if not tokens.empty? + File.open("#{@bot.botclass}/stats/#{channel}", "w") { |f| + tokens.each { |token, datahash| + f.puts "#{token} <=> #{datahash_to_s(datahash)}" + } + } + else + File.delete "#{@bot.botclass}/stats/#{channel}" + end + } + end + #}}} + #{{{ + def listen(m) + if not m.private? + tokens = @channels[m.target] + if not @@commands[m.plugin] + tokens.each_pair { |key, hsh| + if not m.message.scan(/#{Regexp.escape(key)}/).empty? + if hsh[m.sourcenick] + hsh[m.sourcenick] += 1 + else + hsh[m.sourcenick] = 1 + end + end + } + end + end +#This is the old code {{{ +# if not m.private? +# tokens = @channels[m.target] +# hsh = tokens[m.message] +# if hsh +# if hsh[m.sourcenick] +# hsh[m.sourcenick] += 1 +# else +# hsh[m.sourcenick] = 1 +# end +# end +# end }}} + end + #}}} + #The following are helper functions for the plugin {{{ + def datahash_to_s(dhash) + rv = "" + dhash.each { |key, val| + rv << "#{key}:#{val} " + } + rv.chomp + end + + def parse_token_stats(stats) + rv = Hash.new + stats.split(" ").each { |nickstat| + nick, stat = nickstat.split ":" + rv[nick] = stat.to_i + } + rv + end + #}}} + #The following are handler methods for dealing with each command from IRC {{{ + #{{{ + def handle_stats(m) + if not m.private? + total = 0 + tokens = @channels[m.target] + hsh = tokens[m.params] + msg1 = "" + if not hsh.empty? + sorted = hsh.sort { |i, j| j[1] <=> i[1] } + sorted.each { |a| + total += a[1] + } + + msg = "Stats for #{m.params}. Said #{total} times. The top sayers are " + if sorted[0..2] + msg << "#{sorted[0].join ':'}" if sorted[0] + msg << ", #{sorted[1].join ':'}" if sorted[1] + msg << ", and #{sorted[2].join ':'}" if sorted[2] + msg << "." + + msg1 << "#{m.sourcenick} has said it " + if hsh[m.sourcenick] + msg1 << "#{hsh[m.sourcenick]} times." + else + msg1 << "0 times." + end + else + msg << "#{m.params} has not been said yet!" + end + @bot.action m.replyto, msg + @bot.action m.replyto, msg1 if msg1 + else + m.reply "#{m.params} is not currently being tracked." + end + end + end + #}}} + #{{{ + def handle_track(m) + if not m.private? + if @channels[m.target] + tokens = @channels[m.target] + else + tokens = Hash.new + @channels[m.target] = tokens + end + tokens[m.params] = Hash.new + m.reply "now tracking #{m.params}" + end + end + #}}} + #{{{ + def handle_untrack(m) + if not m.private? + toks = @channels[m.target] + if toks.has_key? m.params + toks.delete m.params + m.reply "no longer tracking #{m.params}" + else + m.reply "Are your signals crossed? Since when have I tracked that?" + end + end + + toks = nil + end + #}}} + #{{{ + def handle_listtokens(m) + if not m.private? and not @channels.empty? + tokens = @channels[m.target] + unless tokens.empty? + toks = "" + tokens.each_key { |k| + toks << "#{k} " + } + @bot.action m.replyto, "is currently keeping stats for: #{toks}" + else + @bot.action m.replyto, "is not currently keeping stats for anything" + end + elsif not m.private? + @bot.action m.replyto, "is not currently keeping stats for anything" + end + end + #}}} + #{{{ + def handle_rmabuser(m) + m.reply "This feature has not yet been implemented" + end + #}}} + #}}} + +end +plugin = StatsPlugin.new +plugin.register("stats") +plugin.register("track") +plugin.register("untrack") +plugin.register("listtokens") +#plugin.register("rmabuser") diff --git a/contrib/plugins/vandale.rb b/contrib/plugins/vandale.rb new file mode 100644 index 00000000..7b806c85 --- /dev/null +++ b/contrib/plugins/vandale.rb @@ -0,0 +1,49 @@ +#----------------------------------------------------------------# +# Filename: vandale.rb +# Description: Rbot plugin. Looks up a word in the Dutch VanDale +# dictionary +# Author: eWoud - ewoud.nuyts<AT>student.kuleuven.ac.be +# requires GnuVD www.djcbsoftware.nl/projecten/gnuvd/ +#----------------------------------------------------------------# + +class VanDalePlugin < Plugin + def help(plugin, topic="") + "vandale [<word>] => Look up in the VanDale dictionary" + end + def privmsg(m) + case m.params + when (/^([\w-]+)$/) + ret = Array.new + Utils.safe_exec("/usr/local/bin/gnuvd", m.params).each{|line| if line.length > 5 then ret << line end} + m.reply ret.delete_at(0) + while ret[0] =~ /^[[:alpha:]_]*[0-9]/ + m.reply ret.delete_at(0) + end + while ret[0] =~ /^[0-9]/ + m.reply ret.delete_at(0) + end + i = 0 + while i < ret.length + ret[i] = ret[i].slice(/^[[:graph:]_]*/) + if ret[i].length == 0 or ret[i] =~ /^[0-9]/ + then + ret.delete_at(i) + else + i = i+1 + end + end + if ret.length != 0 then + m.reply "zie ook " + ret.join(", ") + end + return + when nil + m.reply "incorrect usage: " + help(m.plugin) + return + else + m.reply "incorrect usage: " + help(m.plugin) + return + end + end +end +plugin = VanDalePlugin.new +plugin.register("vandale") |