Compare commits
2 commits
57f591d0a2
...
2a05edf78d
Author | SHA1 | Date | |
---|---|---|---|
2a05edf78d | |||
b0ad45e935 |
1 changed files with 23 additions and 13 deletions
|
@ -103,7 +103,7 @@ def optout(msg):
|
||||||
db_session.add(entry)
|
db_session.add(entry)
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
|
|
||||||
reply = "@" + msg.user.username
|
reply = "@" + msg.user.username
|
||||||
reply += " you have been removed from the karma table"
|
reply += " you have been removed from the karma table"
|
||||||
send(msg.channel_id, reply)
|
send(msg.channel_id, reply)
|
||||||
|
|
||||||
|
@ -154,8 +154,18 @@ def karma(room):
|
||||||
reply = "Karma standings\n\n"
|
reply = "Karma standings\n\n"
|
||||||
results = Karma.query.filter(Karma.chanid == room).order_by(Karma.karma.desc()).all()
|
results = Karma.query.filter(Karma.chanid == room).order_by(Karma.karma.desc()).all()
|
||||||
for entry in results:
|
for entry in results:
|
||||||
user, meta = pnutpy.api.get_user(entry.userid)
|
try:
|
||||||
reply += user.username + ": " + str(entry.karma) + "\n"
|
user, meta = pnutpy.api.get_user(entry.userid)
|
||||||
|
reply += user.username + ": " + str(entry.karma) + "\n"
|
||||||
|
|
||||||
|
except pnutpy.errors.PnutMissing:
|
||||||
|
del_karma = Karma.query.filter(Karma.userid == entry.userid).one_or_none()
|
||||||
|
if del_karma:
|
||||||
|
db_session.delete(del_karma)
|
||||||
|
del_counter = MdnpRequests.query.filter(MdnpRequests.userid == entry.userid).one_or_none()
|
||||||
|
if del_counter:
|
||||||
|
db_session.delete(del_counter)
|
||||||
|
db_session.commit()
|
||||||
send(room, reply)
|
send(room, reply)
|
||||||
|
|
||||||
def chimpnut(msg):
|
def chimpnut(msg):
|
||||||
|
@ -163,7 +173,7 @@ def chimpnut(msg):
|
||||||
if prefs is None:
|
if prefs is None:
|
||||||
prefs = Preferences(userid=msg.user.id, chimpnut=False)
|
prefs = Preferences(userid=msg.user.id, chimpnut=False)
|
||||||
db_session.add(prefs)
|
db_session.add(prefs)
|
||||||
|
|
||||||
if prefs.chimpnut:
|
if prefs.chimpnut:
|
||||||
prefs.chimpnut = False
|
prefs.chimpnut = False
|
||||||
reply = "@" + msg.user.username + " ChimPnut alert is now disabled"
|
reply = "@" + msg.user.username + " ChimPnut alert is now disabled"
|
||||||
|
@ -182,16 +192,16 @@ def on_command(msg):
|
||||||
|
|
||||||
elif args[0] == "!botsnack":
|
elif args[0] == "!botsnack":
|
||||||
botsnack(msg.channel_id)
|
botsnack(msg.channel_id)
|
||||||
|
|
||||||
elif args[0] == "!botdrink":
|
elif args[0] == "!botdrink":
|
||||||
botdrink(msg.channel_id)
|
botdrink(msg.channel_id)
|
||||||
|
|
||||||
elif args[0] == "!optout":
|
elif args[0] == "!optout":
|
||||||
optout(msg)
|
optout(msg)
|
||||||
|
|
||||||
elif args[0] == "!optin":
|
elif args[0] == "!optin":
|
||||||
optin(msg)
|
optin(msg)
|
||||||
|
|
||||||
elif args[0] == "!chimpnut":
|
elif args[0] == "!chimpnut":
|
||||||
chimpnut(msg)
|
chimpnut(msg)
|
||||||
|
|
||||||
|
@ -215,7 +225,7 @@ def on_vote(msg, matcher):
|
||||||
reply += " silly human, your karma must be decided by others!"
|
reply += " silly human, your karma must be decided by others!"
|
||||||
send(msg.channel_id, reply)
|
send(msg.channel_id, reply)
|
||||||
return
|
return
|
||||||
|
|
||||||
except pnutpy.errors.PnutMissing:
|
except pnutpy.errors.PnutMissing:
|
||||||
reply = "@" + msg.user.username
|
reply = "@" + msg.user.username
|
||||||
reply += " I do not know who that is"
|
reply += " I do not know who that is"
|
||||||
|
@ -267,7 +277,7 @@ def on_mndp(msg):
|
||||||
|
|
||||||
if "NowPlaying" not in tags:
|
if "NowPlaying" not in tags:
|
||||||
return
|
return
|
||||||
|
|
||||||
for m in mentions:
|
for m in mentions:
|
||||||
addkarma = False
|
addkarma = False
|
||||||
try:
|
try:
|
||||||
|
@ -307,7 +317,7 @@ def on_message(ws, message):
|
||||||
logger.debug("connection_id: " + msg['meta']['connection_id'])
|
logger.debug("connection_id: " + msg['meta']['connection_id'])
|
||||||
subscribe(msg['meta']['connection_id'])
|
subscribe(msg['meta']['connection_id'])
|
||||||
return
|
return
|
||||||
|
|
||||||
if 'data' in msg:
|
if 'data' in msg:
|
||||||
|
|
||||||
if "channel_type" in msg['meta'] and msg['meta']['channel_type'] == "io.pnut.core.chat":
|
if "channel_type" in msg['meta'] and msg['meta']['channel_type'] == "io.pnut.core.chat":
|
||||||
|
@ -367,7 +377,7 @@ def on_open(ws):
|
||||||
step += 1
|
step += 1
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
logger.debug("*** terminate ***")
|
logger.debug("*** terminate ***")
|
||||||
|
|
||||||
t = threading.Thread(target=run)
|
t = threading.Thread(target=run)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
@ -420,7 +430,7 @@ def main():
|
||||||
ws_url += "?access_token=" + config['ACCESS_TOKEN']
|
ws_url += "?access_token=" + config['ACCESS_TOKEN']
|
||||||
|
|
||||||
# setup the websocket connection
|
# setup the websocket connection
|
||||||
ws = websocket.WebSocketApp(ws_url, on_message=on_message,
|
ws = websocket.WebSocketApp(ws_url, on_message=on_message,
|
||||||
on_error=on_error, on_close=on_close)
|
on_error=on_error, on_close=on_close)
|
||||||
ws.on_open = on_open
|
ws.on_open = on_open
|
||||||
r = True
|
r = True
|
||||||
|
|
Loading…
Reference in a new issue