Skip to content

Commit d7624dd

Browse files
authored
Merge pull request CloudBotIRC#132 from linuxdaemon/gonzobot+karma-only-channels
Make sure karma can only be set in channels not in PMs
2 parents cbdaf9f + 0777cba commit d7624dd

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

plugins/karma.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
from collections import defaultdict
44

5+
import sqlalchemy
56
from sqlalchemy import Table, String, Column, Integer, PrimaryKeyConstraint
67

78
from cloudbot import hook
@@ -21,9 +22,20 @@
2122
)
2223

2324

25+
@hook.on_start
26+
def remove_non_channel_points(db):
27+
"""Temporary on_start hook to remove non-channel points"""
28+
db.execute(karma_table.delete().where(sqlalchemy.not_(karma_table.c.chan.startswith('#'))))
29+
db.commit()
30+
31+
2432
@hook.command("pp", "addpoint")
2533
def addpoint(text, nick, chan, db):
2634
"""<thing> - adds a point to the <thing>"""
35+
if nick.casefold() == chan.casefold():
36+
# This is a PM, don't set points in a PM
37+
return
38+
2739
text = text.strip()
2840
karma = db.execute("select score from karma where name = :name and chan = :chan and thing = :thing",
2941
{'name': nick, 'chan': chan, 'thing': text.lower()}).fetchone()
@@ -55,6 +67,10 @@ def re_addpt(match, nick, chan, db, conn, notice):
5567
@hook.command("mm", "rmpoint")
5668
def rmpoint(text, nick, chan, db):
5769
"""<thing> - subtracts a point from the <thing>"""
70+
if nick.casefold() == chan.casefold():
71+
# This is a PM, don't set points in a PM
72+
return
73+
5874
text = text.strip()
5975
karma = db.execute("select score from karma where name = :name and chan = :chan and thing = :thing",
6076
{'name': nick, 'chan': chan, 'thing': text.lower()}).fetchone()

0 commit comments

Comments
 (0)