def is_muted_text_channel(channel: discord.TextChannel) -> bool: """ 指定したチャンネルが聞き専チャンネルかどうか確認します。 """ topic_split: list = my_channel.get_topic(channel, split=True) if topic_split[0] == "これは自動生成されたテキストチャンネルです。": return True else: return False
async def get_auto_voice_owner( channel: discord.TextChannel) -> Union[discord.Member, None]: """ 自動生成されたチャンネルのオーナーのメンバーオブジェクトを返します。 取得できなかった場合はNoneが返ります。 """ owner_id = my_channel.get_topic(channel, split=True)[2] try: return await channel.guild.fetch_member(int(owner_id)) except: return None
async def clean_null_auto_text_channels( 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) rank_vc_id = 807784369166352384 match_vc_id = 807784449067843584 talk_vc_id = 808647004410478592 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 Message.question( bot=self.bot, main_object=message, member=payload.member, title=f"{payload.member.mention}->変更したい名前を入力してください。") if msg is False: return result = msg['result'] question = msg['question'] if len(result.content) > 0: vc_id = int(my_channel.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}`に変更しました!" ) elif str(payload.emoji) == "🔒": msg = await Message.question( bot=self.bot, main_object=message, member=payload.member, title=f"{payload.member.mention}->VCに入れる最大人数を指定してください。") if msg is 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(my_channel.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}人`に変更しました!") 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}`にしました!")
def get_linked_mute_channel(category: discord.CategoryChannel, vc: discord.VoiceChannel): for i in category.channels: topic = my_channel.get_topic(i, split=True) if topic[1] == vc.id: return i