-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
108 lines (88 loc) · 3.05 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
a = 34123
__creator__ = "Red_M"
__credits__ = ["neersighted","Luke","Lahwran"]
__email__ = "[email protected]"
__web__ = "http://red-m.net"
__repo__ = "https://github.com/Red-M/frogbot"
import os
import Queue
import sys
import time
sys.path += ['plugins'] # so 'import hook' works without duplication
sys.path += ['core'] # so 'import IRC' works without duplication
sys.path += ['lib']
os.chdir(sys.path[0] or '.') # do stuff relative to the install directory
class Bot(object):
pass
print "Frogbot made by "+__creator__+" (email:"+__email__+")\nwebsite:"+__web__+" repo:"+__repo__
print "Frogbot had assitance from "+', '.join(__credits__)
bot = Bot()
bot.start_time = time.time()
print 'Loading plugins'
# bootstrap the reloader
eval(compile(open(os.path.join('core', 'reload.py'), 'U').read(),
os.path.join('core', 'reload.py'), 'exec'))
reload(init=True)
config()
if not hasattr(bot, 'config'):
exit()
print 'Connecting to IRC'
bot.conns = {}
bot.cooldown = {}
bot.auth = {}
bot.seen = {}
bot.chanseen = {}
bot.twitterlist = {}
bot.twitterlists = {}
bot.connected={}
bot.path=__file__
try:
for name, conf in bot.config['connections'].iteritems():
if conf.get('ssl'):
bot.conns[name] = SSLIRC(conf['server'], conf['nick'], conf=conf,
port=conf.get('port', 6667), channels=conf['channels'],
ignore_certificate_errors=conf.get('ignore_cert', True),name=name)
else:
bot.conns[name] = IRC(conf['server'], conf['nick'], conf=conf,
port=conf.get('port', 6667), channels=conf['channels'],name=name)
except Exception, e:
print 'ERROR: malformed config file', e
sys.exit()
bot.term=False
for xcon in bot.conns:
bot.cooldown[str(bot.conns[xcon].name)]={}
bot.auth[str(bot.conns[xcon].name)]={}
bot.auth[str(bot.conns[xcon].name)]["owner"]={}
bot.auth[str(bot.conns[xcon].name)]["superadmin"]={}
bot.auth[str(bot.conns[xcon].name)]["admin"]={}
bot.auth[str(bot.conns[xcon].name)]["voiced"]={}
bot.auth[str(bot.conns[xcon].name)]["bots"]={}
bot.auth[str(bot.conns[xcon].name)]["none"]={}
bot.seen[str(bot.conns[xcon].name)]={}
bot.connected[str(bot.conns[xcon].name)]=0
bot.chanseen[str(bot.conns[xcon].name)]={}
for channels in bot.conns[xcon].conf["channels"]:
bot.chanseen[str(bot.conns[xcon].name)][channels]=["start-up"]
bot.test={}
bot.test["test"]=0
bot.persist_dir = os.path.abspath('persist')
bot.logs_dir = os.path.abspath('logs')
if not os.path.exists(bot.logs_dir):
os.mkdir(bot.logs_dir)
if not os.path.exists(bot.persist_dir):
os.mkdir(bot.persist_dir)
print 'Running main loop'
while True:
if bot.term==True:
os._exit(0)
reload() # these functions only do things
config() # if changes have occured
for conn in bot.conns.itervalues():
try:
out = conn.out.get_nowait()
main(conn, out)
except Queue.Empty:
pass
while all(conn.out.empty() for conn in bot.conns.itervalues()):
time.sleep(.15)