diff options
| author | Nakidai <nakidai@disroot.org> | 2024-11-21 01:05:16 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-11-21 01:05:16 +0300 |
| commit | 56ca509f11c836328f524f03810b9be9cfbd9eec (patch) | |
| tree | dc175d453009167ddf145304ba2683ae34fce645 | |
| parent | aaf8fed701a705d69f7c0136c32ed1e6e74c66cb (diff) | |
| download | petthecord-56ca509f11c836328f524f03810b9be9cfbd9eec.tar.gz petthecord-56ca509f11c836328f524f03810b9be9cfbd9eec.zip | |
Do some things with commands
Now previously known /petpet is moved to /petpetlink, and /petpet is a new command that returns with gif rather than link.
| -rw-r--r-- | src/petthecord/bot.py | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/src/petthecord/bot.py b/src/petthecord/bot.py index e1aa8a6..780263f 100644 --- a/src/petthecord/bot.py +++ b/src/petthecord/bot.py @@ -1,14 +1,22 @@ +from io import BytesIO from logging import getLogger -from discord import app_commands, Interaction, User +from discord import app_commands, File, Interaction, User from discord.ext import commands from .defaults import Defaults +from .petter import Petter, HTTPException, NotFound class PetTheCordCog(commands.Cog): - def __init__(self, origin: str = Defaults.Network.ORIGIN) -> None: + def __init__( + self, + + origin: str = Defaults.Network.ORIGIN, + petter: Petter | None = None, + ) -> None: self._origin = origin + self._petter = petter or Petter() super().__init__() self._logger = getLogger(__name__) @@ -16,19 +24,54 @@ class PetTheCordCog(commands.Cog): @app_commands.allowed_installs(users=True) @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True) @app_commands.command( - name="petpet", - description="Pet some user" + name="petpetlink", + description="Pet some user and take a link", ) @app_commands.describe( user="User to pet", - r="Some random stuff, set it if avatar is not up to date" + r="Some random stuff, set it if avatar is not up to date", ) - async def petthecord( + async def petwithlink( self, interaction: Interaction, user: User, - r: str = "" + r: str = "", ) -> None: - self._logger.info(f"Petting {user.id} for {interaction.user.id}") + self._logger.info(f"Petting {user.id} with link for {interaction.user.id}") await interaction.response.send_message(f"{self._origin}/{user.id}.{r}.gif") + + @app_commands.allowed_installs(users=True) + @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True) + @app_commands.command( + name="petpet", + description="Pet some user and take a link" + ) + @app_commands.describe( + user="User to pet", + ) + async def petwithgif( + self, + interaction: Interaction, + + user: User, + ) -> None: + self._logger.info(f"Petting {user.id} with gif for {interaction.user.id}") + try: + await interaction.response.send_message( + file=File( + BytesIO(await self._petter.petpet(user)), + filename=f"{user.id}.gif" + ) + ) + except HTTPException: + self._logger.error(f"Couldn't pet {user.id}") + await interaction.response.send_message( + "Couldn't pet your user :<", + ephemeral=True, + ) + except NotFound: + await interaction.response.send_message( + "Avatar or user was not found :<", + ephemeral=True, + ) |