|
@@ -32,11 +32,32 @@ def get_response(msg, name, score):
|
|
|
@as_plugin
|
|
|
def curse(db, msg):
|
|
|
# TODO might be nice to add subcommands to this later
|
|
|
- name, _ = pop_arg(msg.raw_args)
|
|
|
- score = get_score(db, msg.group_id, name)
|
|
|
- # Note we do this instead of += b/c that can create race conditions in sqlalchemy
|
|
|
- score.curses = score.curses + 1
|
|
|
- return get_response(msg, name, score)
|
|
|
+ name, args = pop_arg(msg.raw_args)
|
|
|
+ if not name.startswith("!"):
|
|
|
+ score = get_score(db, msg.group_id, name)
|
|
|
+ # Note we do this instead of += b/c that can create race conditions in sqlalchemy
|
|
|
+ score.curses = score.curses + 1
|
|
|
+ return get_response(msg, name, score)
|
|
|
+
|
|
|
+ # strip off the '!'
|
|
|
+ subc = name[1:].strip()
|
|
|
+ if len(subc) == 0:
|
|
|
+ # handle the case of spaces between ! and subcommand
|
|
|
+ subc, args = pop_arg(args)
|
|
|
+ subc = subc.lower()
|
|
|
+ name, _ = pop_arg(args)
|
|
|
+ person_id = name.strip().lower()
|
|
|
+
|
|
|
+ if subc == "aggregate":
|
|
|
+ curses = 0
|
|
|
+ blessings = 0
|
|
|
+ for cbs in db.query(CurseBlessScore).filter(CurseBlessScore.person_id == person_id):
|
|
|
+ curses += cbs.curses
|
|
|
+ blessings += cbs.blessings
|
|
|
+ return RollbotResponse(msg, txt=f"From my records, {name} has been cursed {fmt_times(curses)} and blessed {fmt_times(blessings)} across all chats.")
|
|
|
+ else:
|
|
|
+ return RollbotResponse(msg, failure=RollbotFailure.INVALID_SUBCOMMAND)
|
|
|
+
|
|
|
|
|
|
|
|
|
@as_plugin
|