2 # Logging plugin for CyBot.
5 class Logger < PluginBase
8 # Channel_Instances = true
10 # Some per-channel init.
12 @brief_help = 'Records various channel activities.'
20 @seen = YAML.load_file(file_name('seen.db'))
26 open_file('seen.db', 'w') do |f|
27 f.puts '# CyBot logger plugin: Seen database.'
40 # Hook for PRIVMSGs to a channel the bot is in.
41 def hook_privmsg_chan(irc, msg)
42 l = @seen[cn = irc.channel.name] || (@seen[cn] = {})
43 l[irc.from.nnick] = [Time.now, LogPrivmsg, msg]
46 def hook_notice_chan(irc, msg)
47 l = @seen[cn = irc.channel.name] || (@seen[cn] = {})
48 l[irc.from.nnick] = [Time.now, LogNotice, msg]
51 def hook_join_chan(irc)
52 l = @seen[cn = irc.channel.name] || (@seen[cn] = {})
53 l[irc.from.nnick] = [Time.now, LogJoin]
56 def hook_part_chan(irc)
57 l = @seen[cn = irc.channel.name] || (@seen[cn] = {})
58 l[irc.from.nnick] = [Time.now, LogPart]
61 def hook_command_serv(irc, handled, cmd, *args)
63 @seen.each_value do |c|
64 c[irc.from.nnick] = [Time.now, LogNick, args[0]]
69 def chan_seen(irc, chan, nick)
71 if l = @seen[chan.name] and l = l[IRC::Address.normalize(nick)]
72 irc.reply "#{nick} was last seen #{seconds_to_s((Time.now - l[0]).to_i, irc)} ago, " + case l[1]
73 when LogJoin: "joining."
74 when LogPart: "leaving."
75 when LogNick: "changing nick to #{l[2]}"
76 when LogPrivmsg: "saying: #{l[2]}"
77 when LogNoting: "noting: #{l[2]}"
78 else "doing something unknown :-p."
81 irc.reply "I haven't seen #{nick}."
84 irc.reply 'USAGE: seen [channel] <nick name>'
87 help :seen, "Type 'seen <nick>' and I'll tell you when I last heard something from <nick>, and what he or she was saying or doing."