citruspi

ReactIRC

 1 # karmabot.py
 2 
 3 from ReactIRC import Bot
 4 
 5 bot = Bot()
 6 scores = {}
 7 
 8 
 9 @bot.on(r'^karma$')
10 @bot.on(r'^karma ([\S]+)$')
11 def karma_status(user=None):
12     if user is None:
13         user = bot.context['sender']
14 
15     try:
16         return '{} has {} karma'.format(user,
17                                         scores[user])
18     except KeyError:
19         return '{} has 0 karma'.format(user)
20 
21 
22 @bot.on(r'^([\S]+)(\+\+|\-\-){1}$')
23 def karma_adjustment(user, direction):
24     if user not in scores:
25         scores[user] = 0
26 
27     if direction == '--':
28         scores[user] -= 1
29     elif direction == '++':
30         scores[user] += 1
31 
32 bot.monitor(nick='bot', channels='#bots')

ReactIRC is a flask-inspired library for developing IRC bots. It comes with an embedded web server for receiving POST requests from webhook enabled services.