summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-15 01:54:07 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-04-15 01:54:07 +0200
commit8610e08b1dbaa0738d2d6155260dbfba8d8aa42c (patch)
treec00d9bd4629f1dbf3176e58e97ca99e61e59826a /lib/rbot
parentf23cb29ddf2ff1d2f959086571249da52cee0c7d (diff)
irclog core module: dispatch from listen() to catch double-delegated messages early
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/core/basics.rb2
-rw-r--r--lib/rbot/core/config.rb2
-rw-r--r--lib/rbot/core/irclog.rb58
3 files changed, 44 insertions, 18 deletions
diff --git a/lib/rbot/core/basics.rb b/lib/rbot/core/basics.rb
index 2db2bcd8..d991e921 100644
--- a/lib/rbot/core/basics.rb
+++ b/lib/rbot/core/basics.rb
@@ -14,10 +14,8 @@ class BasicsModule < CoreBotModule
case m.ctcp.intern
when :PING
m.ctcp_reply m.message
- @bot.irclog "@ #{m.source} pinged #{who}"
when :TIME
m.ctcp_reply Time.now.to_s
- @bot.irclog "@ #{m.source} asked #{who} what time it is"
end
end
diff --git a/lib/rbot/core/config.rb b/lib/rbot/core/config.rb
index cfc6588b..38140f18 100644
--- a/lib/rbot/core/config.rb
+++ b/lib/rbot/core/config.rb
@@ -205,10 +205,8 @@ class ConfigModule < CoreBotModule
case m.ctcp.intern
when :VERSION
m.ctcp_reply version_string
- # @bot.irclog "@ #{m.source} asked #{who} about version info"
when :SOURCE
m.ctcp_reply Irc::Bot::SOURCE_URL
- # @bot.irclog "@ #{m.source} asked #{who} about source info"
end
end
diff --git a/lib/rbot/core/irclog.rb b/lib/rbot/core/irclog.rb
index 6058a17a..64469f78 100644
--- a/lib/rbot/core/irclog.rb
+++ b/lib/rbot/core/irclog.rb
@@ -58,15 +58,45 @@ class IrcLogModule < CoreBotModule
irclog "joined server #{m.server} as #{m.target}", "server"
end
- def message(m)
- if(m.action?)
- if(m.private?)
- irclog "* [#{m.source}(#{m.sourceaddress})] #{m.logmessage}", m.source
+ def listen(m)
+ case m
+ when PrivMessage
+ method = 'log_message'
+ else
+ method = 'log_' + m.class.name.downcase.match(/^irc::(\w+)message$/).captures.first
+ end
+ if self.respond_to?(method)
+ self.__send__(method, m)
+ else
+ warning "unhandled logging for #{m.pretty_inspect} (no such method #{method})"
+ unknown_message(m)
+ end
+ end
+
+ def log_message(m)
+ if m.ctcp
+ who = m.private? ? "me" : m.target
+ logtarget = m.private? ? m.source : m.target
+ case m.ctcp.intern
+ when :ACTION
+ if m.public?
+ irclog "* #{m.source} #{m.logmessage}", m.target
+ else
+ irclog "* [#{m.source}(#{m.sourceaddress})] #{m.logmessage}", m.source
+ end
+ when :VERSION
+ irclog "@ #{m.source} asked #{who} about version info", logtarget
+ when :SOURCE
+ irclog "@ #{m.source} asked #{who} about source info", logtarget
+ when :PING
+ irclog "@ #{m.source} pinged #{who}", logtarget
+ when :TIME
+ irclog "@ #{m.source} asked #{who} what time it is", logtarget
else
- irclog "* #{m.source} #{m.logmessage}", m.target
+ irclog "@ #{m.source} asked #{who} about #{[m.ctcp, m.message].join(' ')}", logtarget
end
else
- if(m.public?)
+ if m.public?
irclog "<#{m.source}> #{m.logmessage}", m.target
else
irclog "[#{m.source}(#{m.sourceaddress})] #{m.logmessage}", m.source
@@ -74,7 +104,7 @@ class IrcLogModule < CoreBotModule
end
end
- def notice(m)
+ def log_notice(m)
if m.private?
irclog "-#{m.source}- #{m.message}", m.source
else
@@ -88,13 +118,13 @@ class IrcLogModule < CoreBotModule
}
end
- def nick(m)
+ def log_nick(m)
m.is_on.each { |ch|
irclog "@ #{m.oldnick} is now known as #{m.newnick}", ch
}
end
- def quit(m)
+ def log_quit(m)
m.was_on.each { |ch|
irclog "@ Quit: #{m.source}: #{m.message}", ch
}
@@ -104,7 +134,7 @@ class IrcLogModule < CoreBotModule
irclog "@ Mode #{m.message} by #{m.source}", m.target
end
- def join(m)
+ def log_join(m)
if m.address?
debug "joined channel #{m.channel}"
irclog "@ Joined channel #{m.channel}", m.channel
@@ -113,7 +143,7 @@ class IrcLogModule < CoreBotModule
end
end
- def part(m)
+ def log_part(m)
if(m.address?)
debug "left channel #{m.channel}"
irclog "@ Left channel #{m.channel} (#{m.logmessage})", m.channel
@@ -122,7 +152,7 @@ class IrcLogModule < CoreBotModule
end
end
- def kick(m)
+ def log_kick(m)
if(m.address?)
debug "kicked from channel #{m.channel}"
irclog "@ You have been kicked from #{m.channel} by #{m.source} (#{m.logmessage})", m.channel
@@ -131,11 +161,11 @@ class IrcLogModule < CoreBotModule
end
end
- # def invite(m)
+ # def log_invite(m)
# # TODO
# end
- def topic(m)
+ def log_topic(m)
case m.info_or_set
when :set
if m.source == @bot.myself