1 # Copyright (C) 2002 Tom Gilbert.
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to
5 # deal in the Software without restriction, including without limitation the
6 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 # sell copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in
11 # all copies of the Software and its documentation and acknowledgment shall be
12 # given in the documentation and software packages that this Software was
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 require 'rbot/rbotconfig'
31 require 'rbot/rfc2812'
32 require 'rbot/keywords'
33 require 'rbot/ircsocket'
36 require 'rbot/plugins'
37 require 'rbot/channel'
38 require 'rbot/message'
39 require 'rbot/language'
41 require 'rbot/registry'
42 require 'rbot/httputil'
46 # Main bot class, which receives messages, handles them or passes them to
47 # plugins, and stores runtime data
49 # the bot's current nickname
52 # the bot's IrcAuth data
55 # the bot's BotConfig data
58 # the botclass for this bot (determines configdir among other things)
61 # used to perform actions periodically (saves configuration once per minute
68 # bot's configured addressing prefixes
69 attr_reader :addressing_prefixes
71 # channel info for channels the bot is in
74 # bot's object registry, plugins get an interface to this for persistant
75 # storage (hash interface tied to a bdb file, plugins use Accessors to store
76 # and restore objects in their own namespaces.)
79 # bot's httputil help object, for fetching resources via http. Sets up
80 # proxies etc as defined by the bot configuration/environment
83 # create a new IrcBot with botclass +botclass+
84 def initialize(botclass, params = {})
85 # BotConfig for the core bot
86 BotConfig.register BotConfigStringValue.new('server.name',
87 :default => "localhost", :requires_restart => true,
88 :desc => "What server should the bot connect to?",
90 BotConfig.register BotConfigIntegerValue.new('server.port',
91 :default => 6667, :type => :integer, :requires_restart => true,
92 :desc => "What port should the bot connect to?",
93 :validate => Proc.new {|v| v > 0}, :wizard => true)
94 BotConfig.register BotConfigStringValue.new('server.password',
95 :default => false, :requires_restart => true,
96 :desc => "Password for connecting to this server (if required)",
98 BotConfig.register BotConfigStringValue.new('server.bindhost',
99 :default => false, :requires_restart => true,
100 :desc => "Specific local host or IP for the bot to bind to (if required)",
102 BotConfig.register BotConfigIntegerValue.new('server.reconnect_wait',
103 :default => 5, :validate => Proc.new{|v| v >= 0},
104 :desc => "Seconds to wait before attempting to reconnect, on disconnect")
105 BotConfig.register BotConfigStringValue.new('irc.nick', :default => "rbot",
106 :desc => "IRC nickname the bot should attempt to use", :wizard => true,
107 :on_change => Proc.new{|bot, v| bot.sendq "NICK #{v}" })
108 BotConfig.register BotConfigStringValue.new('irc.user', :default => "rbot",
109 :requires_restart => true,
110 :desc => "local user the bot should appear to be", :wizard => true)
111 BotConfig.register BotConfigArrayValue.new('irc.join_channels',
112 :default => [], :wizard => true,
113 :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'")
114 BotConfig.register BotConfigIntegerValue.new('core.save_every',
115 :default => 60, :validate => Proc.new{|v| v >= 0},
116 # TODO change timer via on_change proc
117 :desc => "How often the bot should persist all configuration to disk (in case of a server crash, for example")
118 BotConfig.register BotConfigFloatValue.new('server.sendq_delay',
119 :default => 2.0, :validate => Proc.new{|v| v >= 0},
120 :desc => "(flood prevention) the delay between sending messages to the server (in seconds)",
121 :on_change => Proc.new {|bot, v| bot.socket.sendq_delay = v })
122 BotConfig.register BotConfigIntegerValue.new('server.sendq_burst',
123 :default => 4, :validate => Proc.new{|v| v >= 0},
124 :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",
125 :on_change => Proc.new {|bot, v| bot.socket.sendq_burst = v })
127 @argv = params[:argv]
129 unless FileTest.directory? Config::DATADIR
130 puts "data directory '#{Config::DATADIR}' not found, did you install.rb?"
134 botclass = "/home/#{Etc.getlogin}/.rbot" unless botclass
135 @botclass = botclass.gsub(/\/$/, "")
137 unless FileTest.directory? botclass
138 puts "no #{botclass} directory found, creating from templates.."
139 if FileTest.exist? botclass
140 puts "Error: file #{botclass} exists but isn't a directory"
143 FileUtils.cp_r Config::DATADIR+'/templates', botclass
146 Dir.mkdir("#{botclass}/logs") unless File.exist?("#{botclass}/logs")
148 @startup_time = Time.new
149 @config = BotConfig.new(self)
150 @timer = Timer::Timer.new(1.0) # only need per-second granularity
151 @registry = BotRegistry.new self
152 @timer.add(@config['core.save_every']) { save } if @config['core.save_every']
156 @httputil = Utils::HttpUtil.new(self)
157 @lang = Language::Language.new(@config['core.language'])
158 @keywords = Keywords.new(self)
159 @auth = IrcAuth.new(self)
161 Dir.mkdir("#{botclass}/plugins") unless File.exist?("#{botclass}/plugins")
162 @plugins = Plugins::Plugins.new(self, ["#{botclass}/plugins"])
164 @socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'])
165 @nick = @config['irc.nick']
166 if @config['core.address_prefix']
167 @addressing_prefixes = @config['core.address_prefix'].split(" ")
169 @addressing_prefixes = Array.new
172 @client = IrcClient.new
173 @client["PRIVMSG"] = proc { |data|
174 message = PrivMessage.new(self, data["SOURCE"], data["TARGET"], data["MESSAGE"])
177 @client["NOTICE"] = proc { |data|
178 message = NoticeMessage.new(self, data["SOURCE"], data["TARGET"], data["MESSAGE"])
179 # pass it off to plugins that want to hear everything
180 @plugins.delegate "listen", message
182 @client["MOTD"] = proc { |data|
183 data['MOTD'].each_line { |line|
184 log "MOTD: #{line}", "server"
187 @client["NICKTAKEN"] = proc { |data|
190 @client["BADNICK"] = proc {|data|
191 puts "WARNING, bad nick (#{data['NICK']})"
193 @client["PING"] = proc {|data|
194 # (jump the queue for pongs)
195 @socket.puts "PONG #{data['PINGID']}"
197 @client["NICK"] = proc {|data|
198 sourcenick = data["SOURCENICK"]
200 m = NickMessage.new(self, data["SOURCE"], data["SOURCENICK"], data["NICK"])
201 if(sourcenick == @nick)
204 @channels.each {|k,v|
205 if(v.users.has_key?(sourcenick))
206 log "@ #{sourcenick} is now known as #{nick}", k
207 v.users[nick] = v.users[sourcenick]
208 v.users.delete(sourcenick)
211 @plugins.delegate("listen", m)
212 @plugins.delegate("nick", m)
214 @client["QUIT"] = proc {|data|
215 source = data["SOURCE"]
216 sourcenick = data["SOURCENICK"]
217 sourceurl = data["SOURCEADDRESS"]
218 message = data["MESSAGE"]
219 m = QuitMessage.new(self, data["SOURCE"], data["SOURCENICK"], data["MESSAGE"])
220 if(data["SOURCENICK"] =~ /#{@nick}/i)
222 @channels.each {|k,v|
223 if(v.users.has_key?(sourcenick))
224 log "@ Quit: #{sourcenick}: #{message}", k
225 v.users.delete(sourcenick)
229 @plugins.delegate("listen", m)
230 @plugins.delegate("quit", m)
232 @client["MODE"] = proc {|data|
233 source = data["SOURCE"]
234 sourcenick = data["SOURCENICK"]
235 sourceurl = data["SOURCEADDRESS"]
236 channel = data["CHANNEL"]
237 targets = data["TARGETS"]
238 modestring = data["MODESTRING"]
239 log "@ Mode #{modestring} #{targets} by #{sourcenick}", channel
241 @client["WELCOME"] = proc {|data|
242 log "joined server #{data['SOURCE']} as #{data['NICK']}", "server"
243 debug "I think my nick is #{@nick}, server thinks #{data['NICK']}"
244 if data['NICK'] && data['NICK'].length > 0
247 if(@config['irc.quser'])
248 # TODO move this to a plugin
249 debug "authing with Q using #{@config['quakenet.user']} #{@config['quakenet.auth']}"
250 @socket.puts "PRIVMSG Q@CServe.quakenet.org :auth #{@config['quakenet.user']} #{@config['quakenet.auth']}"
253 @config['irc.join_channels'].each {|c|
254 debug "autojoining channel #{c}"
255 if(c =~ /^(\S+)\s+(\S+)$/i)
262 @client["JOIN"] = proc {|data|
263 m = JoinMessage.new(self, data["SOURCE"], data["CHANNEL"], data["MESSAGE"])
266 @client["PART"] = proc {|data|
267 m = PartMessage.new(self, data["SOURCE"], data["CHANNEL"], data["MESSAGE"])
270 @client["KICK"] = proc {|data|
271 m = KickMessage.new(self, data["SOURCE"], data["TARGET"],data["CHANNEL"],data["MESSAGE"])
274 @client["INVITE"] = proc {|data|
275 if(data["TARGET"] =~ /^#{@nick}$/i)
276 join data["CHANNEL"] if (@auth.allow?("join", data["SOURCE"], data["SOURCENICK"]))
279 @client["CHANGETOPIC"] = proc {|data|
280 channel = data["CHANNEL"]
281 sourcenick = data["SOURCENICK"]
282 topic = data["TOPIC"]
283 timestamp = data["UNIXTIME"] || Time.now.to_i
284 if(sourcenick == @nick)
285 log "@ I set topic \"#{topic}\"", channel
287 log "@ #{sourcenick} set topic \"#{topic}\"", channel
289 m = TopicMessage.new(self, data["SOURCE"], data["CHANNEL"], timestamp, data["TOPIC"])
292 @plugins.delegate("listen", m)
293 @plugins.delegate("topic", m)
295 @client["TOPIC"] = @client["TOPICINFO"] = proc {|data|
296 channel = data["CHANNEL"]
297 m = TopicMessage.new(self, data["SOURCE"], data["CHANNEL"], data["UNIXTIME"], data["TOPIC"])
300 @client["NAMES"] = proc {|data|
301 channel = data["CHANNEL"]
302 users = data["USERS"]
303 unless(@channels[channel])
304 puts "bug: got names for channel '#{channel}' I didn't think I was in\n"
307 @channels[channel].users.clear
309 @channels[channel].users[u[0].sub(/^[@&~+]/, '')] = ["mode", u[1]]
312 @client["UNKNOWN"] = proc {|data|
313 debug "UNKNOWN: #{data['SERVERSTRING']}"
317 # connect the bot to IRC
319 trap("SIGTERM") { quit }
320 trap("SIGHUP") { quit }
321 trap("SIGINT") { quit }
325 raise "failed to connect to IRC server at #{@config['server.name']} #{@config['server.port']}: " + e
327 @socket.puts "PASS " + @config['server.password'] if @config['server.password']
328 @socket.puts "NICK #{@nick}\nUSER #{@config['irc.user']} 4 #{@config['server.name']} :Ruby bot. (c) Tom Gilbert"
331 # begin event handling loop
340 break unless reply = @socket.gets
341 @client.process reply
344 rescue TimeoutError, SocketError => e
345 puts "network exception: connection closed: #{e}"
346 puts e.backtrace.join("\n")
347 @socket.close # now we reconnect
348 rescue => e # TODO be selective, only grab Network errors
349 puts "unexpected exception: connection closed: #{e}"
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 def sendq(message="")
392 @socket.queue(message)
395 # send a notice message to channel/nick +where+
396 def notice(where, message)
397 message.each_line { |line|
399 next unless(line.length > 0)
400 sendmsg("NOTICE", where, line)
404 # say something (PRIVMSG) to channel/nick +where+
405 def say(where, message)
406 message.to_s.gsub(/[\r\n]+/, "\n").each_line { |line|
408 next unless(line.length > 0)
409 unless((where =~ /^#/) && (@channels.has_key?(where) && @channels[where].quiet))
410 sendmsg("PRIVMSG", where, line)
415 # perform a CTCP action with message +message+ to channel/nick +where+
416 def action(where, message)
417 sendq("PRIVMSG #{where} :\001ACTION #{message}\001")
419 log "* #{@nick} #{message}", where
420 elsif (where =~ /^(\S*)!.*$/)
421 log "* #{@nick}[#{where}] #{message}", $1
423 log "* #{@nick}[#{where}] #{message}", where
427 # quick way to say "okay" (or equivalent) to +where+
429 say where, @lang.get("okay")
432 # log message +message+ to a file determined by +where+. +where+ can be a
433 # channel name, or a nick for private message logging
434 def log(message, where="server")
436 stamp = Time.now.strftime("%Y/%m/%d %H:%M:%S")
437 unless(@logs.has_key?(where))
438 @logs[where] = File.new("#{@botclass}/logs/#{where}", "a")
439 @logs[where].sync = true
441 @logs[where].puts "[#{stamp}] #{message}"
442 #debug "[#{stamp}] <#{where}> #{message}"
445 # set topic of channel +where+ to +topic+
446 def topic(where, topic)
447 sendq "TOPIC #{where} :#{topic}"
450 def shutdown(message = nil)
451 trap("SIGTERM", "DEFAULT")
452 trap("SIGHUP", "DEFAULT")
453 trap("SIGINT", "DEFAULT")
454 message = @lang.get("quit") if (message.nil? || message.empty?)
458 @channels.each_value {|v|
459 log "@ quit (#{message})", v.name
461 @socket.puts "QUIT :#{message}"
465 puts "rbot quit (#{message})"
468 # message:: optional IRC quit message
469 # quit IRC, shutdown the bot
470 def quit(message=nil)
475 # totally shutdown and respawn the bot
477 shutdown("restarting, back in #{@config['server.reconnect_wait']}...")
478 sleep @config['server.reconnect_wait']
483 # call the save method for bot's config, keywords, auth and all plugins
492 # call the rescan method for the bot's lang, keywords and all plugins
499 # channel:: channel to join
500 # key:: optional channel key if channel is +s
502 def join(channel, key=nil)
504 sendq "JOIN #{channel} :#{key}"
506 sendq "JOIN #{channel}"
511 def part(channel, message="")
512 sendq "PART #{channel} :#{message}"
515 # attempt to change bot's nick to +name+
517 # if rbot is already taken, this happens:
518 # <giblet> rbot_, nick rbot
519 # --- rbot_ is now known as rbot__
520 # he should of course just keep his existing nick and report the error :P
526 def mode(channel, mode, target)
527 sendq "MODE #{channel} #{mode} #{target}"
530 # m:: message asking for help
531 # topic:: optional topic help is requested for
532 # respond to online help requests
534 topic = nil if topic == ""
537 helpstr = "help topics: core, auth, keywords"
538 helpstr += @plugins.helptopics
539 helpstr += " (help <topic> for more info)"
542 when /^core\s+(.+)$/i
543 helpstr = corehelp $1
546 when /^auth\s+(.+)$/i
547 helpstr = @auth.help $1
549 helpstr = @keywords.help
550 when /^keywords\s+(.+)$/i
551 helpstr = @keywords.help $1
553 unless(helpstr = @plugins.help(topic))
554 helpstr = "no help for topic #{topic}"
561 secs_up = Time.new - @startup_time
562 uptime = Utils.secs_to_string secs_up
563 return "Uptime #{uptime}, #{@plugins.length} plugins active, #{@registry.length} items stored in registry, #{@socket.lines_sent} lines sent, #{@socket.lines_received} received."
569 # handle help requests for "core" topics
570 def corehelp(topic="")
573 return "quit [<message>] => quit IRC with message <message>"
575 return "restart => completely stop and restart the bot (including reconnect)"
577 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"
579 return "part <channel> => part channel <channel>"
581 return "hide => part all channels"
583 return "save => save current dynamic data and configuration"
585 return "rescan => reload modules and static facts"
587 return "nick <nick> => attempt to change nick to <nick>"
589 return "say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>"
591 return "action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>"
593 return "topic <channel> <message> => set topic of <channel> to <message>"
595 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>"
597 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>"
599 return "version => describes software version"
601 return "botsnack => reward #{@nick} for being good"
603 return "hello|hi|hey|yo [#{@nick}] => greet the bot"
605 return "Core help topics: quit, restart, config, join, part, hide, save, rescan, nick, say, action, topic, quiet, talk, version, botsnack, hello"
609 # handle incoming IRC PRIVMSG +m+
614 log "* [#{m.sourcenick}(#{m.sourceaddress})] #{m.message}", m.sourcenick
616 log "* #{m.sourcenick} #{m.message}", m.target
620 log "<#{m.sourcenick}> #{m.message}", m.target
622 log "[#{m.sourcenick}(#{m.sourceaddress})] #{m.message}", m.sourcenick
626 # pass it off to plugins that want to hear everything
627 @plugins.delegate "listen", m
629 if(m.private? && m.message =~ /^\001PING\s+(.+)\001/)
630 notice m.sourcenick, "\001PING #$1\001"
631 log "@ #{m.sourcenick} pinged me"
637 when (/^join\s+(\S+)\s+(\S+)$/i)
638 join $1, $2 if(@auth.allow?("join", m.source, m.replyto))
639 when (/^join\s+(\S+)$/i)
640 join $1 if(@auth.allow?("join", m.source, m.replyto))
642 part m.target if(m.public? && @auth.allow?("join", m.source, m.replyto))
643 when (/^part\s+(\S+)$/i)
644 part $1 if(@auth.allow?("join", m.source, m.replyto))
645 when (/^quit(?:\s+(.*))?$/i)
646 quit $1 if(@auth.allow?("quit", m.source, m.replyto))
648 restart if(@auth.allow?("quit", m.source, m.replyto))
650 join 0 if(@auth.allow?("join", m.source, m.replyto))
652 if(@auth.allow?("config", m.source, m.replyto))
656 when (/^nick\s+(\S+)$/i)
657 nickchg($1) if(@auth.allow?("nick", m.source, m.replyto))
658 when (/^say\s+(\S+)\s+(.*)$/i)
659 say $1, $2 if(@auth.allow?("say", m.source, m.replyto))
660 when (/^action\s+(\S+)\s+(.*)$/i)
661 action $1, $2 if(@auth.allow?("say", m.source, m.replyto))
662 when (/^topic\s+(\S+)\s+(.*)$/i)
663 topic $1, $2 if(@auth.allow?("topic", m.source, m.replyto))
664 when (/^mode\s+(\S+)\s+(\S+)\s+(.*)$/i)
665 mode $1, $2, $3 if(@auth.allow?("mode", m.source, m.replyto))
667 say m.replyto, "pong"
669 if(@auth.allow?("config", m.source, m.replyto))
674 if(auth.allow?("talk", m.source, m.replyto))
676 @channels.each_value {|c| c.quiet = true }
678 when (/^quiet in (\S+)$/i)
680 if(auth.allow?("talk", m.source, m.replyto))
682 where.gsub!(/^here$/, m.target) if m.public?
683 @channels[where].quiet = true if(@channels.has_key?(where))
686 if(auth.allow?("talk", m.source, m.replyto))
687 @channels.each_value {|c| c.quiet = false }
690 when (/^talk in (\S+)$/i)
692 if(auth.allow?("talk", m.source, m.replyto))
693 where.gsub!(/^here$/, m.target) if m.public?
694 @channels[where].quiet = false if(@channels.has_key?(where))
697 when (/^status\??$/i)
698 m.reply status if auth.allow?("status", m.source, m.replyto)
699 when (/^registry stats$/i)
700 if auth.allow?("config", m.source, m.replyto)
701 m.reply @registry.stat.inspect
703 when (/^(help\s+)?config(\s+|$)/)
705 when (/^(version)|(introduce yourself)$/i)
706 say m.replyto, "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"
707 when (/^help(?:\s+(.*))?$/i)
708 say m.replyto, help($1)
709 #TODO move these to a "chatback" plugin
710 when (/^(botsnack|ciggie)$/i)
711 say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
712 say m.replyto, @lang.get("thanks") if(m.private?)
713 when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i)
714 say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?)
715 say m.replyto, @lang.get("hello") if(m.private?)
720 # stuff to handle when not addressed
722 when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$))[\s,-.]+#{@nick}$/i)
723 say m.replyto, @lang.get("hello_X") % m.sourcenick
724 when (/^#{@nick}!*$/)
725 say m.replyto, @lang.get("hello_X") % m.sourcenick
732 # log a message. Internal use only.
733 def log_sent(type, where, message)
737 log "-=#{@nick}=- #{message}", where
738 elsif (where =~ /(\S*)!.*/)
739 log "[-=#{where}=-] #{message}", $1
741 log "[-=#{where}=-] #{message}"
745 log "<#{@nick}> #{message}", where
746 elsif (where =~ /^(\S*)!.*$/)
747 log "[msg(#{where})] #{message}", $1
749 log "[msg(#{where})] #{message}", where
755 @channels[m.channel] = IRCChannel.new(m.channel) unless(@channels.has_key?(m.channel))
757 debug "joined channel #{m.channel}"
758 log "@ Joined channel #{m.channel}", m.channel
760 log "@ #{m.sourcenick} joined channel #{m.channel}", m.channel
761 @channels[m.channel].users[m.sourcenick] = Hash.new
762 @channels[m.channel].users[m.sourcenick]["mode"] = ""
765 @plugins.delegate("listen", m)
766 @plugins.delegate("join", m)
771 debug "left channel #{m.channel}"
772 log "@ Left channel #{m.channel} (#{m.message})", m.channel
773 @channels.delete(m.channel)
775 log "@ #{m.sourcenick} left channel #{m.channel} (#{m.message})", m.channel
776 @channels[m.channel].users.delete(m.sourcenick)
779 # delegate to plugins
780 @plugins.delegate("listen", m)
781 @plugins.delegate("part", m)
784 # respond to being kicked from a channel
787 debug "kicked from channel #{m.channel}"
788 @channels.delete(m.channel)
789 log "@ You have been kicked from #{m.channel} by #{m.sourcenick} (#{m.message})", m.channel
791 @channels[m.channel].users.delete(m.sourcenick)
792 log "@ #{m.target} has been kicked from #{m.channel} by #{m.sourcenick} (#{m.message})", m.channel
795 @plugins.delegate("listen", m)
796 @plugins.delegate("kick", m)
800 @channels[m.channel] = IRCChannel.new(m.channel) unless(@channels.has_key?(m.channel))
801 @channels[m.channel].topic = m.topic if !m.topic.nil?
802 @channels[m.channel].topic.timestamp = m.timestamp if !m.timestamp.nil?
803 @channels[m.channel].topic.by = m.source if !m.source.nil?
805 debug "topic of channel #{m.channel} is now #{@channels[m.channel].topic}"
808 # delegate a privmsg to auth, keyword or plugin handlers
809 def delegate_privmsg(message)
810 [@auth, @plugins, @keywords].each {|m|
811 break if m.privmsg(message)