Browse Source

Implementing reply to test functionality, and increasing sleep timer slightly for groupme driver

Kirk Trombley 3 years ago
parent
commit
1fb58f7c50
2 changed files with 20 additions and 3 deletions
  1. 7 1
      commands/commands/simple.py
  2. 13 2
      drivers/groupme_driver.py

+ 7 - 1
commands/commands/simple.py

@@ -1,6 +1,7 @@
 import random
+import json
 
-from rollbot import as_command, Message, RollbotFailure, Command
+from rollbot import as_command, Message, RollbotFailure, Command, Attachment
 from rollbot.injection import (
     ChannelAdmin,
     OriginAdmin,
@@ -153,3 +154,8 @@ FFFFFFF
 @as_command("f")
 def finchat(cmd: Command):
     return "frick!" if cmd.raw_name == "f" else Fs
+
+
+@as_command
+def reply():
+    return Attachment(name="reply", body="Replying!")

+ 13 - 2
drivers/groupme_driver.py

@@ -76,7 +76,7 @@ class GroupMeBot(rollbot.Rollbot[GroupMeMessage]):
             return (await upload.json())["payload"]["url"]
 
     async def post_message(self, bot_id: str, text: str, attachments: list[dict[str, str]]):
-        await self.context.request.post(
+        result = await self.context.request.post(
             "https://api.groupme.com/v3/bots/post",
             json={
                 "bot_id": bot_id,
@@ -85,10 +85,11 @@ class GroupMeBot(rollbot.Rollbot[GroupMeMessage]):
             },
             timeout=10,
         )
+        self.context.logger.info(f"{result.status} - {await result.json()}")
 
     async def respond(self, res: rollbot.Response):
         # sleep for a moment to make groupme not misorder messages
-        await asyncio.sleep(0.2)
+        await asyncio.sleep(0.5)
 
         if res.origin_id != "GROUPME":
             self.context.logger.error(f"Unable to respond to {res.origin_id}")
@@ -114,6 +115,16 @@ class GroupMeBot(rollbot.Rollbot[GroupMeMessage]):
                             )
                         else:
                             attachments.append({"type": "image", "url": att.body})
+                    if att.name == "reply":
+                        if not isinstance(att.body, str):
+                            raise ValueError("Invalid reply body type")
+                        message += att.body # append reply text to response
+                        attachments.append({
+                            "type": "reply",
+                            "base_reply_id": res.channel_id,
+                            "reply_id": res.channel_id,
+                        })
+                         
         except:
             self.context.debugging = "".join(traceback.format_exc())
             message += "Failed to upload one or more attachments!\n"