Ejemplo n.º 1
0
 def is_muted_text_channel(self, channel: discord.TextChannel) -> bool:
     """
     指定したチャンネルが聞き専チャンネルかどうか確認します。
     """
     topic_split: list = my_channel.get_topic(channel, split=True)
     if topic_split[0] == "これは自動生成されたテキストチャンネルです。":
         return True
     else:
         return False
Ejemplo n.º 2
0
 async def clean_null_auto_text_channels(
         self, category: discord.CategoryChannel,
         channels: Callable[[discord.CategoryChannel], list]):
     """
     使われていない自動生成されたテキストチャンネルを検知し、削除します。
     ※第二引数でclean_null_auto_voice_channelsを呼び出す想定で実装しています。
     """
     for channel in category.channels:
         if type(channel) == discord.TextChannel:
             topic = my_channel.get_topic(channel, split=True)
             if topic is None:
                 continue
             elif topic[1] in channels:
                 await channel.delete(reason="誰もいないため")
    async def on_raw_reaction_add(self,
                                  payload: discord.RawReactionActionEvent):

        if payload.member.bot:
            return

        channel: discord.TextChannel = self.bot.get_channel(payload.channel_id)
        guild: discord.Guild = self.bot.get_guild(payload.guild_id)
        voice_category_id = 770140316078309416

        if not self.voice.is_muted_text_channel(
                channel
        ) or payload.member != await self.voice.get_auto_voice_owner(channel):
            return

        message: discord.Message = await channel.fetch_message(
            payload.message_id)

        if not self.voice.is_voice_control_panel(message, self.bot):
            return

        global reaction_list

        if not str(payload.emoji) in reaction_list:
            return

        await message.remove_reaction(payload.emoji, payload.member)

        if str(payload.emoji) == "✏":

            msg = await self.msg.question(
                bot=self.bot,
                main_object=message,
                member=payload.member,
                title=f"{payload.member.mention}->変更したい名前を入力してください。")

            before_name = channel.name

            if msg == False:
                return

            result = msg['result']
            question = msg['question']

            if len(result.content) > 0:
                vc_id = int(yonosumi_utils.get_topic(channel, split=True)[1])
                if vc_id is None:
                    return await question.edit(
                        content=f"{payload.member.mention}->不明なエラーが発生しました!")

                vc = self.bot.get_channel(vc_id)

                await channel.edit(name=result.content)
                await vc.edit(name=result.content)
                await channel.send(
                    f"{payload.member.mention}->チャンネル名を`{result.content}`に変更しました!"
                )
                self.bot.logger.info(
                    f"{payload.member}がチャンネル名を{before_name}から{result.content}に変更しました"
                )

        elif str(payload.emoji) == "🔒":

            msg = await self.msg.question(
                bot=self.bot,
                main_object=message,
                member=payload.member,
                title=f"{payload.member.mention}->VCに入れる最大人数を指定してください。")

            if msg == False:
                return

            result = msg['result']
            question = msg['question']

            try:
                num = int(result.content)
            except:
                return await question.edit(
                    content=f"{payload.member.mention}->不正な値が渡されました!")

            if not num > 100:
                vc_id = int(yonosumi_utils.get_topic(channel, split=True)[1])
                if vc_id is None:
                    return await question.edit(
                        content=f"{payload.member.mention}->不明なエラーが発生しました!")
                vc = self.bot.get_channel(vc_id)
                await vc.edit(user_limit=num)
                await channel.send(
                    f"{payload.member.mention}->VCの参加可能人数を`{num}人`に変更しました!")
                self.bot.logger.info(f"{payload.member}が参加可能人数を{num}に制限しました。")
            else:
                return await question.edit(
                    content=f"{payload.member.mention}->100人以上は指定できません!")

        elif str(payload.emoji) == "👀":

            if not self.voice.is_hide(payload.member.voice.channel):

                result = "非公開"

                vc: discord.VoiceChannel = self.bot.get_channel(
                    my_channel.get_topic(channel, split=True)[1])

                for member in payload.member.voice.members:
                    await channel.set_permissions(
                        target=member,
                        view_channel=True,
                    )

                    await vc.set_permissions(target=member,
                                             view_channel=True,
                                             connect=True)

                await vc.set_permissions(guild.default_role,
                                         view_channel=False,
                                         connect=False)

                await channel.set_permissions(guild.default_role,
                                              view_channel=False)

            else:

                result = "公開"

                vc: discord.VoiceChannel = self.bot.get_channel(
                    my_channel.get_topic(channel, split=True)[1])

                await vc.set_permissions(guild.default_role,
                                         read_messages=True,
                                         connect=True)

                await channel.set_permissions(guild.default_role,
                                              read_messages=True)

            await channel.send(
                content=f"{payload.member.mention}->このVCを``{result}``にしました!")