-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·53 lines (42 loc) · 1.27 KB
/
main.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
#!/usr/bin/python2
from ConfigParser import ConfigParser
from ircbot import IRCbot
from roll import parseRoll
def main():
cp = ConfigParser()
if not cp.read('dice.conf'):
f = open('dice.conf', 'w')
print >> f, '[bot]'
print >> f, 'nickname = dicebot'
print >> f, 'channel = #dicebot'
print >> f, 'server = irc.freenode.org'
f.close()
print 'Please modify dice.conf and restart.'
exit(1)
nickname = cp.get('bot', 'nickname')
channel = cp.get('bot', 'channel')
server = cp.get('bot', 'server')
bot = DiceBot(nickname, [channel])
bot.connect(server, 6667)
class DiceBot(IRCbot):
def privmsg(self, src, dest, msg):
rolls = parseRoll(msg)
if not rolls:
return
lst = []
for r in rolls:
name = str(r)
total, indiv = r()
if r.expand:
i = ','.join(map(str, indiv))
s = '%s (%s) = %s' % (name, i, total)
else:
s = '%s = %s' % (name, total)
lst.append(s)
out = '%s: [%s]' % (src[0], '] ['.join(lst))
if dest.startswith('#'):
d = dest
else:
d = src[0]
self.send2(None, 'PRIVMSG', [d], out)
main()