Преглед изворни кода

Adding replies in market responses, but disabling it in driver temporarily

Kirk Trombley пре 3 година
родитељ
комит
8a5c3ec1ee
3 измењених фајлова са 18 додато и 13 уклоњено
  1. 7 5
      commands/commands/rollcoin.py
  2. 9 8
      drivers/groupme_driver.py
  3. 2 0
      rollbot/rollbot/injection/util.py

+ 7 - 5
commands/commands/rollcoin.py

@@ -3,7 +3,7 @@ from typing import Optional
 import random
 
 from rollbot import as_command, initialize_data, RollbotFailure
-from rollbot.injection import Data, Sender, Config, Const, Arg
+from rollbot.injection import Data, Sender, Config, Const, Arg, Reply
 
 # View
 #   !wallet - shows your number of rollcoins, NFTs (Non-Functional Tamagotchis), and market balance
@@ -77,8 +77,8 @@ MarketMessages = Config("rollcoin.market.messages")
 
 
 @as_command
-def wallet(sender_wallet: SenderWallet):
-    return f"You currently own...\n{sender_wallet}"
+def wallet(sender_wallet: SenderWallet, reply: Reply):
+    return f"You currently own...\n{sender_wallet}", reply
 
 
 @as_command
@@ -148,6 +148,7 @@ async def bet(
     multipliers: MarketMultipliers,
     messages: MarketMessages,
     amount: Arg(0, convert=convert_amount, missing_msg="You must provide an amount to bet!", fail_msg="Could not parse {} as value"),
+    reply: Reply,
 ):
     if not isinstance(amount, float):
         # handle special converters
@@ -169,7 +170,7 @@ async def bet(
 
     await evolve_market(state, transitions, multipliers, wallet_store, state_store)
     
-    return f"{messages[state.market_state]}\n{await wallet_store.load(sender_id)}"
+    return f"{messages[state.market_state]}\n{await wallet_store.load(sender_id)}", reply
 
 
 @as_command
@@ -183,6 +184,7 @@ async def cash(
     multipliers: MarketMultipliers,
     messages: MarketMessages,
     amount: Arg(0, convert=convert_amount, missing_msg="You must provide an amount to bet!", fail_msg="Could not parse {} as value"),
+    reply: Reply,
 ):
     if not isinstance(amount, float):
         # handle special converters
@@ -224,4 +226,4 @@ async def cash(
 
     await evolve_market(state, transitions, multipliers, wallet_store, state_store)
     
-    return f"{response}\n{messages[state.market_state]}\n{await wallet_store.load(sender_id)}"
+    return f"{response}\n{messages[state.market_state]}\n{await wallet_store.load(sender_id)}", reply

+ 9 - 8
drivers/groupme_driver.py

@@ -121,14 +121,15 @@ class GroupMeBot(rollbot.Rollbot[GroupMeMessage]):
                             )
                         else:
                             attachments.append({"type": "image", "url": att.body})
-                    if att.name == "reply":
-                        if att.body is None or not isinstance(att.body, str):
-                            raise ValueError("Invalid reply body type, must be message ID")
-                        attachments.append({
-                            "type": "reply",
-                            "base_reply_id": att.body,
-                            "reply_id": att.body,
-                        })
+                    # TODO re-enable replies
+                    # if att.name == "reply":
+                    #     if att.body is None or not isinstance(att.body, str):
+                    #         raise ValueError("Invalid reply body type, must be message ID")
+                    #     attachments.append({
+                    #         "type": "reply",
+                    #         "base_reply_id": att.body,
+                    #         "reply_id": att.body,
+                    #     })
                          
         except:
             self.context.debugging = "".join(traceback.format_exc())

+ 2 - 0
rollbot/rollbot/injection/util.py

@@ -20,6 +20,7 @@ __all__ = [
     "SenderName",
     "Text",
     "Attachments",
+    "Reply",
     "CommandInjector",
     "Request",
     "Respond",
@@ -41,6 +42,7 @@ ChannelAdmin = Simple[bool](lambda m, c: m.channel_admin)
 SenderName = Simple[Optional[str]](lambda m, c: m.sender_name)
 Text = Simple[str](lambda m, c: m.text)
 Attachments = Simple[list[Attachment]](lambda m, c: m.attachments)
+Reply = Simple[Attachment](lambda m, c: Attachment(name="reply", body=m.message_id))
 CommandInjector = Simple[Command](lambda m, c: m.command)
 Request = Simple[ClientSession](lambda m, c: c.request)
 Respond = Simple[Callable[[], Coroutine[None, None, None]]](lambda m, c: c.respond)