From a072ea3dd0830660bf54a20833254e174360c066 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 8 Nov 2021 14:01:43 +0100 Subject: [PATCH] Improve Brother messages --- config.yml.example | 1 + orochi/bot.py | 41 ++++++++++++++++++++++++++++++----------- orochi/config.py | 3 ++- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/config.yml.example b/config.yml.example index 5f15fed..3f1ebc2 100644 --- a/config.yml.example +++ b/config.yml.example @@ -1 +1,2 @@ discord_token: insert_token_here +guild: insert_guild_id_here diff --git a/orochi/bot.py b/orochi/bot.py index 61dfa2d..01b70d3 100644 --- a/orochi/bot.py +++ b/orochi/bot.py @@ -251,25 +251,36 @@ async def on_ready(): philia, overwrite=PermissionOverwrite(read_message_history=True, read_messages=True) ) - if not config.left_channel: - channel: TextChannel = await secret_category.create_text_channel("left") - config.left_channel = channel.id + if not config.brother_channel: + channel: TextChannel = await secret_category.create_text_channel("doliprane") + config.brother_channel = channel.id config.save() - left_channel: TextChannel = await guild.fetch_channel(config.left_channel) - if not left_channel: - config.left_channel = None + brother_channel: TextChannel = await guild.fetch_channel(config.brother_channel) + if not brother_channel: + config.brother_channel = None return await on_ready() - await left_channel.edit(name="left", category=secret_category, position=1, - topic="Des voix dans la tête ...") - await left_channel.set_permissions( + await brother_channel.edit(name="doliprane", category=secret_category, position=1, + topic="Des voix dans la tête ...") + await brother_channel.set_permissions( guild.default_role, overwrite=PermissionOverwrite(read_message_history=False, read_messages=False) ) - await left_channel.set_permissions( + await brother_channel.set_permissions( philia, overwrite=PermissionOverwrite(read_message_history=True, read_messages=True) ) + brother_channel_webhook = None + if config.brother_channel_webhook is not None: + try: + brother_channel_webhook = await bot.fetch_webhook(config.brother_channel_webhook) + except disnake.HTTPException | disnake.NotFound | disnake.Forbidden: + pass + if brother_channel_webhook is None: + brother_channel_webhook = await brother_channel.create_webhook(name="???") + config.brother_channel_webhook = brother_channel_webhook.id + config.save() + if not config.backdoor_channel: channel: TextChannel = await secret_category.create_text_channel("backdoor") config.backdoor_channel = channel.id @@ -293,13 +304,21 @@ async def on_ready(): config.save() -@bot.command() +@bot.command(help="Envoyer un message en tant qu'Orochi.") @commands.has_permissions(administrator=True) async def send(ctx: commands.Context, *, message: str): await ctx.message.delete() await ctx.send(message) +@bot.command(help="Envoyer un message à Philia par la pensée en tant que Brother.") +@commands.has_permissions(administrator=True) +async def brother(ctx: commands.Context, *, message: str): + webhook = await bot.fetch_webhook(bot.config.brother_channel_webhook) + await webhook.send(message) + await ctx.message.reply("Message envoyé.") + + @bot.command() async def vote(ctx: commands.Context): view = Confirm() diff --git a/orochi/config.py b/orochi/config.py index a78f8d3..19b93a6 100644 --- a/orochi/config.py +++ b/orochi/config.py @@ -25,7 +25,8 @@ class Config: vote_channels: dict[str, int] = field(default_factory=dict) backdoor_channel: int = None telepathy_channel: int = None - left_channel: int = None + brother_channel: int = None + brother_channel_webhook: int = None player_roles: dict[str, int] = field(default_factory=dict) @classmethod