diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 15:59:13 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 15:59:13 +0000 |
commit | 21949774b91eaec6ecde4eaa8ad121e2c0a36b87 (patch) | |
tree | 41a7601e168018ac203bad7ca8d7f9f82515bc28 /data/rbot/contrib/plugins | |
parent | 51cf09ec02d089bfdd80e5f728cfc92a234dc437 (diff) |
rearrange repo for packaging
Diffstat (limited to 'data/rbot/contrib/plugins')
-rw-r--r-- | data/rbot/contrib/plugins/figlet.rb | 20 | ||||
-rw-r--r-- | data/rbot/contrib/plugins/ri.rb | 83 | ||||
-rw-r--r-- | data/rbot/contrib/plugins/stats.rb | 232 | ||||
-rw-r--r-- | data/rbot/contrib/plugins/vandale.rb | 49 |
4 files changed, 384 insertions, 0 deletions
diff --git a/data/rbot/contrib/plugins/figlet.rb b/data/rbot/contrib/plugins/figlet.rb new file mode 100644 index 00000000..ce17fe71 --- /dev/null +++ b/data/rbot/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/data/rbot/contrib/plugins/ri.rb b/data/rbot/contrib/plugins/ri.rb new file mode 100644 index 00000000..99292f1c --- /dev/null +++ b/data/rbot/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/data/rbot/contrib/plugins/stats.rb b/data/rbot/contrib/plugins/stats.rb new file mode 100644 index 00000000..4cafbbe9 --- /dev/null +++ b/data/rbot/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/data/rbot/contrib/plugins/vandale.rb b/data/rbot/contrib/plugins/vandale.rb new file mode 100644 index 00000000..7b806c85 --- /dev/null +++ b/data/rbot/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") |