示例#1
0
async def qnbank(ctx):
    Mathematics = Button(
        label="Mathematics",
        url=
        "https://aakritsubedi9.com.np/uploads/que-bank/Engineering-Mathematics-II.pdf"
    )
    Chemistry = Button(
        label="Chemistry",
        url=
        "https://aakritsubedi9.com.np/uploads/que-bank/Engineering-Chemistry.pdf"
    )
    Drawing = Button(
        label="Drawing",
        url=
        "https://aakritsubedi9.com.np/uploads/que-bank/Engineering-Drawing-II.pdf"
    )
    Electronics = Button(
        label="Electronics",
        url=
        "https://aakritsubedi9.com.np/uploads/que-bank/Basic-Electronics-Engineering.pdf"
    )
    Thermodynamics = Button(
        label="Thermodynamics",
        url="https://aakritsubedi9.com.np/uploads/que-bank/Thermodynamics.pdf")
    view = View()
    view.add_item(Mathematics)
    view.add_item(Chemistry)
    view.add_item(Drawing)
    view.add_item(Electronics)
    view.add_item(Thermodynamics)
    await ctx.reply(
        "**Old Questions**\nPro tip: Once you click __trust this domain__, the button will directly open the url without the confirmation box",
        view=view)
示例#2
0
    def __init__(self,
                 *args,
                 pages: list[Union[str, Embed]] = None,
                 num_pages=None,
                 original_author: User = None,
                 guild: Guild,
                 **kwargs):
        super().__init__(*args, **kwargs)

        self.children: list[Button] = []

        self.pages = pages
        self.num_pages = len(pages) if pages is not None else num_pages
        self.original_author = original_author
        self.guild = guild

        self.page_index = 0

        self.add_item(
            Button(
                style=ButtonStyle.blurple,
                label=Translatable("mrvn_api_views_paginator_button_first")))
        self.add_item(
            Button(style=ButtonStyle.gray,
                   label=Translatable("mrvn_api_views_paginator_button_prev")))
        self.add_item(
            Button(style=ButtonStyle.gray, label="N/A", disabled=True))
        self.add_item(
            Button(style=ButtonStyle.gray,
                   label=Translatable("mrvn_api_views_paginator_button_next")))
        self.add_item(
            Button(style=ButtonStyle.blurple,
                   label=Translatable("mrvn_api_views_paginator_button_last")))

        self.message = None
示例#3
0
async def cmds(ctx: MrvnCommandContext):
    cat_commands = {}

    for cat in categories.categories:
        cat_commands[cat] = runtime.bot.get_category_commands(cat, ctx.guild_id)

    cat_commands = {k: v for k, v in sorted(cat_commands.items(), key=lambda item: len(item[1]), reverse=True)}

    items = [Button(label=f"{ctx.translate(cat.name)} ({len(items)})", disabled=not len(items),
                    style=ButtonStyle.blurple if len(items) else ButtonStyle.gray) for cat, items in
             cat_commands.items()]

    view = CategoryView(ctx, items, author=ctx.author, timeout=10)

    message = await ctx.respond(ctx.translate("std_command_help_choose_category"), view=view)

    await view.wait()

    if view.category_len is None:
        return

    category, items = list(cat_commands.items())[view.category_len]
    count = len(items)

    num_pages = math.ceil(count / PAGE_SIZE) if count > PAGE_SIZE else 1

    paginator = CmdsPaginator(ctx, items, ctx.translate(category.name), num_pages=num_pages, timeout=30,
                              original_author=ctx.author, guild=ctx.guild)

    await paginator.attach(message)
示例#4
0
async def resources(ctx):
    MathSolution = Button(
        label="Math Solution",
        url=
        "https://aakritsubedi9.com.np/uploads/2/SH451_2020-12-07T02:52:49.778Z_Maths%20Solution%20II%20Sem.pdf"
    )
    view = View()
    view.add_item(MathSolution)
    await ctx.reply("**OK NERD!!**", view=view)
示例#5
0
    def __init__(self, tr: Translator, entries: list[BotStatusEntry],
                 **kwargs):
        items = [
            Button(style=ButtonStyle.danger, label=x.text) for x in entries
        ]

        super().__init__(tr, *items, **kwargs)

        self.entries = entries
        self.message = None
