From 54d1a38a8086397d631c869646121c981f55a9f7 Mon Sep 17 00:00:00 2001 From: agatha Date: Wed, 18 Sep 2024 17:35:40 -0400 Subject: [PATCH] feat: catbot has dogs now --- catbot/catbot/__init__.py | 23 +++++++++++++++++++++++ catbot/maubot.yaml | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/catbot/catbot/__init__.py b/catbot/catbot/__init__.py index f24eb02..897a8d2 100644 --- a/catbot/catbot/__init__.py +++ b/catbot/catbot/__init__.py @@ -26,3 +26,26 @@ class CatBot(Plugin): ) else: await evt.reply("couldn't fetch a cat image :(") + + @command.new("dog") + async def dog_command(self, evt: MessageEvent) -> None: + async with self.http.get("https://random.dog/woof.json") as response: + if response.status == 200: + image_link = await response.json() + else: + await evt.reply("couldn't fetch a dog image :(") + return + + async with self.http.get(image_link['url']) as response: + if response.status == 200: + image_data = await response.read() + mxc_uri = await self.client.upload_media(image_data, mime_type="image/jpeg") + await evt.respond( + content=MediaMessageEventContent( + url=mxc_uri, + body="dog", + msgtype=MessageType.IMAGE, + ) + ) + else: + await evt.reply("couldn't fetch a dog image :(") diff --git a/catbot/maubot.yaml b/catbot/maubot.yaml index f84c73b..eb3555c 100644 --- a/catbot/maubot.yaml +++ b/catbot/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.5.0 id: com.juggalol.catbot -version: 0.1.12 +version: 0.2.1 license: MIT modules: - catbot