~ubuntu-branches/ubuntu/precise/gozerbot/precise

« back to all changes in this revision

Viewing changes to gozerplugs/plugs/relay.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2008-06-02 19:26:39 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080602192639-3rn65nx4q1sgd6sy
Tags: 0.8.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
#
4
4
 
5
 
""" relay between bot/channels """
 
5
"""
 
6
 the bot can relay between different bots both IRC and Jabber ones.
 
7
 relay uses the following format.
 
8
 
 
9
 <botname> <channel> <botname> <channel>
 
10
 
 
11
 <------ from -----> <------- to ------>
 
12
"""
6
13
 
7
14
__copyright__ = 'this file is in the public domain'
 
15
__gendoclast__ = ['relay-del', ]
8
16
 
9
17
from gozerbot.commands import cmnds
10
18
from gozerbot.examples import examples
135
143
 
136
144
def cbMessage(bot, msg):
137
145
    """ jabber relay message callback """
138
 
    if not msg.groupchat:
 
146
    if msg.usercmnd and not msg.groupchat:
139
147
        return
140
 
    result = "[%s] %s" % (msg.nick, msg.origtxt)
 
148
    if bot.google:
 
149
        result = "[%s] %s" % (msg.userhost, msg.origtxt)
 
150
    else:
 
151
        result = "[%s] %s" % (msg.nick, msg.origtxt)
141
152
    relay.check(bot.name, msg.channel, result, fromm=msg.userhost)
142
153
 
143
154
jcallbacks.add('Message', cbMessage, prerelay, threaded=True)
199
210
def jabberprerelaysay(bot, jmsg):
200
211
    """ precondition on bot.say callbacks """
201
212
    if jmsg:
202
 
        return relay.wouldrelay(bot.name, jmsg.to)
 
213
        return relay.wouldrelay(bot.name, jmsg.to.split('/')[0])
203
214
 
204
215
def jabbersaycb(bot, jmsg):
205
216
    """ callback for bots output """
 
217
    if jmsg.botoutput and not jmsg.groupchat:
 
218
        return
206
219
    try:
207
 
        relay.check(bot.name, jmsg.to, "[bot] %s" % jmsg.txt, \
208
 
fromm=jmsg.stripped)
 
220
        relay.check(bot.name, jmsg.to.split('/')[0], "[%s] %s" % (bot.nick, \
 
221
jmsg.txt), fromm=bot.name)
209
222
    except AttributeError:
210
223
        return
211
224
        
239
252
 
240
253
cmnds.add('relay-add', handle_relayadd, 'OPER')
241
254
examples.add('relay-add', 'relay-add <botname> <channel> <botname> \
242
 
<channel> .. add bot/channel to relay', 'relay-add main #r5 main #bartbot')
 
255
<channel> .. add bot/channel to relay', 'relay-add main #dunkbots test \
 
256
#dunkbots')
243
257
 
244
258
def handle_relaydel(bot, ievent):
245
259
    """ relay-del <botname> <channel> <botname> <channel> .. delete a relay """
262
276
 
263
277
cmnds.add('relay-del', handle_relaydel, 'OPER')
264
278
examples.add('relay-del', 'relay-del <botname> <channel> <botname> \
265
 
<channel> .. delete bot/channel from relay', 'relay-del main #gozerbot \
266
 
main #dunkbots')
 
279
<channel> .. delete bot/channel from relay', 'relay-del main #dunkbots \
 
280
test #dunkbots')