示例#6
0
class LevelsView(View):
    prev_button = Button(label='Previous',
                         style=discord.ButtonStyle.green,
                         custom_id=f'prev_cmd{time.time()}')
    next_button = Button(label='Next',
                         style=discord.ButtonStyle.green,
                         custom_id=f'next_cmd{time.time()}')

    def __init__(self, embeds, max_pages):
        super().__init__()
        self.page = 1
        self.embeds = embeds
        self.max_pages = max_pages
        self.next_button.callback = self.button_callback
        self.prev_button.callback = self.button_callback
        self.add_item(self.prev_button)
        self.add_item(self.next_button)
        self.disable_buttons()

    async def button_callback(self, interaction: discord.Interaction):
        button_id = interaction.data['custom_id']

        if button_id == self.next_button.custom_id:
            self.page += 1
        elif button_id == self.prev_button.custom_id:
            self.page -= 1

        self.disable_buttons()

        embed = self.embeds[self.page - 1]
        await interaction.response.edit_message(embed=embed, view=self)

    def disable_buttons(self):
        if self.page <= 1:
            self.prev_button.disabled = True
        else:
            self.prev_button.disabled = False
        if self.page == self.max_pages:
            self.next_button.disabled = True
        else:
            self.next_button.disabled = False
示例#7
0
    def __init__(self, ctx: MrvnCommandContext, **kwargs):
        super().__init__(ctx, **kwargs)

        self.ctx = ctx
        self.message = None

        for i in range(1, 10):
            if 3 < i <= 6:
                row = 1
            elif i > 6:
                row = 2
            else:
                row = 0

            self.add_item(Button(label=str(i), style=ButtonStyle.gray, row=row))

        self.add_item(Button(emoji="❌", row=3, style=ButtonStyle.red))
        self.add_item(Button(label="0", style=ButtonStyle.gray, row=3))
        self.add_item(Button(emoji="✅", row=3, style=ButtonStyle.green))

        self.code = ""
示例#8
0
async def list_(ctx: MrvnCommandContext, global_setting: bool):
    items = []

    for cat in settings.categories:
        cat_settings = cat.get_settings(global_setting)

        items.append(
            Button(label=ctx.translate(cat.name),
                   style=ButtonStyle.blurple
                   if len(cat_settings) else ButtonStyle.gray,
                   disabled=not len(cat_settings)))

    view = CategoryView(ctx, items, author=ctx.author, timeout=10)

    message = await ctx.respond(
        ctx.translate("std_command_settings_choose_category"), view=view)

    await view.wait()

    if view.category_len is None:
        return

    category = settings.categories[view.category_len]
    category_settings = category.get_settings(global_setting)

    count = len(category_settings)

    num_pages = math.ceil(count / PAGE_SIZE) if count > PAGE_SIZE else 1

    settings_list = []

    for setting in category_settings:
        if global_setting:
            value = (await setting.get_or_create())[0].value
        else:
            value = (await
                     setting.get_or_create(guild_id=ctx.guild_id))[0].value

        settings_list.append(
            (f"{setting.key} [{value}]", ctx.translate(setting.description)))

    paginator = CmdsPaginator(ctx,
                              settings_list,
                              ctx.translate(category.name),
                              is_global=global_setting,
                              num_pages=num_pages,
                              timeout=30,
                              original_author=ctx.author,
                              guild=ctx.guild)

    await paginator.attach(message)
示例#9
0
    async def anime(self, interaction: discord.Interaction, params: str):
        print(
            f'{interaction.user}({interaction.user.id}) executed Anime command.'
        )

        await interaction.response.send_message(embed=discord.Embed(
            title='Fetching Data...Please Wait.',
            color=self.client.guilds[0].get_member(self.client.user.id).color))

        search = AnimeSearch(params)

        if len(search.results) > 0:
            anime_data = search.results[0]

            anime_data_2 = Anime(anime_data.mal_id)

            print(anime_data_2.title)

            embed = discord.Embed(title=anime_data.title,
                                  description=anime_data_2.title_japanese,
                                  color=self.client.guilds[0].get_member(
                                      self.client.user.id).color,
                                  url=anime_data.url)
            embed.set_image(url=anime_data.image_url)
            embed.add_field(name='Synopsis',
                            value=anime_data.synopsis,
                            inline=False)
            embed.add_field(name='Episodes',
                            value=str(anime_data_2.episodes),
                            inline=True)
            embed.add_field(name='Status',
                            value=str(anime_data_2.status),
                            inline=True)
            embed.add_field(name='Score',
                            value=str(anime_data.score),
                            inline=True)

            embed.set_footer(text=f'Aired: {anime_data_2.aired}')

            button = Button(label='View on site',
                            style=discord.ButtonStyle.url,
                            url=anime_data_2.url)
            view = View()
            view.add_item(button)

            await interaction.edit_original_message(embed=embed, view=view)
        else:
            await interaction.edit_original_message(
                embed=await helpers.embed_helper.create_error_embed(
                    f'Could not find any anime similar to {params}'))
