Added the irclog django project
[pyIRCbot.git] / pyircbot.py
blob4bad749bf3480a795a15a77cf0d740bcb378146d
1 import os
2 import sys
4 from plugins import Plugins
5 import configuration as conf
6 from debug import Debug
8 # libs
9 if conf.LIBS_PATH not in sys.path:
10 sys.path.append(conf.LIBS_PATH)
11 import irclib
14 class PyIRCBot(Plugins, Debug):
15 def __init__(self):
16 Plugins.__init__(self, conf.PLUGIN_PATH)
18 def connect(self):
19 """Connect to host. Set name. Identify"""
20 self.irc = irclib.IRC()
21 self.server = self.irc.server()
22 self.server.connect(conf.CONNECT_HOST, 6667, conf.IRC_NAME,
23 conf.IRC_PASSWORD, conf.IRC_IDENT, conf.IRC_REALNAME)
24 self.server.join(conf.CONNECT_CHANNEL)
26 def run_plugins(self):
27 """Run each plugin"""
28 # get the message and save it.
29 self.server.msg_data = self.server.process_data()
30 # save msg dict as msg_data['msg_list']
31 # no more message split needed ;)
32 try:
33 self.server.msg_data['msg_list'] = \
34 self.server.msg_data['args'][0].split()
35 except (IndexError, TypeError):
36 self.server.msg_data['msg_list'] = ''
37 for plugin in self.plugins:
38 plugin(self.server)
40 def loop(self):
41 """Start the main loop."""
42 while self.server.connected:
43 self.run_plugins()
44 self.debug()
47 if __name__ == "__main__":
48 bot = PyIRCBot()
49 try:
50 # load plugins
51 bot.plugins_load()
52 # connect to server
53 bot.connect()
54 # start the loop
55 bot.loop()
56 except KeyboardInterrupt:
57 print "Exit."