Skip to content

Commit 561ad81

Browse files
committed
Make sure karma can only be set in channels not in PMs
1 parent 8857dc7 commit 561ad81

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

plugins/karma.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from collections import defaultdict
55

6+
import sqlalchemy
67
from sqlalchemy import Table, String, Column, Integer, PrimaryKeyConstraint
78

89
from cloudbot import hook
@@ -22,9 +23,20 @@
2223
)
2324

2425

26+
@hook.on_start
27+
def remove_non_channel_points(db):
28+
"""Temporary on_start hook to remove non-channel points"""
29+
db.execute(karma_table.delete().where(sqlalchemy.not_(karma_table.c.chan.startswith('#'))))
30+
db.commit()
31+
32+
2533
@hook.command("pp", "addpoint")
2634
def addpoint(text, nick, chan, db, conn):
2735
"""<thing> - adds a point to the <thing>"""
36+
if nick.casefold() == chan.casefold():
37+
# This is a PM, don't set points in a PM
38+
return
39+
2840
text = text.strip()
2941
karma = db.execute("select score from karma where name = :name and chan = :chan and thing = :thing", {'name': nick, 'chan': chan, 'thing': text.lower()}).fetchone()
3042
if karma:

0 commit comments

Comments
 (0)