示例#10
0
    def __init__(self,
                 issue_data: dict,
                 api: GitHubAPI,
                 bot: Red,
                 author_id: int,
                 timeout: float = 300.0):  # 5 min
        super().__init__(timeout=timeout)
        self.issue_data = issue_data
        self.api = api
        self.bot = bot
        self.author_id = author_id
        self.is_pr = bool(issue_data.get("mergeable_state"))

        self.add_item(
            Button(style=ButtonStyle.link,
                   label="View on GitHub",
                   url=issue_data["html_url"],
                   row=1))

        if issue_data.get("merged"):
            openable = False
            closeable = False
            mergeable = False
        else:
            openable = issue_data["state"] == "closed" and not issue_data.get(
                "merged", False)
            closeable = issue_data["state"] == "open"
            mergeable = issue_data.get("mergeable_state") == "clean"

        self.btn_open.disabled = not openable
        self.btn_close.disabled = not closeable

        if not self.is_pr:
            self.remove_item(self.btn_merge)  # type:ignore
        else:
            self.btn_merge.disabled = not mergeable

        self.master_msg: Optional[Message] = None
示例#11
0
class PokemonView(View):
    prev_button = Button(label='Previous Form',
                         style=discord.ButtonStyle.green,
                         custom_id=f'prev_poke{time.time()}')
    shiny_button = Button(label='Toggle Shiny',
                          style=discord.ButtonStyle.blurple,
                          custom_id=f'shiny_poke{time.time()}',
                          emoji='✨')
    next_button = Button(label='Next Form',
                         style=discord.ButtonStyle.green,
                         custom_id=f'next_poke{time.time()}')

    def __init__(self, embeds, max_pages):
        super().__init__()
        self.page = 1
        self.shiny = False
        self.embeds = embeds
        self.max_pages = max_pages
        self.next_button.callback = self.button_callback
        self.prev_button.callback = self.button_callback
        self.shiny_button.callback = self.shiny_callback
        self.add_item(self.prev_button)
        self.add_item(self.shiny_button)
        self.add_item(self.next_button)
        self.disable_buttons()

    async def button_callback(self, interaction: discord.Interaction):
        button_id = interaction.data['custom_id']
        if button_id == self.next_button.custom_id:
            self.page += 1
        elif button_id == self.prev_button.custom_id:
            self.page -= 1

        self.disable_buttons()

        embed = self.embeds[self.page - 1]
        self.shiny = False
        self.update_image(embed)
        await interaction.response.edit_message(embed=embed, view=self)

    async def shiny_callback(self, interaction: discord.Interaction):
        button_id = interaction.data['custom_id']
        embed: discord.Embed = self.embeds[self.page - 1]
        if button_id == self.shiny_button.custom_id:
            self.shiny = not self.shiny
            self.update_image(embed)

        await interaction.response.edit_message(embed=embed, view=self)

    def disable_buttons(self):
        if self.page <= 1:
            self.prev_button.disabled = True
        else:
            self.prev_button.disabled = False
        if self.page == self.max_pages:
            self.next_button.disabled = True
        else:
            self.next_button.disabled = False

    def update_image(self, embed):
        url_list = embed.image.url.split('/')
        file_name = url_list[len(url_list) - 1]
        file_list = file_name.split('_')
        if self.shiny:
            if len(file_list) < 6:
                file_name = f'{file_name[:-4]}_s.png'
                embed.set_image(url=f'{img_url}{file_name}')
            embed.set_footer(text=f'Forms [{self.page}/{self.max_pages}] ✨')
        else:
            if len(file_list) > 5:
                file_name = f'{file_name[:-6]}.png'
                embed.set_image(url=f'{img_url}{file_name}')
            embed.set_footer(text=f'Forms [{self.page}/{self.max_pages}]')
