about summary refs log tree commit diff
path: root/src/petthecord/bot.py
blob: 0725943fbd34a9858f9a1129aac87202697b5c70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from aiohttp.web import AppRunner, TCPSite
from discord import app_commands, Interaction, Intents, User
from discord.ext import commands

from .server import Server


class PatTheCordCog(commands.Cog):
    def __init__(self, client: commands.Bot) -> None:
        self.client = client

    @app_commands.allowed_installs(users=True)
    @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
    @app_commands.command(
        name="petpet",
        description="Pat some user"
    )
    @app_commands.describe(
        user="User to pet",
        r="Some random stuff, set it if avatar is not up to date"
    )
    async def petthecord(
        self,
        interaction: Interaction,

        user: User,
        r: str = ""
    ) -> None:
        await interaction.response.send_message(f"https://ptc.nakidai.ru/{user.id}.{r}.gif")


class Bot(commands.Bot):
    def __init__(self, host: str = "127.0.0.1", port: int = 8080) -> None:
        super().__init__(
            command_prefix="!",
            intents=Intents.default()
        )
        self._host = host
        self._port = port

    async def on_ready(self) -> None:
        await self.add_cog(PatTheCordCog(self))
        await self.tree.sync()

        runner = AppRunner(Server(self))
        await runner.setup()
        site = TCPSite(runner, self._host, self._port)
        await site.start()