/[shmookey]/killbot/easybot.py


UCC Code Repository

Contents of /killbot/easybot.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 122 - (show annotations) (download) (as text)
Wed Sep 16 01:39:09 2009 UTC (12 years, 2 months ago) by shmookey
File MIME type: text/x-python
File size: 1076 byte(s)
Added multi-channel support.

1 ''' easybot.py
2 Easier to use abstraction for making a bot than the one that comes with irclib.
3 Written by Luke Williams <[email protected]>
4 Distributed under an MIT-style license - see the LICENSE file for details.
5 '''
6
7 from ircbot import SingleServerIRCBot
8 from irclib import nm_to_n
9
10 class EasyBot(SingleServerIRCBot):
11 def __init__(self, nickname, server, port=6667):
12 SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
13 self.welcome_hook = False
14 self.message_hook = False
15
16 def on_nicknameinuse(self, c, e):
17 c.nick(c.get_nickname() + "_")
18
19 def on_welcome(self, c, e):
20 if self.welcome_hook: self.welcome_hook (c)
21
22 def on_privmsg(self, c, e):
23 pass
24
25 def on_pubmsg(self, c, e):
26 self.do_command(e, e.arguments()[0])
27
28 def do_command(self, e, cmd):
29 nick = nm_to_n(e.source())
30 c = self.connection
31 channel = e.target ()
32
33 chobj = self.channels [channel]
34 opers = chobj.opers()
35 if self.message_hook: self.message_hook (chobj = c, channel = channel, msg_from = nick, msg = e.arguments()[0], is_oper = (nick in opers))
36

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26