feat: catbot has dogs now

This commit is contained in:
agatha 2024-09-18 17:35:40 -04:00
parent 92520761d8
commit 54d1a38a80
2 changed files with 24 additions and 1 deletions

View File

@ -26,3 +26,26 @@ class CatBot(Plugin):
) )
else: else:
await evt.reply("couldn't fetch a cat image :(") 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 :(")

View File

@ -1,6 +1,6 @@
maubot: 0.5.0 maubot: 0.5.0
id: com.juggalol.catbot id: com.juggalol.catbot
version: 0.1.12 version: 0.2.1
license: MIT license: MIT
modules: modules:
- catbot - catbot