Пример #1
0
    def _init_components(self, guild_data: GuildData, content: dict):
        options_translation = content["PLUGINS"]
        options = [
            SelectOption(
                label=options_translation["MAIN_PAGE"],
                value="main_page",
                emoji="🏠",
                default=True,
            )
        ]

        for cog_name, cog in self.bot.cogs.items():
            if self._cog_check(guild_data, cog):
                continue

            emoji = cog.emoji
            if isinstance(emoji, int):
                emoji = self.bot.get_emoji(emoji)
            options.append(
                SelectOption(
                    label=options_translation[cog_name.upper()],
                    value=cog_name,
                    emoji=emoji,
                )
            )

        return [Select(placeholder=content["SELECT_MODULE_TEXT"], options=options)]
Пример #2
0
 def _get_bot_menu_components(self):
     return [
         Select(
             placeholder="Reload extensions",
             custom_id="select_reload_extensions",
             options=[
                 SelectOption(label=extension[5:], value=extension)
                 for extension in self.bot.extensions
             ],
             max_values=len(self.bot.extensions),
         ),
         [
             Button(
                 style=ButtonStyle.blue,
                 label="Reload bot",
                 custom_id="button_reload_bot",
             ),
             Button(
                 style=ButtonStyle.blue,
                 label="Sync commands",
                 custom_id="button_sync_commands",
             ),
             Button(style=ButtonStyle.red, label="Exit", custom_id="button_exit"),
         ],
     ]
Пример #3
0
    async def autorole_create_dropdown(
        self,
        ctx: SlashContext,
        name: str,
        message_content: str,
        placeholder: str = None,
    ):
        guild_data = await self.bot.mongo.get_guild_data(ctx.guild_id)

        content: dict = get_content("AUTOROLE_DROPDOWN",
                                    guild_data.configuration.language)
        components = [
            Select(
                placeholder=placeholder
                if placeholder is not None else content["NO_OPTIONS_TEXT"],
                options=[SelectOption(label="None", value="None")],
                disabled=True,
                custom_id="autorole_select",
            )
        ]

        message = await ctx.channel.send(content=message_content,
                                         components=components)
        await ctx.send(content["CREATED_DROPDOWN_TEXT"], hidden=True)

        await guild_data.add_autorole(
            name,
            {
                "content": message_content,
                "message_id": message.id,
                "autorole_type": "select_menu",
                "component": components[0].to_dict(),
            },
        )
Пример #4
0
    async def on_button_click(self, ctx: ComponentContext):
        if not ctx.custom_id.startswith("voice"):
            return

        guild_data = await self.bot.mongo.get_guild_data(ctx.guild_id)
        if not guild_data.private_voice:
            raise PrivateVoiceNotSetup
        active_channels = guild_data.private_voice.active_channels
        content = get_content("PRIVATE_VOICE", guild_data.configuration.language)
        if str(ctx.author_id) not in active_channels:
            return await ctx.send(content["DONT_HAVE_PRIVATE_ROOM"], hidden=True)

        voice_channel: VoiceChannel = ctx.guild.get_channel(active_channels[str(ctx.author_id)])
        match ctx.custom_id:
            case "voice_close":
                await voice_channel.set_permissions(ctx.guild.default_role, connect=False)
                await ctx.send(content["ROOM_CLOSED"], hidden=True)
            case "voice_open":
                await voice_channel.set_permissions(ctx.guild.default_role, connect=True)
                await ctx.send(content["ROOM_OPENED"], hidden=True)
            case "voice_hide":
                await voice_channel.set_permissions(ctx.guild.default_role, view_channel=False)
                await ctx.send(content["ROOM_HIDED"], hidden=True)
            case "voice_unhide":
                await voice_channel.set_permissions(ctx.guild.default_role, view_channel=True)
                await ctx.send(content["ROOM_UNHIDED"], hidden=True)
            case "voice_change_room_name":
                modal = Modal(
                    custom_id="voice_modal_change_room_name",
                    title=content["PRIVATE_ROOM_CONTROL_MODAL"],
                    components=[
                        TextInput(
                            custom_id="channel_name",
                            label=content["ROOM_NAME"],
                            style=TextInputStyle.SHORT,
                        )
                    ],
                )
                await ctx.popup(modal)
            case "voice_ban" | "voice_unban" | "voice_kick" | "voice_transfer":
                modal = Modal(
                    custom_id=f"voice_modal_{ctx.custom_id.replace('voice', '')}",
                    title=content["PRIVATE_ROOM_CONTROL_MODAL"],
                    components=[
                        TextInput(
                            custom_id="user_id",
                            label=content["MEMBER_ID"],
                            style=TextInputStyle.SHORT,
                        )
                    ],
                )
                await ctx.popup(modal)
            case "voice_set_room_limit":
                select = Select(
                    custom_id="voice_select_set_room_limit",
                    options=[
                        SelectOption(label=content["REMOVE_LIMIT"], value=0),
                        SelectOption(label="2", value=2),
                        SelectOption(label="3", value=3),
                        SelectOption(label="4", value=4),
                        SelectOption(label="5", value=5),
                        SelectOption(label="10", value=10),
                    ],
                )
                await ctx.send(content["SETUP_ROOM_LIMIT"], components=[select], hidden=True)