示例#12
0
async def routine(ctx):
    view = View()
    Sunday = Button(label="Sunday", style=discord.ButtonStyle.green)

    async def Sunday_callback(interaction):
        embed = discord.Embed(title="   ", color=0xe100ff)
        embed.set_author(name="-SUNDAY-")
        embed.add_field(name="**Test**", value="11:00 - 11:45", inline=False)
        embed.add_field(name="**Maths - ChD**",
                        value="11:45 - 1:15",
                        inline=False)
        embed.add_field(name="**Drawing**", value="2:00 - 5:00", inline=False)
        embed.set_footer(text="Hope you fail!")
        await interaction.response.send_message(embed=embed)

    Sunday.callback = Sunday_callback
    view.add_item(Sunday)

    Monday = Button(label="Monday", style=discord.ButtonStyle.green)

    async def Monday_callback(interaction):
        embed = discord.Embed(title="   ", color=0xe100ff)
        embed.set_author(name="-MONDAY-")
        embed.add_field(name="**Thermodynamics**",
                        value="11:00 - 12:30",
                        inline=False)
        embed.add_field(name="**Electronics - BRM**",
                        value="12:30 - 1:15",
                        inline=False)
        embed.add_field(name="**Drawing**", value="2:00 - 5:00", inline=False)
        embed.set_footer(text="Hope you fail!")
        await interaction.response.send_message(embed=embed)

    Monday.callback = Monday_callback
    view.add_item(Monday)

    Tuesday = Button(label="Tuesday", style=discord.ButtonStyle.green)

    async def Tuesday_callback(interaction):
        embed = discord.Embed(title="   ", color=0xe100ff)
        embed.set_author(name="-TUESDAY-")
        embed.add_field(name="**Math - BK**",
                        value="11:00 - 12:30",
                        inline=False)
        embed.add_field(name="**Electronics - DG**",
                        value="12:30 - 2:00",
                        inline=False)
        embed.add_field(name="**Math - ChD**",
                        value="2:45 - 3:30",
                        inline=False)
        embed.add_field(name="**Chemistry - RPD**",
                        value="3:30 - 5:00",
                        inline=False)
        await interaction.response.send_message(embed=embed)

    Tuesday.callback = Tuesday_callback
    view.add_item(Tuesday)

    Wednesday = Button(label="Wednesday", style=discord.ButtonStyle.green)

    async def Wednesday_callback(interaction):
        embed = discord.Embed(title="   ", color=0xe100ff)
        embed.set_author(name="-WEDNESDAY-")
        embed.add_field(name="**Thermodynamics/Elctronics Lab**",
                        value="11:00 - 1:45",
                        inline=False)
        embed.add_field(name="**Chemistry - RPD**",
                        value="11:45 - 1:15",
                        inline=False)
        embed.add_field(name="**Thermodynamics -MLP**",
                        value="2:00 - 5:00",
                        inline=False)
        embed.set_footer(text="Hope you fail!")
        await interaction.response.send_message(embed=embed)

    Wednesday.callback = Wednesday_callback
    view.add_item(Wednesday)

    Thurdsday = Button(label="Thurdsday", style=discord.ButtonStyle.green)

    async def Thurdsday_callback(interaction):
        embed = discord.Embed(title="   ", color=0xe100ff)
        embed.set_author(name="-THURSDAY-")
        embed.add_field(name="**Thermodynamics**",
                        value="11:00 - 12:30",
                        inline=False)
        embed.add_field(name="**Electronics - BRM**",
                        value="12:30 - 1:15",
                        inline=False)
        embed.add_field(name="**Chemistry**",
                        value="2:00 - 2:45",
                        inline=False)
        embed.add_field(name="**Tutorial - BK**",
                        value="2:45 - 3:30",
                        inline=False)
        embed.add_field(name="**Tutorial - MLP**",
                        value="3:30 - 4:15",
                        inline=False)
        embed.add_field(name="**Tutorial - DG**",
                        value="4:15 - 5:00",
                        inline=False)
        embed.set_footer(text="Hope you fail!")
        await interaction.response.send_message(embed=embed)

    Thurdsday.callback = Thurdsday_callback
    view.add_item(Thurdsday)

    Friday = Button(label="Friday", style=discord.ButtonStyle.green)

    async def Friday_callback(interaction):
        embed = discord.Embed(title="   ", color=0x45a1f7)
        embed.set_author(name="-FRIDAY-")
        embed.add_field(name="**Electronics - BRM**",
                        value="11 - 12:30",
                        inline=False)
        embed.add_field(name="**Maths - ChD**",
                        value="12:30 - 1:15",
                        inline=False)
        embed.add_field(name="**Chemistry - NRB**",
                        value="2:00 - 2:45",
                        inline=False)
        embed.add_field(name="**Chemistry Lab**",
                        value="2:45 - 5:00",
                        inline=False)
        embed.set_footer(text="Hope you fail!")
        await interaction.response.send_message(embed=embed)

    Friday.callback = Friday_callback
    view.add_item(Friday)

    await ctx.reply("**Routine**", view=view)