Made a DNS module\!
[scrappy.git] / modules / karma / karma.py
blob6d1a56e67f2e8e15151fb25d91731bc3dc823af1
1 #karma module for scrappy
3 import re
5 plusexp = re.compile('\+\+$')
6 minusexp = re.compile('\-\-$')
8 #this needs to be stored in sql or a text file or something
9 karma = {}
11 def init(scrap):
12 scrap.register_event("msg", karma_look)
13 scrap.register_event("msg", karma_cmd)
15 def karma_look(c,list,bot):
16 """ Should not be called directly """
17 nick = list[0]
18 if list[3] == False:
19 if plusexp.search(list[4]):
20 name = list[4].split("++")[0]
21 newname = name.lower()
22 if newname == nick.lower():
23 c.privmsg(list[5], "No touching yourself, %s." % nick)
24 return
25 try:
26 karma[newname] = karma[newname] + 1
27 except KeyError:
28 karma[newname] = 1
30 c.privmsg(list[5],"%s karma increased to %s" %
31 (name,karma[newname]))
32 if minusexp.search(list[4]):
33 name = list[4].split("--")[0]
34 newname = name.lower()
35 if newname == nick.lower():
36 c.privmsg(list[5], "No touching yourself, %s." % nick)
37 return
38 try:
39 karma[newname] = karma[newname] - 1
40 except KeyError:
41 karma[newname] = -1
43 c.privmsg(list[5],"%s karma decreased to %s" %
44 (name,karma[newname]))
46 def karma_cmd(c,list,bot):
47 """ Tells the karma of the argument. """
48 cmd = list[4].split(" ")[0]
50 if list[3] and cmd == "karma":
51 name = list[4].split(" ")[1]
52 newname = name.lower()
54 try:
55 karma[newname] = karma[newname]
56 except KeyError:
57 c.privmsg(list[5],"%s is not in the karma database." %
58 name)
59 return
61 c.privmsg(list[5],"%s karma is %s" % (name,karma[newname]))