summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-07 13:51:48 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-07 14:08:58 +0200
commitb8802b0ff7eb9695ddf3372c80698405c24ffe97 (patch)
tree67b6b4a59e4c95d4c405755a1bd3e55e24aaabda /lib
parent8a3ef5e5aaf5cb8305728f3bcd407ac17fc23138 (diff)
plugins: irc_delegate to do listen+actual delegate
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/ircbot.rb32
-rw-r--r--lib/rbot/plugins.rb15
2 files changed, 24 insertions, 23 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 97f8ead4..f1a56792 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -577,13 +577,7 @@ class Bot
irclogprivmsg(m)
unless ignored
- @plugins.delegate "listen", m
- @plugins.delegate("ctcp_listen", m) if m.ctcp
- @plugins.delegate "message", m
- @plugins.privmsg(m) if m.address?
- if not m.replied
- @plugins.delegate "unreplied", m
- end
+ @plugins.irc_delegate('privmsg', m)
end
}
@client[:notice] = proc { |data|
@@ -630,8 +624,7 @@ class Bot
data[:is_on].each { |ch|
irclog "@ #{old} is now known as #{new}", ch
}
- @plugins.delegate("listen", m)
- @plugins.delegate("nick", m)
+ @plugins.irc_delegate("nick", m)
}
@client[:quit] = proc {|data|
source = data[:source]
@@ -640,8 +633,7 @@ class Bot
data[:was_on].each { |ch|
irclog "@ Quit: #{source}: #{message}", ch
}
- @plugins.delegate("listen", m)
- @plugins.delegate("quit", m)
+ @plugins.irc_delegate("quit", m)
}
@client[:mode] = proc {|data|
irclog "@ Mode #{data[:modestring]} by #{data[:source]}", data[:channel]
@@ -650,36 +642,31 @@ class Bot
m = JoinMessage.new(self, server, data[:source], data[:channel], data[:message])
irclogjoin(m)
- @plugins.delegate("listen", m)
- @plugins.delegate("join", m)
+ @plugins.irc_delegate("join", m)
sendq("WHO #{data[:channel]}", data[:channel], 2) if m.address?
}
@client[:part] = proc {|data|
m = PartMessage.new(self, server, data[:source], data[:channel], data[:message])
irclogpart(m)
- @plugins.delegate("listen", m)
- @plugins.delegate("part", m)
+ @plugins.irc_delegate("part", m)
}
@client[:kick] = proc {|data|
m = KickMessage.new(self, server, data[:source], data[:target], data[:channel],data[:message])
irclogkick(m)
- @plugins.delegate("listen", m)
- @plugins.delegate("kick", m)
+ @plugins.irc_delegate("kick", m)
}
@client[:invite] = proc {|data|
m = InviteMessage.new(self, server, data[:source], data[:target], data[:channel])
- @plugins.delegate("listen", m)
- @plugins.delegate("invite", m)
+ @plugins.irc_delegate("invite", m)
}
@client[:changetopic] = proc {|data|
m = TopicMessage.new(self, server, data[:source], data[:channel], data[:topic])
irclogtopic(m)
- @plugins.delegate("listen", m)
- @plugins.delegate("topic", m)
+ @plugins.irc_delegate("topic", m)
}
@client[:topic] = proc { |data|
irclog "@ Topic is \"#{data[:topic]}\"", data[:channel]
@@ -690,8 +677,7 @@ class Bot
irclog "@ Topic set by #{topic.set_by} on #{topic.set_on}", channel
m = TopicMessage.new(self, server, data[:source], channel, topic)
- @plugins.delegate("listen", m)
- @plugins.delegate("topic", m)
+ @plugins.irc_delegate("topic", m)
}
@client[:names] = proc { |data|
@plugins.delegate "names", data[:channel], data[:users]
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index 7631bfc3..567724f8 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -822,6 +822,21 @@ module Plugins
return false
# debug "Finished delegating privmsg with key #{m.plugin.inspect}"
end
+
+ # delegate IRC messages, by delegating 'listen' first, and the actual method
+ # afterwards. Delegating 'privmsg' also delegates ctcp_listen and message
+ # as appropriate.
+ def irc_delegate(method, m)
+ delegate('listen', m)
+ if method.to_sym == :privmsg
+ delegate('ctcp_listen', m) if m.ctcp
+ delegate('message', m)
+ privmsg(m) if m.address?
+ delegate('unreplied', m) unless m.replied
+ else
+ delegate(method, m)
+ end
+ end
end
# Returns the only PluginManagerClass instance