|
@@ -4,6 +4,7 @@ import random
|
|
|
from sqlalchemy import Column, Integer, String
|
|
|
|
|
|
from rollbot import RollbotFailure, as_plugin, ModelBase, pop_arg
|
|
|
+from rollbot.plugins.injection import Database, Message, Subcommand, Bot, Config, Injector
|
|
|
|
|
|
|
|
|
class CurseBlessScore(ModelBase):
|
|
@@ -34,7 +35,7 @@ def fmt_times(n):
|
|
|
return str(n) + (" time" if n == 1 else " times")
|
|
|
|
|
|
|
|
|
-def curse_agg(db, msg, args):
|
|
|
+def curse_agg(db: Database, msg: Message, args: Subcommand.ArgString):
|
|
|
if args is None:
|
|
|
return f"Sorry! I need to know who's records you're trying to aggregate!"
|
|
|
person_id = get_person_id(args)
|
|
@@ -46,7 +47,7 @@ def curse_agg(db, msg, args):
|
|
|
return f"From my records, {args} has been cursed {fmt_times(curses)} and blessed {fmt_times(blessings)} across all chats."
|
|
|
|
|
|
|
|
|
-def curse_clear(db, msg, args):
|
|
|
+def curse_clear(db: Database, msg: Message, args: Subcommand.ArgString):
|
|
|
if args is None:
|
|
|
return f"Sorry! I need to know who's records you're trying to clear!"
|
|
|
person_id = get_person_id(args)
|
|
@@ -62,7 +63,7 @@ def curse_clear(db, msg, args):
|
|
|
return f"Done! I have cleared all records of {args} in this chat, who was previously cursed {fmt_times(oc)} and blessed {fmt_times(ob)}!"
|
|
|
|
|
|
|
|
|
-def curse_clearall(db, msg, args):
|
|
|
+def curse_clearall(db: Database, msg: Message, args: Subcommand.ArgString):
|
|
|
if args is None:
|
|
|
return f"Sorry! I need to know who's records you're trying to clear!"
|
|
|
person_id = get_person_id(args)
|
|
@@ -88,7 +89,7 @@ TOP_MAP = {
|
|
|
}
|
|
|
|
|
|
|
|
|
-def curse_top(db, msg, args):
|
|
|
+def curse_top(db: Database, msg: Message, args: Subcommand.ArgString):
|
|
|
if msg.command == "curse":
|
|
|
target = CurseBlessScore.curses
|
|
|
text = "cursed"
|
|
@@ -150,21 +151,30 @@ CMD_MAP = {
|
|
|
|
|
|
|
|
|
@as_plugin
|
|
|
-def curse(db, msg, subc, bot, ban_list_cfg: "curse.banlist", no_list_cfg: "curse.nolist"):
|
|
|
+def curse(db: Database,
|
|
|
+ msg: Message,
|
|
|
+ subc: Subcommand,
|
|
|
+ bot: Bot,
|
|
|
+ ban_list: Config("curse.banlist"),
|
|
|
+ no_list: Config("curse.nolist"),
|
|
|
+ inject: 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_cfg):
|
|
|
- if msg.sender_id in no_list_cfg:
|
|
|
+ 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_cfg[msg.sender_id][0]}"
|
|
|
+ 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 SUBC_MAP.get(subc.command, lambda *_: RollbotFailure.INVALID_SUBCOMMAND)(db, msg, subc.raw_args)
|
|
|
+ try:
|
|
|
+ return inject.run_with_deps(SUBC_MAP[subc.command])
|
|
|
+ except KeyError:
|
|
|
+ RollbotFailure.INVALID_SUBCOMMAND.raise_exc()
|