Пример #5
0
    async def _start_random(self, ctx: SlashContext, _list: list = None):
        lang = await self.bot.get_guild_bot_lang(ctx.guild_id)
        content = get_content("FUNC_RANDOM_ITEMS", lang)
        if _list is None:
            _list = content["ITEMS_LIST"]
        components = [
            Button(
                style=ButtonStyle.blue,
                label=content["SELECT_BUTTON"],
                custom_id="toggle",
            ),
            Select(
                placeholder=content["SELECT_ITEMS_TEXT"],
                options=[
                    SelectOption(label=item, value=item) for item in _list
                ],
                max_values=len(_list),
            ),
            [
                Button(
                    label=content["START_RANDOM_BUTTON"],
                    custom_id="start_random",
                    style=ButtonStyle.green,
                ),
                Button(
                    label=content["EXIT_BUTTON"],
                    custom_id="exit",
                    style=ButtonStyle.red,
                ),
            ],
        ]
        selected = None
        is_exception = False
        is_removed = False
        embed = Embed(
            title=content["EMBED_TITLE"],
            color=await self.bot.get_embed_color(ctx.guild_id),
        )

        message = await ctx.send(embed=embed, components=components)
        message_for_update = await ctx.send(content["SECOND_MESSAGE_CONTENT"])

        while True:
            try:
                button_ctx = await self._get_button_ctx(
                    ctx, message, message_for_update)
            except TimeoutError:
                return

            if isinstance(button_ctx.component, Select):
                selected = button_ctx.values
                if is_exception:
                    _selected = _list.copy()
                    for item in selected:
                        _selected.remove(item)
                    selected = _selected
                embed.description = content["SELECTED_ITEMS_TEXT"] + ", ".join(
                    selected)
                await button_ctx.edit_origin(embed=embed)

            elif button_ctx.custom_id == "toggle":
                is_exception = not is_exception
                button_ctx.component.label = (content["EXCEPTION_BUTTON"]
                                              if is_exception else
                                              content["SELECT_BUTTON"])
                selected = None
                is_removed = False
                embed.description = ""

                await button_ctx.edit_origin(
                    embed=embed,
                    components=button_ctx.origin_message.components)

            elif button_ctx.custom_id == "start_random":
                if not is_exception and selected is not None:
                    item = choice(selected)
                    await message_for_update.edit(content=item)

                elif is_exception and selected is not None:
                    if not is_removed:
                        is_removed = True
                        items = _list.copy()
                        for item in selected:
                            items.remove(item)
                    item = choice(selected)
                    await message_for_update.edit(content=item)
                elif is_exception:
                    selected = _list
                    item = choice(selected)
                    await message_for_update.edit(content=item)

            elif button_ctx.custom_id == "exit":
                await message.delete()
                await message_for_update.delete()
                return
