2 # -*- coding: utf-8 -*-
5 class arenopage(object):
6 def __init__(self
, config
):
8 self
.folders
, self
.connection_data
, self
.plugins_on_load
= config
.folders
, config
.connection_data
, config
.plugins_auto_load
10 print "You have error in config file!"
13 self
.irc
= socket
.socket()
14 connect
= self
.irc
.connect((self
.connection_data
['host'], self
.connection_data
['port']))
15 self
.query("NICK %s" % self
.connection_data
['nick'])
16 self
.query("USER %s host server : %s" % (self
.connection_data
['ident'], self
.connection_data
['name']))
17 if self
.connection_data
['password']:
18 self
.query("PRIVMSG NickServ :IDENTIFY %s" % self
.connection_data
['password'])
19 for channel
in self
.connection_data
['channels']:
20 self
.query("JOIN %s" % channel
)
22 self
.do_action(self
.irc
.recv(500).split('\r\n')[0])
25 def query(self
, query
):
26 self
.irc
.send(query
+ '\r\n')
28 def do_action(self
, data
):
30 Parse data, autoload plugins.
33 regexp
= re
.compile(':(.*)!n=(.*) ([A-Z]+) :{0,1}(#{0,1}[A-Za-z0-9\-\_\.]*)\s*:{0,1}(.*)')
34 check
= regexp
.match(data
)
36 'nick' : check
.group(1),
37 'host' : check
.group(2),
38 'action' : check
.group(3),
39 'to' : check
.group(4),
40 'msg' : check
.group(5)
43 for plugin
in self
.plugins_on_load
:
44 self
.load_plugin(plugin
)
48 def load_plugin(self
, plugin
= None):
52 check
= re
.compile("^!%s (.*)" % self
.connection_data
['nick']).match(self
.data
['msg']).group(1).split()
53 plugin_data
= { 'name' : check
[0], 'args' : check
[1:] }
55 plugin_data
= { 'name' : plugin
, 'args' : '' }
56 if not self
.plugins
.has_key(plugin_data
['name']):
58 imported
= __import__(plugin_data
['name'])
59 self
.plugin
= imported
.plugin()
60 self
.plugins
[plugin_data
['name']] = self
.plugin
61 for plugin
in self
.plugins
:
62 getattr(self
.plugins
[plugin
], 'install')(self
, plugin_data
['args'])
68 def send_msg(self
, msg
, to
= None):
70 for channel
in self
.connection_data
['channels']:
71 self
.query("PRIVMSG %s :%s" % (channel
, msg
))
72 elif isinstance(to
, list):
74 self
.query("PRVMSG %s :%s" % (receiver
, msg
))
75 elif isinstance(to
, str):
76 self
.query("PRIVMSG %s :%s" % (to
, msg
))