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
77 # bot's object registry, plugins get an interface to this for persistant
78 # storage (hash interface tied to a bdb file, plugins use Accessors to store
79 # and restore objects in their own namespaces.)
82 # bot's httputil help object, for fetching resources via http. Sets up
83 # proxies etc as defined by the bot configuration/environment
86 # create a new IrcBot with botclass +botclass+
87 def initialize(botclass, params = {})
88 # BotConfig for the core bot
89 BotConfig.register BotConfigStringValue.new('server.name',
90 :default => "localhost", :requires_restart => true,
91 :desc => "What server should the bot connect to?",
93 BotConfig.register BotConfigIntegerValue.new('server.port',
94 :default => 6667, :type => :integer, :requires_restart => true,
95 :desc => "What port should the bot connect to?",
96 :validate => Proc.new {|v| v > 0}, :wizard => true)
97 BotConfig.register BotConfigStringValue.new('server.password',
98 :default => false, :requires_restart => true,
99 :desc => "Password for connecting to this server (if required)",
101 BotConfig.register BotConfigStringValue.new('server.bindhost',
102 :default => false, :requires_restart => true,
103 :desc => "Specific local host or IP for the bot to bind to (if required)",
105 BotConfig.register BotConfigIntegerValue.new('server.reconnect_wait',
106 :default => 5, :validate => Proc.new{|v| v >= 0},
107 :desc => "Seconds to wait before attempting to reconnect, on disconnect")
108 BotConfig.register BotConfigStringValue.new('irc.nick', :default => "rbot",
109 :desc => "IRC nickname the bot should attempt to use", :wizard => true,
110 :on_change => Proc.new{|bot, v| bot.sendq "NICK #{v}" })
111 BotConfig.register BotConfigStringValue.new('irc.user', :default => "rbot",
112 :requires_restart => true,
113 :desc => "local user the bot should appear to be", :wizard => true)
114 BotConfig.register BotConfigArrayValue.new('irc.join_channels',
115 :default => [], :wizard => true,
116 :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'")
117 BotConfig.register BotConfigIntegerValue.new('core.save_every',
118 :default => 60, :validate => Proc.new{|v| v >= 0},
119 # TODO change timer via on_change proc
120 :desc => "How often the bot should persist all configuration to disk (in case of a server crash, for example")
121 BotConfig.register BotConfigFloatValue.new('server.sendq_delay',
122 :default => 2.0, :validate => Proc.new{|v| v >= 0},
123 :desc => "(flood prevention) the delay between sending messages to the server (in seconds)",
124 :on_change => Proc.new {|bot, v| bot.socket.sendq_delay = v })
125 BotConfig.register BotConfigIntegerValue.new('server.sendq_burst',
126 :default => 4, :validate => Proc.new{|v| v >= 0},
127 :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",
128 :on_change => Proc.new {|bot, v| bot.socket.sendq_burst = v })
130 @argv = params[:argv]
132 unless FileTest.directory? Config::DATADIR
133 puts "data directory '#{Config::DATADIR}' not found, did you install.rb?"
137 botclass = "/home/#{Etc.getlogin}/.rbot" unless botclass
138 @botclass = botclass.gsub(/\/$/, "")
140 unless FileTest.directory? botclass
141 puts "no #{botclass} directory found, creating from templates.."
142 if FileTest.exist? botclass
143 puts "Error: file #{botclass} exists but isn't a directory"
146 FileUtils.cp_r Config::DATADIR+'/templates', botclass
149 Dir.mkdir("#{botclass}/logs") unless File.exist?("#{botclass}/logs")
151 @startup_time = Time.new
152 @config = BotConfig.new(self)
153 @timer = Timer::Timer.new(1.0) # only need per-second granularity
154 @registry = BotRegistry.new self
155 @timer.add(@config['core.save_every']) { save } if @config['core.save_every']
159 @httputil = Utils::HttpUtil.new(self)
160 @lang = Language::Language.new(@config['core.language'])
161 @keywords = Keywords.new(self)
162 @auth = IrcAuth.new(self)
164 Dir.mkdir("#{botclass}/plugins") unless File.exist?("#{botclass}/plugins")
165 @plugins = Plugins::Plugins.new(self, ["#{botclass}/plugins"])
167 @socket = IrcSocket.new(@config['server.name'], @config['server.port'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'])
168 @nick = @config['irc.nick']
169 if @config['core.address_prefix']
170 @addressing_prefixes = @config['core.address_prefix'].split(" ")
172 @addressing_prefixes = Array.new
175 @client = IrcClient.new
176 @client["PRIVMSG"] = proc { |data|
177 message = PrivMessage.new(self, data["SOURCE"], data["TARGET"], data["MESSAGE"])
180 @client["NOTICE"] = proc { |data|
181 message = NoticeMessage.new(self, data["SOURCE"], data["TARGET"], data["MESSAGE"])
182 # pass it off to plugins that want to hear everything
183 @plugins.delegate "listen", message
185 @client["MOTD"] = proc { |data|
186 data['MOTD'].each_line { |line|
187 log "MOTD: #{line}", "server"
190 @client["NICKTAKEN"] = proc { |data|
193 @client["BADNICK"] = proc {|data|
194 puts "WARNING, bad nick (#{data['NICK']})"
196 @client["PING"] = proc {|data|
197 # (jump the queue for pongs)
198 @socket.puts "PONG #{data['PINGID']}"
200 @client["NICK"] = proc {|data|
201 sourcenick = data["SOURCENICK"]
203 m = NickMessage.new(self, data["SOURCE"], data["SOURCENICK"], data["NICK"])
204 if(sourcenick == @nick)
207 @channels.each {|k,v|
208 if(v.users.has_key?(sourcenick))
209 log "@ #{sourcenick} is now known as #{nick}", k
210 v.users[nick] = v.users[sourcenick]
211 v.users.delete(sourcenick)
214 @plugins.delegate("listen", m)
215 @plugins.delegate("nick", m)
217 @client["QUIT"] = proc {|data|
218 source = data["SOURCE"]
219 sourcenick = data["SOURCENICK"]
220 sourceurl = data["SOURCEADDRESS"]
221 message = data["MESSAGE"]
222 m = QuitMessage.new(self, data["SOURCE"], data["SOURCENICK"], data["MESSAGE"])
223 if(data["SOURCENICK"] =~ /#{@nick}/i)
225 @channels.each {|k,v|
226 if(v.users.has_key?(sourcenick))
227 log "@ Quit: #{sourcenick}: #{message}", k
228 v.users.delete(sourcenick)
232 @plugins.delegate("listen", m)
233 @plugins.delegate("quit", m)
235 @client["MODE"] = proc {|data|
236 source = data["SOURCE"]
237 sourcenick = data["SOURCENICK"]
238 sourceurl = data["SOURCEADDRESS"]
239 channel = data["CHANNEL"]
240 targets = data["TARGETS"]
241 modestring = data["MODESTRING"]
242 log "@ Mode #{modestring} #{targets} by #{sourcenick}", channel
244 @client["WELCOME"] = proc {|data|
245 log "joined server #{data['SOURCE']} as #{data['NICK']}", "server"
246 debug "I think my nick is #{@nick}, server thinks #{data['NICK']}"
247 if data['NICK'] && data['NICK'].length > 0
250 if(@config['irc.quser'])
251 # TODO move this to a plugin
252 debug "authing with Q using #{@config['quakenet.user']} #{@config['quakenet.auth']}"
253 @socket.puts "PRIVMSG Q@CServe.quakenet.org :auth #{@config['quakenet.user']} #{@config['quakenet.auth']}"
256 @config['irc.join_channels'].each {|c|
257 debug "autojoining channel #{c}"
258 if(c =~ /^(\S+)\s+(\S+)$/i)
265 @client["JOIN"] = proc {|data|
266 m = JoinMessage.new(self, data["SOURCE"], data["CHANNEL"], data["MESSAGE"])
269 @client["PART"] = proc {|data|
270 m = PartMessage.new(self, data["SOURCE"], data["CHANNEL"], data["MESSAGE"])
273 @client["KICK"] = proc {|data|
274 m = KickMessage.new(self, data["SOURCE"], data["TARGET"],data["CHANNEL"],data["MESSAGE"])
277 @client["INVITE"] = proc {|data|
278 if(data["TARGET"] =~ /^#{@nick}$/i)
279 join data["CHANNEL"] if (@auth.allow?("join", data["SOURCE"], data["SOURCENICK"]))
282 @client["CHANGETOPIC"] = proc {|data|
283 channel = data["CHANNEL"]
284 sourcenick = data["SOURCENICK"]
285 topic = data["TOPIC"]
286 timestamp = data["UNIXTIME"] || Time.now.to_i
287 if(sourcenick == @nick)
288 log "@ I set topic \"#{topic}\"", channel
290 log "@ #{sourcenick} set topic \"#{topic}\"", channel
292 m = TopicMessage.new(self, data["SOURCE"], data["CHANNEL"], timestamp, data["TOPIC"])
295 @plugins.delegate("listen", m)
296 @plugins.delegate("topic", m)
298 @client["TOPIC"] = @client["TOPICINFO"] = proc {|data|
299 channel = data["CHANNEL"]
300 m = TopicMessage.new(self, data["SOURCE"], data["CHANNEL"], data["UNIXTIME"], data["TOPIC"])
303 @client["NAMES"] = proc {|data|
304 channel = data["CHANNEL"]
305 users = data["USERS"]
306 unless(@channels[channel])
307 puts "bug: got names for channel '#{channel}' I didn't think I was in\n"
310 @channels[channel].users.clear
312 @channels[channel].users[u[0].sub(/^[@&~+]/, '')] = ["mode", u[1]]
315 @client["UNKNOWN"] = proc {|data|
316 debug "UNKNOWN: #{data['SERVERSTRING']}"
320 # connect the bot to IRC
322 trap("SIGTERM") { quit }
323 trap("SIGHUP") { quit }
324 trap("SIGINT") { quit }
328 raise "failed to connect to IRC server at #{@config['server.name']} #{@config['server.port']}: " + e
330 @socket.puts "PASS " + @config['server.password'] if @config['server.password']
331 @socket.puts "NICK #{@nick}\nUSER #{@config['irc.user']} 4 #{@config['server.name']} :Ruby bot. (c) Tom Gilbert"
334 # begin event handling loop
343 break unless reply = @socket.gets
344 @client.process reply
347 rescue TimeoutError, SocketError => e
348 puts "network exception: connection closed: #{e}"
349 puts e.backtrace.join("\n")
350 @socket.close # now we reconnect
351 rescue => e # TODO be selective, only grab Network errors
352 puts "unexpected exception: connection closed: #{e}"
353 puts e.backtrace.join("\n")
361 puts "waiting to reconnect"
362 sleep @config['server.reconnect_wait']
366 # type:: message type
367 # where:: message target
368 # message:: message text
369 # send message +message+ of type +type+ to target +where+
370 # Type can be PRIVMSG, NOTICE, etc, but those you should really use the
371 # relevant say() or notice() methods. This one should be used for IRCd
372 # extensions you want to use in modules.
373 def sendmsg(type, where, message)
374 # limit it 440 chars + CRLF.. so we have to split long lines
375 left = 440 - type.length - where.length - 3
377 if(left >= message.length)
378 sendq("#{type} #{where} :#{message}")
379 log_sent(type, where, message)
382 line = message.slice!(0, left)
383 lastspace = line.rindex(/\s+/)
385 message = line.slice!(lastspace, line.length) + message
386 message.gsub!(/^\s+/, "")
388 sendq("#{type} #{where} :#{line}")
389 log_sent(type, where, line)
390 end while(message.length > 0)
393 def sendq(message="")
395 @socket.queue(message)
398 # send a notice message to channel/nick +where+
399 def notice(where, message)
400 message.each_line { |line|
402 next unless(line.length > 0)
403 sendmsg("NOTICE", where, line)
407 # say something (PRIVMSG) to channel/nick +where+
408 def say(where, message)
409 message.to_s.gsub(/[\r\n]+/, "\n").each_line { |line|
411 next unless(line.length > 0)
412 unless((where =~ /^#/) && (@channels.has_key?(where) && @channels[where].quiet))
413 sendmsg("PRIVMSG", where, line)
418 # perform a CTCP action with message +message+ to channel/nick +where+
419 def action(where, message)
420 sendq("PRIVMSG #{where} :\001ACTION #{message}\001")
422 log "* #{@nick} #{message}", where
423 elsif (where =~ /^(\S*)!.*$/)
424 log "* #{@nick}[#{where}] #{message}", $1
426 log "* #{@nick}[#{where}] #{message}", where
430 # quick way to say "okay" (or equivalent) to +where+
432 say where, @lang.get("okay")
435 # log message +message+ to a file determined by +where+. +where+ can be a
436 # channel name, or a nick for private message logging
437 def log(message, where="server")
439 stamp = Time.now.strftime("%Y/%m/%d %H:%M:%S")
440 unless(@logs.has_key?(where))
441 @logs[where] = File.new("#{@botclass}/logs/#{where}", "a")
442 @logs[where].sync = true
444 @logs[where].puts "[#{stamp}] #{message}"
445 #debug "[#{stamp}] <#{where}> #{message}"
448 # set topic of channel +where+ to +topic+
449 def topic(where, topic)
450 sendq "TOPIC #{where} :#{topic}"
453 def shutdown(message = nil)
454 trap("SIGTERM", "DEFAULT")
455 trap("SIGHUP", "DEFAULT")
456 trap("SIGINT", "DEFAULT")
457 message = @lang.get("quit") if (message.nil? || message.empty?)
461 @channels.each_value {|v|
462 log "@ quit (#{message})", v.name
464 @socket.puts "QUIT :#{message}"
468 puts "rbot quit (#{message})"
471 # message:: optional IRC quit message
472 # quit IRC, shutdown the bot
473 def quit(message=nil)
478 # totally shutdown and respawn the bot
480 shutdown("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+
520 # if rbot is already taken, this happens:
521 # <giblet> rbot_, nick rbot
522 # --- rbot_ is now known as rbot__
523 # he should of course just keep his existing nick and report the error :P
529 def mode(channel, mode, target)
530 sendq "MODE #{channel} #{mode} #{target}"
533 # m:: message asking for help
534 # topic:: optional topic help is requested for
535 # respond to online help requests
537 topic = nil if topic == ""
540 helpstr = "help topics: core, auth, keywords"
541 helpstr += @plugins.helptopics
542 helpstr += " (help <topic> for more info)"
545 when /^core\s+(.+)$/i
546 helpstr = corehelp $1
549 when /^auth\s+(.+)$/i
550 helpstr = @auth.help $1
552 helpstr = @keywords.help
553 when /^keywords\s+(.+)$/i
554 helpstr = @keywords.help $1
556 unless(helpstr = @plugins.help(topic))
557 helpstr = "no help for topic #{topic}"
564 secs_up = Time.new - @startup_time
565 uptime = Utils.secs_to_string secs_up
566 return "Uptime #{uptime}, #{@plugins.length} plugins active, #{@registry.length} items stored in registry, #{@socket.lines_sent} lines sent, #{@socket.lines_received} received."
572 # handle help requests for "core" topics
573 def corehelp(topic="")
576 return "quit [<message>] => quit IRC with message <message>"
578 return "restart => completely stop and restart the bot (including reconnect)"
580 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"
582 return "part <channel> => part channel <channel>"
584 return "hide => part all channels"
586 return "save => save current dynamic data and configuration"
588 return "rescan => reload modules and static facts"
590 return "nick <nick> => attempt to change nick to <nick>"
592 return "say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>"
594 return "action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>"
596 return "topic <channel> <message> => set topic of <channel> to <message>"
598 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>"
600 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>"
602 return "version => describes software version"
604 return "botsnack => reward #{@nick} for being good"
606 return "hello|hi|hey|yo [#{@nick}] => greet the bot"
608 return "Core help topics: quit, restart, config, join, part, hide, save, rescan, nick, say, action, topic, quiet, talk, version, botsnack, hello"
612 # handle incoming IRC PRIVMSG +m+
617 log "* [#{m.sourcenick}(#{m.sourceaddress})] #{m.message}", m.sourcenick
619 log "* #{m.sourcenick} #{m.message}", m.target
623 log "<#{m.sourcenick}> #{m.message}", m.target
625 log "[#{m.sourcenick}(#{m.sourceaddress})] #{m.message}", m.sourcenick
629 # pass it off to plugins that want to hear everything
630 @plugins.delegate "listen", m
632 if(m.private? && m.message =~ /^\001PING\s+(.+)\001/)
633 notice m.sourcenick, "\001PING #$1\001"
634 log "@ #{m.sourcenick} pinged me"
640 when (/^join\s+(\S+)\s+(\S+)$/i)
641 join $1, $2 if(@auth.allow?("join", m.source, m.replyto))
642 when (/^join\s+(\S+)$/i)
643 join $1 if(@auth.allow?("join", m.source, m.replyto))
645 part m.target if(m.public? && @auth.allow?("join", m.source, m.replyto))
646 when (/^part\s+(\S+)$/i)
647 part $1 if(@auth.allow?("join", m.source, m.replyto))
648 when (/^quit(?:\s+(.*))?$/i)
649 quit $1 if(@auth.allow?("quit", m.source, m.replyto))
651 restart if(@auth.allow?("quit", m.source, m.replyto))
653 join 0 if(@auth.allow?("join", m.source, m.replyto))
655 if(@auth.allow?("config", m.source, m.replyto))
659 when (/^nick\s+(\S+)$/i)
660 nickchg($1) if(@auth.allow?("nick", m.source, m.replyto))
661 when (/^say\s+(\S+)\s+(.*)$/i)
662 say $1, $2 if(@auth.allow?("say", m.source, m.replyto))
663 when (/^action\s+(\S+)\s+(.*)$/i)
664 action $1, $2 if(@auth.allow?("say", m.source, m.replyto))
665 when (/^topic\s+(\S+)\s+(.*)$/i)
666 topic $1, $2 if(@auth.allow?("topic", m.source, m.replyto))
667 when (/^mode\s+(\S+)\s+(\S+)\s+(.*)$/i)
668 mode $1, $2, $3 if(@auth.allow?("mode", m.source, m.replyto))
670 say m.replyto, "pong"
672 if(@auth.allow?("config", m.source, m.replyto))
677 if(auth.allow?("talk", m.source, m.replyto))
679 @channels.each_value {|c| c.quiet = true }
681 when (/^quiet in (\S+)$/i)
683 if(auth.allow?("talk", m.source, m.replyto))
685 where.gsub!(/^here$/, m.target) if m.public?
686 @channels[where].quiet = true if(@channels.has_key?(where))
689 if(auth.allow?("talk", m.source, m.replyto))
690 @channels.each_value {|c| c.quiet = false }
693 when (/^talk in (\S+)$/i)
695 if(auth.allow?("talk", m.source, m.replyto))
696 where.gsub!(/^here$/, m.target) if m.public?
697 @channels[where].quiet = false if(@channels.has_key?(where))
700 when (/^status\??$/i)
701 m.reply status if auth.allow?("status", m.source, m.replyto)
702 when (/^registry stats$/i)
703 if auth.allow?("config", m.source, m.replyto)
704 m.reply @registry.stat.inspect
706 when (/^(help\s+)?config(\s+|$)/)
708 when (/^(version)|(introduce yourself)$/i)
709 say m.replyto, "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"
710 when (/^help(?:\s+(.*))?$/i)
711 say m.replyto, help($1)
712 #TODO move these to a "chatback" plugin
713 when (/^(botsnack|ciggie)$/i)
714 say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
715 say m.replyto, @lang.get("thanks") if(m.private?)
716 when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i)
717 say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?)
718 say m.replyto, @lang.get("hello") if(m.private?)
723 # stuff to handle when not addressed
725 when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$))[\s,-.]+#{@nick}$/i)
726 say m.replyto, @lang.get("hello_X") % m.sourcenick
727 when (/^#{@nick}!*$/)
728 say m.replyto, @lang.get("hello_X") % m.sourcenick
735 # log a message. Internal use only.
736 def log_sent(type, where, message)
740 log "-=#{@nick}=- #{message}", where
741 elsif (where =~ /(\S*)!.*/)
742 log "[-=#{where}=-] #{message}", $1
744 log "[-=#{where}=-] #{message}"
748 log "<#{@nick}> #{message}", where
749 elsif (where =~ /^(\S*)!.*$/)
750 log "[msg(#{where})] #{message}", $1
752 log "[msg(#{where})] #{message}", where
758 @channels[m.channel] = IRCChannel.new(m.channel) unless(@channels.has_key?(m.channel))
760 debug "joined channel #{m.channel}"
761 log "@ Joined channel #{m.channel}", m.channel
763 log "@ #{m.sourcenick} joined channel #{m.channel}", m.channel
764 @channels[m.channel].users[m.sourcenick] = Hash.new
765 @channels[m.channel].users[m.sourcenick]["mode"] = ""
768 @plugins.delegate("listen", m)
769 @plugins.delegate("join", m)
774 debug "left channel #{m.channel}"
775 log "@ Left channel #{m.channel} (#{m.message})", m.channel
776 @channels.delete(m.channel)
778 log "@ #{m.sourcenick} left channel #{m.channel} (#{m.message})", m.channel
779 @channels[m.channel].users.delete(m.sourcenick)
782 # delegate to plugins
783 @plugins.delegate("listen", m)
784 @plugins.delegate("part", m)
787 # respond to being kicked from a channel
790 debug "kicked from channel #{m.channel}"
791 @channels.delete(m.channel)
792 log "@ You have been kicked from #{m.channel} by #{m.sourcenick} (#{m.message})", m.channel
794 @channels[m.channel].users.delete(m.sourcenick)
795 log "@ #{m.target} has been kicked from #{m.channel} by #{m.sourcenick} (#{m.message})", m.channel
798 @plugins.delegate("listen", m)
799 @plugins.delegate("kick", m)
803 @channels[m.channel] = IRCChannel.new(m.channel) unless(@channels.has_key?(m.channel))
804 @channels[m.channel].topic = m.topic if !m.topic.nil?
805 @channels[m.channel].topic.timestamp = m.timestamp if !m.timestamp.nil?
806 @channels[m.channel].topic.by = m.source if !m.source.nil?
808 debug "topic of channel #{m.channel} is now #{@channels[m.channel].topic}"
811 # delegate a privmsg to auth, keyword or plugin handlers
812 def delegate_privmsg(message)
813 [@auth, @plugins, @keywords].each {|m|
814 break if m.privmsg(message)