5 $debug = false unless $debug
6 # print +message+ if debugging is enabled
8 print "DEBUG: #{message}\n" if($debug && message)
13 require 'rbot/rbotconfig'
17 require 'rbot/rfc2812'
18 require 'rbot/keywords'
19 require 'rbot/ircsocket'
22 require 'rbot/plugins'
23 require 'rbot/channel'
24 require 'rbot/message'
25 require 'rbot/language'
27 require 'rbot/registry'
28 require 'rbot/httputil'
32 # Main bot class, which manages the various components, receives messages,
33 # handles them or passes them to plugins, and contains core functionality.
35 # the bot's current nickname
38 # the bot's IrcAuth data
41 # the bot's BotConfig data
44 # the botclass for this bot (determines configdir among other things)
47 # used to perform actions periodically (saves configuration once per minute
54 # bot's configured addressing prefixes
55 attr_reader :addressing_prefixes
57 # channel info for channels the bot is in
63 # bot's object registry, plugins get an interface to this for persistant
64 # storage (hash interface tied to a bdb file, plugins use Accessors to store
65 # and restore objects in their own namespaces.)
68 # bot's httputil help object, for fetching resources via http. Sets up
69 # proxies etc as defined by the bot configuration/environment
72 # create a new IrcBot with botclass +botclass+
73 def initialize(botclass, params = {})
74 # BotConfig for the core bot
75 BotConfig.register BotConfigStringValue.new('server.name',
76 :default => "localhost", :requires_restart => true,
77 :desc => "What server should the bot connect to?",
79 BotConfig.register BotConfigIntegerValue.new('server.port',
80 :default => 6667, :type => :integer, :requires_restart => true,
81 :desc => "What port should the bot connect to?",
82 :validate => Proc.new {|v| v > 0}, :wizard => true)
83 BotConfig.register BotConfigStringValue.new('server.password',
84 :default => false, :requires_restart => true,
85 :desc => "Password for connecting to this server (if required)",
87 BotConfig.register BotConfigStringValue.new('server.bindhost',
88 :default => false, :requires_restart => true,
89 :desc => "Specific local host or IP for the bot to bind to (if required)",
91 BotConfig.register BotConfigIntegerValue.new('server.reconnect_wait',
92 :default => 5, :validate => Proc.new{|v| v >= 0},
93 :desc => "Seconds to wait before attempting to reconnect, on disconnect")
94 BotConfig.register BotConfigStringValue.new('irc.nick', :default => "rbot",
95 :desc => "IRC nickname the bot should attempt to use", :wizard => true,
96 :on_change => Proc.new{|bot, v| bot.sendq "NICK #{v}" })
97 BotConfig.register BotConfigStringValue.new('irc.user', :default => "rbot",
98 :requires_restart => true,
99 :desc => "local user the bot should appear to be", :wizard => true)
100 BotConfig.register BotConfigArrayValue.new('irc.join_channels',
101 :default => [], :wizard => true,
102 :desc => "What channels the bot should always join at startup. List multiple channels using commas to separate. If a channel requires a password, use a space after the channel name. e.g: '#chan1, #chan2, #secretchan secritpass, #chan3'")
103 BotConfig.register BotConfigIntegerValue.new('core.save_every',
104 :default => 60, :validate => Proc.new{|v| v >= 0},
105 # TODO change timer via on_change proc
106 :desc => "How often the bot should persist all configuration to disk (in case of a server crash, for example")
107 BotConfig.register BotConfigFloatValue.new('server.sendq_delay',
108 :default => 2.0, :validate => Proc.new{|v| v >= 0},
109 :desc => "(flood prevention) the delay between sending messages to the server (in seconds)",
110 :on_change => Proc.new {|bot, v| bot.socket.sendq_delay = v })
111 BotConfig.register BotConfigIntegerValue.new('server.sendq_burst',
112 :default => 4, :validate => Proc.new{|v| v >= 0},
113 :desc => "(flood prevention) max lines to burst to the server before throttling. Most ircd's allow bursts of up 5 lines, with non-burst limits of 512 bytes/2 seconds",
114 :on_change => Proc.new {|bot, v| bot.socket.sendq_burst = v })
115 BotConfig.register BotConfigIntegerValue.new('server.ping_timeout',
116 :default => 10, :validate => Proc.new{|v| v >= 0},
117 :on_change => Proc.new {|bot, v| bot.start_server_pings},
118 :desc => "reconnect if server doesn't respond to PING within this many seconds (set to 0 to disable)")
120 @argv = params[:argv]
122 unless FileTest.directory? Config::datadir
123 puts "data directory '#{Config::datadir}' not found, did you setup.rb?"
127 #botclass = "#{Etc.getpwnam(Etc.getlogin).dir}/.rbot" unless botclass
128 botclass = "#{ENV['HOME']}/.rbot" unless botclass
129 @botclass = botclass.gsub(/\/$/, "")
131 unless FileTest.directory? botclass
132 puts "no #{botclass} directory found, creating from templates.."
133 if FileTest.exist? botclass
134 puts "Error: file #{botclass} exists but isn't a directory"
137 FileUtils.cp_r Config::datadir+'/templates', botclass
140 Dir.mkdir("#{botclass}/logs") unless File.exist?("#{botclass}/logs")
144 @startup_time = Time.new
145 @config = BotConfig.new(self)
146 # TODO background self after botconfig has a chance to run wizard
147 @timer = Timer::Timer.new(1.0) # only need per-second granularity
148 @registry = BotRegistry.new self
149 @timer.add(@config['core.save_every']) { save } if @config['core.save_every']
152 @httputil = Utils::HttpUtil.new(self)
153 @lang = Language::Language.new(@config['core.language'])
154 @keywords = Keywords.new(self)
155 @auth = IrcAuth.new(self)
157 Dir.mkdir("#{botclass}/plugins") unless File.exist?("#{botclass}/plugins")
158 @plugins = Plugins::Plugins.new(self, ["#{botclass}/plugins"])
160 @socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'])
161 @nick = @config['irc.nick']
163 @client = IrcClient.new
164 @client[:privmsg] = proc { |data|
165 message = PrivMessage.new(self, data[:source], data[:target], data[:message])
168 @client[:notice] = proc { |data|
169 message = NoticeMessage.new(self, data[:source], data[:target], data[:message])
170 # pass it off to plugins that want to hear everything
171 @plugins.delegate "listen", message
173 @client[:motd] = proc { |data|
174 data[:motd].each_line { |line|
175 log "MOTD: #{line}", "server"
178 @client[:nicktaken] = proc { |data|
179 nickchg "#{data[:nick]}_"
181 @client[:badnick] = proc {|data|
182 puts "WARNING, bad nick (#{data[:nick]})"
184 @client[:ping] = proc {|data|
185 # (jump the queue for pongs)
186 @socket.puts "PONG #{data[:pingid]}"
188 @client[:pong] = proc {|data|
189 # cancel the timeout timer
190 debug "got a pong from the server, cancelling timeout"
193 @client[:nick] = proc {|data|
194 sourcenick = data[:sourcenick]
196 m = NickMessage.new(self, data[:source], data[:sourcenick], data[:nick])
197 if(sourcenick == @nick)
198 debug "my nick is now #{nick}"
201 @channels.each {|k,v|
202 if(v.users.has_key?(sourcenick))
203 log "@ #{sourcenick} is now known as #{nick}", k
204 v.users[nick] = v.users[sourcenick]
205 v.users.delete(sourcenick)
208 @plugins.delegate("listen", m)
209 @plugins.delegate("nick", m)
211 @client[:quit] = proc {|data|
212 source = data[:source]
213 sourcenick = data[:sourcenick]
214 sourceurl = data[:sourceaddress]
215 message = data[:message]
216 m = QuitMessage.new(self, data[:source], data[:sourcenick], data[:message])
217 if(data[:sourcenick] =~ /#{Regexp.escape(@nick)}/i)
219 @channels.each {|k,v|
220 if(v.users.has_key?(sourcenick))
221 log "@ Quit: #{sourcenick}: #{message}", k
222 v.users.delete(sourcenick)
226 @plugins.delegate("listen", m)
227 @plugins.delegate("quit", m)
229 @client[:mode] = proc {|data|
230 source = data[:source]
231 sourcenick = data[:sourcenick]
232 sourceurl = data[:sourceaddress]
233 channel = data[:channel]
234 targets = data[:targets]
235 modestring = data[:modestring]
236 log "@ Mode #{modestring} #{targets} by #{sourcenick}", channel
238 @client[:welcome] = proc {|data|
239 log "joined server #{data[:source]} as #{data[:nick]}", "server"
240 debug "I think my nick is #{@nick}, server thinks #{data[:nick]}"
241 if data[:nick] && data[:nick].length > 0
245 @plugins.delegate("connect")
247 @config['irc.join_channels'].each {|c|
248 debug "autojoining channel #{c}"
249 if(c =~ /^(\S+)\s+(\S+)$/i)
256 @client[:join] = proc {|data|
257 m = JoinMessage.new(self, data[:source], data[:channel], data[:message])
260 @client[:part] = proc {|data|
261 m = PartMessage.new(self, data[:source], data[:channel], data[:message])
264 @client[:kick] = proc {|data|
265 m = KickMessage.new(self, data[:source], data[:target],data[:channel],data[:message])
268 @client[:invite] = proc {|data|
269 if(data[:target] =~ /^#{Regexp.escape(@nick)}$/i)
270 join data[:channel] if (@auth.allow?("join", data[:source], data[:sourcenick]))
273 @client[:changetopic] = proc {|data|
274 channel = data[:channel]
275 sourcenick = data[:sourcenick]
277 timestamp = data[:unixtime] || Time.now.to_i
278 if(sourcenick == @nick)
279 log "@ I set topic \"#{topic}\"", channel
281 log "@ #{sourcenick} set topic \"#{topic}\"", channel
283 m = TopicMessage.new(self, data[:source], data[:channel], timestamp, data[:topic])
286 @plugins.delegate("listen", m)
287 @plugins.delegate("topic", m)
289 @client[:topic] = @client[:topicinfo] = proc {|data|
290 channel = data[:channel]
291 m = TopicMessage.new(self, data[:source], data[:channel], data[:unixtime], data[:topic])
294 @client[:names] = proc {|data|
295 channel = data[:channel]
297 unless(@channels[channel])
298 puts "bug: got names for channel '#{channel}' I didn't think I was in\n"
301 @channels[channel].users.clear
303 @channels[channel].users[u[0].sub(/^[@&~+]/, '')] = ["mode", u[1]]
306 @client[:unknown] = proc {|data|
307 #debug "UNKNOWN: #{data[:serverstring]}"
308 log data[:serverstring], ":unknown"
312 # connect the bot to IRC
314 trap("SIGTERM") { quit }
315 trap("SIGHUP") { quit }
316 trap("SIGINT") { quit }
320 raise "failed to connect to IRC server at #{@config['server.name']} #{@config['server.port']}: " + e
322 @socket.puts "PASS " + @config['server.password'] if @config['server.password']
323 @socket.puts "NICK #{@nick}\nUSER #{@config['irc.user']} 4 #{@config['server.name']} :Ruby bot. (c) Tom Gilbert"
327 # begin event handling loop
336 break unless reply = @socket.gets
337 @client.process reply
340 # I despair of this. Some of my users get "connection reset by peer"
341 # exceptions that ARENT SocketError's. How am I supposed to handle
343 #rescue TimeoutError, SocketError => e
344 rescue Exception => e
345 puts "network exception: connection closed: #{e}"
346 puts e.backtrace.join("\n")
347 @socket.shutdown # now we reconnect
349 puts "unexpected exception: connection closed: #{e.inspect}"
350 puts e.backtrace.join("\n")
358 puts "waiting to reconnect"
359 sleep @config['server.reconnect_wait']
363 # type:: message type
364 # where:: message target
365 # message:: message text
366 # send message +message+ of type +type+ to target +where+
367 # Type can be PRIVMSG, NOTICE, etc, but those you should really use the
368 # relevant say() or notice() methods. This one should be used for IRCd
369 # extensions you want to use in modules.
370 def sendmsg(type, where, message)
371 # limit it 440 chars + CRLF.. so we have to split long lines
372 left = 440 - type.length - where.length - 3
374 if(left >= message.length)
375 sendq("#{type} #{where} :#{message}")
376 log_sent(type, where, message)
379 line = message.slice!(0, left)
380 lastspace = line.rindex(/\s+/)
382 message = line.slice!(lastspace, line.length) + message
383 message.gsub!(/^\s+/, "")
385 sendq("#{type} #{where} :#{line}")
386 log_sent(type, where, line)
387 end while(message.length > 0)
390 # queue an arbitraty message for the server
391 def sendq(message="")
393 @socket.queue(message)
396 # send a notice message to channel/nick +where+
397 def notice(where, message)
398 message.each_line { |line|
400 next unless(line.length > 0)
401 sendmsg("NOTICE", where, line)
405 # say something (PRIVMSG) to channel/nick +where+
406 def say(where, message)
407 message.to_s.gsub(/[\r\n]+/, "\n").each_line { |line|
409 next unless(line.length > 0)
410 unless((where =~ /^#/) && (@channels.has_key?(where) && @channels[where].quiet))
411 sendmsg("PRIVMSG", where, line)
416 # perform a CTCP action with message +message+ to channel/nick +where+
417 def action(where, message)
418 sendq("PRIVMSG #{where} :\001ACTION #{message}\001")
420 log "* #{@nick} #{message}", where
421 elsif (where =~ /^(\S*)!.*$/)
422 log "* #{@nick}[#{where}] #{message}", $1
424 log "* #{@nick}[#{where}] #{message}", where
428 # quick way to say "okay" (or equivalent) to +where+
430 say where, @lang.get("okay")
433 # log message +message+ to a file determined by +where+. +where+ can be a
434 # channel name, or a nick for private message logging
435 def log(message, where="server")
437 stamp = Time.now.strftime("%Y/%m/%d %H:%M:%S")
438 unless(@logs.has_key?(where))
439 @logs[where] = File.new("#{@botclass}/logs/#{where}", "a")
440 @logs[where].sync = true
442 @logs[where].puts "[#{stamp}] #{message}"
443 #debug "[#{stamp}] <#{where}> #{message}"
446 # set topic of channel +where+ to +topic+
447 def topic(where, topic)
448 sendq "TOPIC #{where} :#{topic}"
451 # disconnect from the server and cleanup all plugins and modules
452 def shutdown(message = nil)
453 trap("SIGTERM", "DEFAULT")
454 trap("SIGHUP", "DEFAULT")
455 trap("SIGINT", "DEFAULT")
456 message = @lang.get("quit") if (message.nil? || message.empty?)
460 @channels.each_value {|v|
461 log "@ quit (#{message})", v.name
463 @socket.puts "QUIT :#{message}"
467 puts "rbot quit (#{message})"
470 # message:: optional IRC quit message
471 # quit IRC, shutdown the bot
472 def quit(message=nil)
477 # totally shutdown and respawn the bot
478 def restart(message = false)
479 msg = message ? message : "restarting, back in #{@config['server.reconnect_wait']}..."
481 sleep @config['server.reconnect_wait']
486 # call the save method for bot's config, keywords, auth and all plugins
495 # call the rescan method for the bot's lang, keywords and all plugins
502 # channel:: channel to join
503 # key:: optional channel key if channel is +s
505 def join(channel, key=nil)
507 sendq "JOIN #{channel} :#{key}"
509 sendq "JOIN #{channel}"
514 def part(channel, message="")
515 sendq "PART #{channel} :#{message}"
518 # attempt to change bot's nick to +name+
524 def mode(channel, mode, target)
525 sendq "MODE #{channel} #{mode} #{target}"
528 # m:: message asking for help
529 # topic:: optional topic help is requested for
530 # respond to online help requests
532 topic = nil if topic == ""
535 helpstr = "help topics: core, auth, keywords"
536 helpstr += @plugins.helptopics
537 helpstr += " (help <topic> for more info)"
540 when /^core\s+(.+)$/i
541 helpstr = corehelp $1
544 when /^auth\s+(.+)$/i
545 helpstr = @auth.help $1
547 helpstr = @keywords.help
548 when /^keywords\s+(.+)$/i
549 helpstr = @keywords.help $1
551 unless(helpstr = @plugins.help(topic))
552 helpstr = "no help for topic #{topic}"
558 # returns a string describing the current status of the bot (uptime etc)
560 secs_up = Time.new - @startup_time
561 uptime = Utils.secs_to_string secs_up
562 return "Uptime #{uptime}, #{@plugins.length} plugins active, #{@registry.length} items stored in registry, #{@socket.lines_sent} lines sent, #{@socket.lines_received} received."
565 # we'll ping the server every 30 seconds or so, and expect a response
566 # before the next one come around..
567 def start_server_pings
568 # stop existing timers if running
569 unless @ping_timer.nil?
570 @timer.remove @ping_timer
574 timeout = @config['server.ping_timeout']
575 return unless timeout > 0
576 timeout = 30 if timeout > 30
577 # we want to respond to a hung server within 30 secs or so
578 @ping_timer = @timer.add(30) {
580 @socket.puts "PING :rbot"
581 @timeout_timer = @timer.add_once(timeout) {
582 debug "no PONG from server for #{timeout} seconds, reconnecting"
586 debug "couldn't shutdown connection (already shutdown?)"
588 } if @config['server.ping_timeout']
594 def remove_timeout_timer
595 unless @timeout_timer.nil?
596 @timer.remove(@timeout_timer)
601 # handle help requests for "core" topics
602 def corehelp(topic="")
605 return "quit [<message>] => quit IRC with message <message>"
607 return "restart => completely stop and restart the bot (including reconnect)"
609 return "join <channel> [<key>] => join channel <channel> with secret key <key> if specified. #{@nick} also responds to invites if you have the required access level"
611 return "part <channel> => part channel <channel>"
613 return "hide => part all channels"
615 return "save => save current dynamic data and configuration"
617 return "rescan => reload modules and static facts"
619 return "nick <nick> => attempt to change nick to <nick>"
621 return "say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>"
623 return "action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>"
625 return "topic <channel> <message> => set topic of <channel> to <message>"
627 return "quiet [in here|<channel>] => with no arguments, stop speaking in all channels, if \"in here\", stop speaking in this channel, or stop speaking in <channel>"
629 return "talk [in here|<channel>] => with no arguments, resume speaking in all channels, if \"in here\", resume speaking in this channel, or resume speaking in <channel>"
631 return "version => describes software version"
633 return "botsnack => reward #{@nick} for being good"
635 return "hello|hi|hey|yo [#{@nick}] => greet the bot"
637 return "Core help topics: quit, restart, config, join, part, hide, save, rescan, nick, say, action, topic, quiet, talk, version, botsnack, hello"
641 # handle incoming IRC PRIVMSG +m+
646 log "* [#{m.sourcenick}(#{m.sourceaddress})] #{m.message}", m.sourcenick
648 log "* #{m.sourcenick} #{m.message}", m.target
652 log "<#{m.sourcenick}> #{m.message}", m.target
654 log "[#{m.sourcenick}(#{m.sourceaddress})] #{m.message}", m.sourcenick
658 # pass it off to plugins that want to hear everything
659 @plugins.delegate "listen", m
661 if(m.private? && m.message =~ /^\001PING\s+(.+)\001/)
662 notice m.sourcenick, "\001PING #$1\001"
663 log "@ #{m.sourcenick} pinged me"
669 when (/^join\s+(\S+)\s+(\S+)$/i)
670 join $1, $2 if(@auth.allow?("join", m.source, m.replyto))
671 when (/^join\s+(\S+)$/i)
672 join $1 if(@auth.allow?("join", m.source, m.replyto))
674 part m.target if(m.public? && @auth.allow?("join", m.source, m.replyto))
675 when (/^part\s+(\S+)$/i)
676 part $1 if(@auth.allow?("join", m.source, m.replyto))
677 when (/^quit(?:\s+(.*))?$/i)
678 quit $1 if(@auth.allow?("quit", m.source, m.replyto))
679 when (/^restart(?:\s+(.*))?$/i)
680 restart $1 if(@auth.allow?("quit", m.source, m.replyto))
682 join 0 if(@auth.allow?("join", m.source, m.replyto))
684 if(@auth.allow?("config", m.source, m.replyto))
688 when (/^nick\s+(\S+)$/i)
689 nickchg($1) if(@auth.allow?("nick", m.source, m.replyto))
690 when (/^say\s+(\S+)\s+(.*)$/i)
691 say $1, $2 if(@auth.allow?("say", m.source, m.replyto))
692 when (/^action\s+(\S+)\s+(.*)$/i)
693 action $1, $2 if(@auth.allow?("say", m.source, m.replyto))
694 when (/^topic\s+(\S+)\s+(.*)$/i)
695 topic $1, $2 if(@auth.allow?("topic", m.source, m.replyto))
696 when (/^mode\s+(\S+)\s+(\S+)\s+(.*)$/i)
697 mode $1, $2, $3 if(@auth.allow?("mode", m.source, m.replyto))
699 say m.replyto, "pong"
701 if(@auth.allow?("config", m.source, m.replyto))
706 if(auth.allow?("talk", m.source, m.replyto))
708 @channels.each_value {|c| c.quiet = true }
710 when (/^quiet in (\S+)$/i)
712 if(auth.allow?("talk", m.source, m.replyto))
714 where.gsub!(/^here$/, m.target) if m.public?
715 @channels[where].quiet = true if(@channels.has_key?(where))
718 if(auth.allow?("talk", m.source, m.replyto))
719 @channels.each_value {|c| c.quiet = false }
722 when (/^talk in (\S+)$/i)
724 if(auth.allow?("talk", m.source, m.replyto))
725 where.gsub!(/^here$/, m.target) if m.public?
726 @channels[where].quiet = false if(@channels.has_key?(where))
729 when (/^status\??$/i)
730 m.reply status if auth.allow?("status", m.source, m.replyto)
731 when (/^registry stats$/i)
732 if auth.allow?("config", m.source, m.replyto)
733 m.reply @registry.stat.inspect
735 when (/^(help\s+)?config(\s+|$)/)
737 when (/^(version)|(introduce yourself)$/i)
738 say m.replyto, "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"
739 when (/^help(?:\s+(.*))?$/i)
740 say m.replyto, help($1)
741 #TODO move these to a "chatback" plugin
742 when (/^(botsnack|ciggie)$/i)
743 say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
744 say m.replyto, @lang.get("thanks") if(m.private?)
745 when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i)
746 say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?)
747 say m.replyto, @lang.get("hello") if(m.private?)
752 # stuff to handle when not addressed
754 when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi|yo(\W|$))[\s,-.]+#{Regexp.escape(@nick)}$/i)
755 say m.replyto, @lang.get("hello_X") % m.sourcenick
756 when (/^#{Regexp.escape(@nick)}!*$/)
757 say m.replyto, @lang.get("hello_X") % m.sourcenick
764 # log a message. Internal use only.
765 def log_sent(type, where, message)
769 log "-=#{@nick}=- #{message}", where
770 elsif (where =~ /(\S*)!.*/)
771 log "[-=#{where}=-] #{message}", $1
773 log "[-=#{where}=-] #{message}"
777 log "<#{@nick}> #{message}", where
778 elsif (where =~ /^(\S*)!.*$/)
779 log "[msg(#{where})] #{message}", $1
781 log "[msg(#{where})] #{message}", where
787 @channels[m.channel] = IRCChannel.new(m.channel) unless(@channels.has_key?(m.channel))
789 debug "joined channel #{m.channel}"
790 log "@ Joined channel #{m.channel}", m.channel
792 log "@ #{m.sourcenick} joined channel #{m.channel}", m.channel
793 @channels[m.channel].users[m.sourcenick] = Hash.new
794 @channels[m.channel].users[m.sourcenick]["mode"] = ""
797 @plugins.delegate("listen", m)
798 @plugins.delegate("join", m)
803 debug "left channel #{m.channel}"
804 log "@ Left channel #{m.channel} (#{m.message})", m.channel
805 @channels.delete(m.channel)
807 log "@ #{m.sourcenick} left channel #{m.channel} (#{m.message})", m.channel
808 @channels[m.channel].users.delete(m.sourcenick)
811 # delegate to plugins
812 @plugins.delegate("listen", m)
813 @plugins.delegate("part", m)
816 # respond to being kicked from a channel
819 debug "kicked from channel #{m.channel}"
820 @channels.delete(m.channel)
821 log "@ You have been kicked from #{m.channel} by #{m.sourcenick} (#{m.message})", m.channel
823 @channels[m.channel].users.delete(m.sourcenick)
824 log "@ #{m.target} has been kicked from #{m.channel} by #{m.sourcenick} (#{m.message})", m.channel
827 @plugins.delegate("listen", m)
828 @plugins.delegate("kick", m)
832 @channels[m.channel] = IRCChannel.new(m.channel) unless(@channels.has_key?(m.channel))
833 @channels[m.channel].topic = m.topic if !m.topic.nil?
834 @channels[m.channel].topic.timestamp = m.timestamp if !m.timestamp.nil?
835 @channels[m.channel].topic.by = m.source if !m.source.nil?
837 debug "topic of channel #{m.channel} is now #{@channels[m.channel].topic}"
840 # delegate a privmsg to auth, keyword or plugin handlers
841 def delegate_privmsg(message)
842 [@auth, @plugins, @keywords].each {|m|
843 break if m.privmsg(message)