|
@@ -19,18 +19,6 @@ def get_person_id(args):
|
|
|
return args.strip().lower().replace(" ", "_")
|
|
|
|
|
|
|
|
|
-def get_score(db, group_id, person_id):
|
|
|
- score = db.query(CurseBlessScore).get((group_id, person_id))
|
|
|
- if not score:
|
|
|
- score = CurseBlessScore(group_id=group_id, person_id=person_id, curses=0, blessings=0)
|
|
|
- db.add(score)
|
|
|
- return score
|
|
|
-
|
|
|
-
|
|
|
-def is_banned(msg, person_id, ban_list):
|
|
|
- return msg.sender_id in ban_list and person_id in ban_list[msg.sender_id]
|
|
|
-
|
|
|
-
|
|
|
def fmt_times(n):
|
|
|
return str(n) + (" time" if n == 1 else " times")
|
|
|
|
|
@@ -83,12 +71,6 @@ def curse_clearall(db: Database, msg: Message, args: Subcommand.ArgString):
|
|
|
return f"Done! I have cleared all records of {args} in all chats, who was previously cursed {fmt_times(oc)} and blessed {fmt_times(ob)} in total!"
|
|
|
|
|
|
|
|
|
-TOP_MAP = {
|
|
|
- "curse": CurseBlessScore.curses,
|
|
|
- "bless": CurseBlessScore.blessings,
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
def curse_top(db: Database, msg: Message, args: Subcommand.ArgString):
|
|
|
if msg.command == "curse":
|
|
|
target = CurseBlessScore.curses
|
|
@@ -150,31 +132,41 @@ CMD_MAP = {
|
|
|
}
|
|
|
|
|
|
|
|
|
+def curse_command(db: Database,
|
|
|
+ msg: Message,
|
|
|
+ bot: Bot,
|
|
|
+ ban_list: Config("curse.banlist"),
|
|
|
+ no_list: Config("curse.nolist"),
|
|
|
+ inject: Injector):
|
|
|
+ if not msg.from_admin and msg.command.startswith("un"):
|
|
|
+ return RollbotFailure.PERMISSIONS.with_reason("For now, only admins can unbless or uncurse people!")
|
|
|
+
|
|
|
+ if msg.raw_args is None:
|
|
|
+ return f"Sorry - you need to provide the name of someone to {msg.command}!"
|
|
|
+
|
|
|
+ person_id = get_person_id(msg.raw_args)
|
|
|
+ if msg.sender_id in ban_list and person_id in ban_list[msg.sender_id]:
|
|
|
+ if msg.sender_id in no_list:
|
|
|
+ return "No!!!!!!!!!!"
|
|
|
+ if random.randint(0, 1) == 0:
|
|
|
+ bot.manually_post_message("Hey! You aren't allowed to affect that person's score! And cheaters never propser!", msg.group_id)
|
|
|
+ return f"!curse {ban_list[msg.sender_id][0]}"
|
|
|
+ return "Hey! You aren't allowed to affect that person's score!"
|
|
|
+
|
|
|
+ score = db.query(CurseBlessScore).get((msg.group_id, person_id))
|
|
|
+ if score is None:
|
|
|
+ score = CurseBlessScore(group_id=msg.group_id, person_id=person_id, curses=0, blessings=0)
|
|
|
+ db.add(score)
|
|
|
+ CMD_MAP[msg.command](score)
|
|
|
+
|
|
|
+ return f"It is done! {msg.raw_args} has been cursed {fmt_times(score.curses)} and blessed {fmt_times(score.blessings)} in this chat."
|
|
|
+
|
|
|
+
|
|
|
@as_plugin
|
|
|
-def curse(db: Database,
|
|
|
- msg: Message,
|
|
|
- subc: Subcommand,
|
|
|
- bot: Bot,
|
|
|
- ban_list: Config("curse.banlist"),
|
|
|
- no_list: Config("curse.nolist"),
|
|
|
- inject: Injector):
|
|
|
+def curse(subc: Subcommand, injector: Injector):
|
|
|
if subc is None:
|
|
|
- if not msg.from_admin and msg.command.startswith("un"):
|
|
|
- return RollbotFailure.PERMISSIONS.with_reason("For now, only admins can unbless or uncurse people!")
|
|
|
- if msg.raw_args is None:
|
|
|
- return f"Sorry - you need to provide the name of someone to {msg.command}!"
|
|
|
- person_id = get_person_id(msg.raw_args)
|
|
|
- if is_banned(msg, person_id, ban_list):
|
|
|
- if msg.sender_id in no_list:
|
|
|
- return "No!!!!!!!!!!"
|
|
|
- if random.randint(0, 1) == 0:
|
|
|
- bot.manually_post_message("Hey! You aren't allowed to affect that person's score! And cheaters never propser!", msg.group_id)
|
|
|
- return f"!curse {ban_list[msg.sender_id][0]}"
|
|
|
- return "Hey! You aren't allowed to affect that person's score!"
|
|
|
- score = get_score(db, msg.group_id, person_id)
|
|
|
- CMD_MAP[msg.command](score)
|
|
|
- return f"It is done! {msg.raw_args} has been cursed {fmt_times(score.curses)} and blessed {fmt_times(score.blessings)} in this chat."
|
|
|
+ return injector.run_with_deps(curse_command)
|
|
|
try:
|
|
|
- return inject.run_with_deps(SUBC_MAP[subc.command])
|
|
|
+ return injector.run_with_deps(SUBC_MAP[subc.command])
|
|
|
except KeyError:
|
|
|
- RollbotFailure.INVALID_SUBCOMMAND.raise_exc()
|
|
|
+ return RollbotFailure.INVALID_SUBCOMMAND
|