Permalink
Browse files

Added an ignore command.

  • Loading branch information...
1 parent 4f30230 commit 6d31090b622f3376a5a63412505c5539652afd53 @wilkie wilkie committed Feb 8, 2012
View
@@ -37,8 +37,8 @@ class << self
attr_reader :ssl
def add_plugin plugin
- @plugins = [] if @plugins.nil?
- @plugins << plugin
+ @plugins = {} if @plugins.nil?
+ @plugins[plugin.class.name] = plugin
end
def start
@@ -4,7 +4,7 @@ class Commands < XOmBot::Plugin
def execute(m)
commands = []
- XOmBot.plugins.each do |p|
+ XOmBot.plugins.each do |_,p|
p.commands.each do |k,v|
short_name = k.inspect.to_s[1..-2][/\w+/]
commands << short_name
@@ -5,7 +5,7 @@ class Help < XOmBot::Plugin
usage "help help -- Displays this thing you are reading"
def execute(m, command)
- XOmBot.plugins.each do |p|
+ XOmBot.plugins.each do |_,p|
idx = p.commands.keys.map{|c| c.inspect.to_s[1..-2][/\w+/]}.index command
if not idx.nil?
info = p.commands[p.commands.keys[idx]]
@@ -0,0 +1,27 @@
+class Ignore < XOmBot::Plugin
+ match /ignore (.+)/, :method => :ignore
+ help "Ignores speech from a particular user"
+ usage "ignore wilkie -- XOmBot will not respond to wilkie"
+
+ match /unignore (.+)/, :method => :unignore
+ help "Reverses decision to ignore speech from a particular user"
+ usage "unignore wilkie -- XOmBot will now respond to wilkie"
+
+ attr_reader :ignored
+
+ def initialize(*args)
+ super(*args)
+
+ @ignored = []
+ end
+
+ def ignore(m, nick)
+ @ignored << nick
+ m.emote "ignores #{nick}'s brains."
+ end
+
+ def unignore(m, nick)
+ @ignored.delete nick
+ m.emote "again finds #{nick}'s brains delicious."
+ end
+end
@@ -3,8 +3,8 @@ class Plugins < XOmBot::Plugin
def execute(m)
m.reply "Plugins:"
- XOmBot::plugins.each do |p|
- m.reply "-- #{p.class.name}"
+ XOmBot::plugins.keys.each do |p|
+ m.reply "-- #{p}"
end
end
end
@@ -2,6 +2,9 @@ class URLAnnounce < XOmBot::Plugin
listen_to :channel
def listen(m)
+ ignore_plugin = XOmBot.plugins["XOmBot::Plugins::Ignore"]
+ return if ignore_plugin and ignore_plugin.ignored.include? m.user.nick
+
m.message.scan /https?:\/\/[\S]+/ do |url|
page = Mechanize.new.get url
if page.is_a? Mechanize::Page

0 comments on commit 6d31090

Please sign in to comment.