Browse Source

Fixing up a bug in the command parsing, adding a raw_command attribute, and doing some cleanup to curse and f

Kirk Trombley 5 years ago
parent
commit
45df8e7a6b
3 changed files with 10 additions and 15 deletions
  1. 2 1
      lib/rollbot/messaging.py
  2. 7 13
      src/plugins/curse.py
  3. 1 1
      src/plugins/finchat.py

+ 2 - 1
lib/rollbot/messaging.py

@@ -26,10 +26,11 @@ class RollbotMessage:
 
     def __post_init__(self):
         self.is_command = False
-        if len(self.message_txt) > 0 and self.message_txt[0] in BANGS:
+        if self.message_txt is not None and len(self.message_txt) > 0 and self.message_txt[0] in BANGS:
             cmd, raw = pop_arg(self.message_txt[1:].strip())
             if cmd is not None:
                 self.is_command = True
+                self.raw_command = cmd
                 self.command = cmd.lower()
                 self.raw_args = raw
 

+ 7 - 13
src/plugins/curse.py

@@ -106,10 +106,11 @@ BAN_LIST = get_secret("curse.banlist")
 
 
 @as_plugin
-def curse(db, msg):
-    # TODO might be nice to add subcommands to this later
-    name, args = pop_arg(msg.raw_args)
-    if not name.startswith("!"):
+def curse(db, msg, subc):
+    if subc is None:
+        name, _ = pop_arg(msg.raw_args)
+        if name is None:
+            return "Sorry - you need to provide the name of someone to curse!"
         person_id = name.strip().lower()
         if is_banned(msg, person_id):
             if msg.sender_id in get_secret("curse.nolist"):
@@ -120,14 +121,7 @@ def curse(db, msg):
         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()
-
-    return SUBC_MAP.get(subc, lambda *a: RollbotResponse(msg, failure=RollbotFailure.INVALID_SUBCOMMAND))(db, msg, args)
+    return SUBC_MAP.get(subc.command, lambda *_: RollbotResponse(msg, failure=RollbotFailure.INVALID_SUBCOMMAND))(db, msg, subc.raw_args)
 
 
 class Bless(RollbotPlugin):
@@ -140,7 +134,7 @@ class Bless(RollbotPlugin):
     def on_command(self, db, msg):
         name, _ = pop_arg(msg.raw_args)
         if name.startswith("!"):
-            return "Sorry! Subcommands have to go on !curse for now - this will be fixed in the future!"
+            return RollbotResponse(msg, txt="Sorry! Subcommands have to go on !curse for now - this will be fixed in the future!")
         person_id = name.strip().lower()
         if is_banned(msg, person_id):
             self.bot.manually_post_message("Hey! You aren't allowed to affect that person's score! And cheaters never propser!", msg.group_id)

+ 1 - 1
src/plugins/finchat.py

@@ -21,4 +21,4 @@ FFFFFFF
 
 @as_plugin("f")
 def finchat(msg):
-    return "frick!" if msg.message_txt[1:].strip().startswith("f") else Fs
+    return "frick!" if msg.raw_command == "f" else Fs