4 # Author: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
5 # Copyright (C) 2006 Giuseppe Bilotta
7 # Based on an idea by hagabaka (Yaohan Chen <yaohan.chen@gmail.com>)
9 # This plugin is used to grab messages from eggdrops (or other bots) that link
10 # channels from different networks. For the time being, a PRIVMSG echoed by an
11 # eggdrop is assumed to be in the form:
12 # <eggdrop> (nick@network) text of the message
13 # (TODO make it configurable) and it's fed back to the message delegators.
15 # This plugin also shows how to create 'fake' messages from a plugin, letting
17 # TODO a possible enhancement to the Irc framework could be to create 'fake'
18 # servers to make this even easier.
19 class LinkBot < Plugin
20 BotConfig.register BotConfigArrayValue.new('linkbot.nicks',
22 :desc => "Nick(s) of the bots that act as channel links across networks")
24 # Initialize the plugin
31 linkbots = @bot.config['linkbot.nicks']
32 return if linkbots.empty?
33 return unless linkbots.include?(m.sourcenick)
34 return unless m.kind_of?(PrivMessage)
35 # Now we know that _m_ is a PRIVMSG from a linkbot. Let's split it
36 # in nick, network, message
37 if m.message.match(/^\((\w+?)@(\w+?)\)\s+(.*)$/)
42 debug "#{m.sourcenick} reports that #{new_nick} said #{message.inspect} on #{network}"
43 # One way to pass the new message back to the bot is to create a PrivMessage
44 # and delegate it to the plugins
45 new_m = PrivMessage.new(@bot, m.server, m.server.user(new_nick), m.target, message)
46 @bot.plugins.delegate "listen", new_m
47 @bot.plugins.privmsg(new_m) if new_m.address?
49 ## Another way is to create a data Hash with source, target and message keys
50 ## and then letting the bot client :privmsg handler handle it
51 ## Note that this will also create irclog entries for the fake PRIVMSG
52 ## TODO we could probably add a :no_irc_log entry to the data passed to the
53 ## @bot.client handlers, or something like that
55 # :source => m.server.user(new_nick)
59 # @bot.client[:privmsg].call(data)