Пример #6
0
    async def open_control_menu(self, ctx: SlashContext):
        components = [
            [
                Button(
                    style=ButtonStyle.green,
                    label="Check Bot updates",
                    custom_id="update_bot",
                    emoji="📥",
                ),
                Button(
                    style=ButtonStyle.gray,
                    label="Check discord.py updates",
                    custom_id="update_discord.py",
                    emoji=self.bot.get_emoji(964091772416454676),
                ),
                Button(
                    style=ButtonStyle.gray,
                    label="Check discord-slash updates",
                    custom_id="update_discord-slash",
                    emoji=self.bot.get_emoji(963104705406439425),
                ),
            ],
            [
                Button(
                    style=ButtonStyle.red,
                    label="Reload Bot",
                    custom_id="reload_bot",
                    emoji=self.bot.get_emoji(963104705888804976),
                ),
                Button(
                    style=ButtonStyle.gray,
                    label="Reload all extensions",
                    custom_id="reload_cogs",
                    emoji="🧱",
                ),
                Button(
                    style=ButtonStyle.gray,
                    label="Reload localization",
                    custom_id="reload_locales",
                    emoji="🇺🇸",
                ),
            ],
            [
                Button(
                    style=ButtonStyle.blue,
                    label="Sync commands",
                    custom_id="sync_commands",
                    emoji=self.bot.get_emoji(963104705406439425),
                ),
            ],
            [
                Select(
                    placeholder="Reload extensions",
                    custom_id="reload_extensions",
                    options=[
                        SelectOption(label=extension[5:], value=extension)
                        for extension in self.bot.extensions
                    ],
                    max_values=len(self.bot.extensions),
                ),
            ],
        ]

        embed = Embed(title="Bot Control Menu", color=DiscordColors.EMBED_COLOR)

        await ctx.send(embed=embed, components=components)
Пример #7
0
    async def autorole_dropdown_add_option(
        self,
        ctx: SlashContext,
        name: str,
        option_name: str,
        role: Role,
        emoji: str = None,
        description: str = None,
    ):
        guild_data = await self.bot.mongo.get_guild_data(ctx.guild_id)
        content: dict = get_content("AUTOROLE_DROPDOWN",
                                    guild_data.configuration.language)

        autoroles = guild_data.autoroles
        if autoroles is None:
            return await ctx.send(content["NOT_SAVED_DROPDOWNS"])
        autorole = None
        for autorole in autoroles:
            if autorole.name == name:
                break

        if autorole is None:
            return await ctx.send(content["DROPDOWN_NOT_FOUND"])
        message_id = autorole.message_id

        original_message: ComponentMessage = await ctx.channel.fetch_message(
            int(message_id))
        if not original_message.components:
            return await ctx.send(content["MESSAGE_WITHOUT_DROPDOWN_TEXT"],
                                  hidden=True)

        select_component: Select = original_message.components[0].components[0]
        if select_component.custom_id != "autorole_select":
            return await ctx.send(content["MESSAGE_WITHOUT_DROPDOWN_TEXT"],
                                  hidden=True)

        if len(select_component.options) == 25:
            return await ctx.send(content["OPTIONS_OVERKILL_TEXT"],
                                  hidden=True)

        if emoji:
            emoji = self.get_emoji(emoji)

        if select_component.options[0].label == "None":
            select_component.options = [
                SelectOption(
                    label=option_name,
                    value=f"{role.id}",
                    emoji=emoji,
                    description=description,
                )
            ]
        else:
            select_component.options.append(
                SelectOption(
                    label=option_name,
                    value=f"{role.id}",
                    emoji=emoji,
                    description=description,
                ))
        select_component.disabled = False
        if select_component.placeholder == content["NO_OPTIONS_TEXT"]:
            select_component.placeholder = content["SELECT_ROLE_TEXT"]

        select_component.max_values = len(select_component.options)
        await original_message.edit(components=[select_component])
        await ctx.send(content["ROLE_ADDED_TEXT"], hidden=True)

        await autorole.update_component(select_component.to_dict())