-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkarma.py
More file actions
100 lines (90 loc) · 3.06 KB
/
Copy pathkarma.py
File metadata and controls
100 lines (90 loc) · 3.06 KB
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
from willie.tools import Nick
from willie.module import commands, example, priority, rule
import re
try:
import imp
import sys
from permissions import perm_chk
except:
try:
ffp, pathname, description = imp.find_module('permissions',['/home/dropbox/Dropbox/WillieBot'])
permissions = imp.load_source('permissions', pathname, ffp)
sys.modules['permissions'] = permissions
finally:
if ffp:
ffp.close()
from permissions import perm_chk
def setup(willie):
Db = willie.db.connect()
cur = Db.cursor()
cur.execute('create table if not exists karma_table (karmatag , karma, Primary Key (karmatag))')
Db.close()
@commands('karma')
def karma_chk(willie, trigger):
if not trigger.group(2):
willie.say("Please specify something to check the karma of.")
return
if not perm_chk(trigger.hostmask, "Bc", willie):
return
karmatag = trigger.group(2).strip()
if karmatag == "":
return
Db = willie.db.connect()
cur = Db.cursor()
params = (karmatag,)
cur.execute('SELECT karma FROM karma_table WHERE Upper(karmatag)=upper(?)', params)
try:
karma = cur.fetchone()[0]
except:
willie.say(u"%s has no karma." % (karmatag))
return
Db.close()
willie.say(u"%s has a karma of %d" % (karmatag,karma))
@rule(".*\+\+\s*$")
def karmaup(willie, trigger):
'''For adding new permsions. Use syntax hostmask Permission'''
if not perm_chk(trigger.hostmask, "Bc", willie) or not "#" == trigger.sender[0]:
return
karmatag = re.sub('(.*?)\:?s*\+\+\s*$',('\\1'), trigger).strip()
if karmatag == "":
return
Db = willie.db.connect()
cur = Db.cursor()
params = (karmatag,)
cur.execute('SELECT karma FROM karma_table WHERE Upper(karmatag)=upper(?)', params)
try:
karma = cur.fetchone()[0]
karma += 1
except:
karma = 1
params = (karmatag,)
cur.execute('Delete from karma_table where Upper(karmatag)=upper(?)', params)
params = (karmatag, karma)
cur.execute('Insert Into karma_table VALUES (?, ?)', params)
Db.commit()
Db.close()
willie.say(u"%s now has a karma of %d" % (karmatag, karma))
@rule(".*--\s*$")
def karmadown(willie, trigger):
'''For adding new permsions. Use syntax hostmask Permission'''
if not perm_chk(trigger.hostmask, "Bc", willie) or not "#" == trigger.sender[0]:
return
karmatag = re.sub('(.*?):?(\s)*--\s*$',('\\1'), trigger).strip()
if karmatag == "":
return
Db = willie.db.connect()
cur = Db.cursor()
params = (karmatag,)
cur.execute(u'SELECT karma FROM karma_table WHERE Upper(karmatag)=upper(?)', params)
try:
karma = cur.fetchone()[0]
karma -= 1
except:
karma = -1
params = (karmatag,)
cur.execute('Delete from karma_table where Upper(karmatag)=upper(?)', params)
params = (karmatag, karma)
cur.execute('Insert Into karma_table VALUES (?, ?)', params)
Db.commit()
Db.close()
willie.say(u"%s now has a karma of %d" % (karmatag, karma))