示例#1
0
文件: bot.py 项目: DrowsyGoose/vkl
async def select(ctx, mess):

    await ctx.send(f"{mess}",
                   components=[
                       Select(placeholder="Нажми чтобы выбрать",
                              options=[
                                  SelectOption(label="Да", value="A"),
                                  SelectOption(label="Нет", value="B")
                              ])
                   ])

    interaction = await bot.wait_for(
        "select_option", check=lambda i: i.component[0].value == "A")

    await interaction.respond(
        content="Спасибо за ваш голос. Проверить голоса: !golosa", gg=gg + 1)

    interaction1 = await bot.wait_for(
        "select_option", check=lambda i: i.component[0].value == "B")

    await interaction1.respond(
        content="Спасибо за ваш голос. Проверить голоса: !golosa")
    if i.component[0].value == "A":
        gg = gg + 1
    elif i.components[0].value == "B":
        hh = hh + 1
示例#2
0
    async def single_channel_updater(self, ctx, settings_category: str, setting: str,
                                     setting_text: str):
        config = copy.deepcopy(self.bot.servers_config[str(ctx.guild.id)][settings_category])
        categories = ctx.guild.categories
        categories_selects = []
        for category in categories:
            list_channels = []
            for channel in category.channels:
                list_channels.append(channel.name)
            channels = ", ".join(list_channels)
            channels = channels[:50]
            categories_selects.append(SelectOption(label=category.name[:25],
                                                   value=category.id,
                                                   description=channels))

        res = await self.dynamic_menu(ctx, categories_selects,
                                      "Select category",
                                      "Select the category the desired channel is in (60s timeout)",
                                      max_values=1)

        if res is None:
            return

        category_id = res[0]
        category_channels = []

        for category in categories:
            if category_id == category.id:
                category_channels = category.text_channels

        channel_selects = []
        for channel in category_channels:
            if channel.topic is None:
                topic = "No topic set"
            else:
                topic = channel.topic[:50]
            channel_selects.append(SelectOption(label=channel.name[:25],
                                                value=channel.id,
                                                description=topic))

        res2 = await self.dynamic_menu(ctx, channel_selects,
                                       "Select channel",
                                       setting_text,
                                       max_values=1)
        if res2 is None:
            return
        channel_id = res2[0]
        channel_final = None
        for channel in category_channels:
            if channel_id == channel.id:
                channel_final = channel

        self.bot.servers_config[str(ctx.guild.id)][settings_category][setting] = channel_final.id
        self.bot.update_server_json()
        # await ctx.send("{} has been set as the {} {} channel".format(channel_final.mention, settings_category, setting))
        await ctx.send(embed=self.updated_embed(ctx, settings_category, setting, config,
                                                self.bot.servers_config[str(ctx.guild.id)][settings_category]))
示例#3
0
    async def role_updater(self, ctx, settings_category: str, setting: str, setting_text: str):
        config = copy.deepcopy(self.bot.servers_config[str(ctx.guild.id)][settings_category])
        roles = ctx.guild.roles
        role_selects = []
        for role in roles:
            if role.is_integration() or role.is_bot_managed():
                continue
            if role.name == "@everyone":
                continue
            if role.permissions != role.permissions.none():
                if role.id in config[setting]:
                    enabled = True
                else:
                    enabled = False

                role_selects.append(SelectOption(label=role.name[:25],
                                                 value=role.id,
                                                 default=enabled,
                                                 description="{} members have this role".format(len(role.members))))

        res = await self.dynamic_menu(ctx, role_selects,
                                      "Select Roles",
                                      setting_text)
        if res is not None:
            self.bot.servers_config[str(ctx.guild.id)][settings_category][setting] = res
            self.bot.update_server_json()
            # await ctx.send("Updated {} {}".format(settings_category, setting))
            await ctx.send(embed=self.updated_embed(ctx, settings_category, setting, config,
                                                    self.bot.servers_config[str(ctx.guild.id)][settings_category]))
示例#4
0
    async def category_updater(self, ctx, settings_category: str, setting: str, setting_text: str,
                               max_values: int = None):

        config = copy.deepcopy(self.bot.servers_config[str(ctx.guild.id)][settings_category])
        categories = ctx.guild.categories
        categories_selects = []
        for category in categories:
            if category.id in config[setting]:
                enabled = True
            else:
                enabled = False
            first_channel = category.channels[0]
            categories_selects.append(SelectOption(label=category.name[:25],
                                                   value=category.id,
                                                   default=enabled,
                                                   description="First channel name: {}".format(first_channel)))

        res = await self.dynamic_menu(ctx, categories_selects,
                                      "Select Categories",
                                      setting_text,
                                      max_values=max_values)
        if res is not None:
            self.bot.servers_config[str(ctx.guild.id)][settings_category][setting] = res
            self.bot.update_server_json()
            # await ctx.send("Updated {} {}".format(settings_category, setting))
            await ctx.send(embed=self.updated_embed(ctx, settings_category, setting, config,
                                                    self.bot.servers_config[str(ctx.guild.id)][settings_category]))
示例#5
0
 async def trivia(self, ctx, title, question, answer, *answers):
     """Starts a trivia"""
     await ctx.message.delete()
     embed = discord.Embed(title=title,
                           description=question,
                           colour=0xff564a)
     embed.set_author(name=ctx.author.display_name,
                      icon_url=ctx.author.avatar_url)
     options = [
         SelectOption(label=option, value=f"-{option}")
         for option in answers
     ]
     options.append(SelectOption(label=answer, value=f"+{answer}"))
     shuffle(options)
     await ctx.send(embed=embed,
                    components=[
                        Select(placeholder="Select an answer",
                               options=options,
                               custom_id="trivia"),
                        Button(label="Info",
                               style=ButtonStyle.grey,
                               id="trivia.info",
                               emoji="ℹ")
                    ])
示例#6
0
    async def channels_updater(self, ctx, settings_category: str, setting: str,
                               setting_text: str):
        config = copy.deepcopy(self.bot.servers_config[str(ctx.guild.id)][settings_category])
        selected_channels = []
        continue_loop = True
        while continue_loop:
            categories = ctx.guild.categories
            categories_selects = []
            for category in categories:
                list_channels = []
                for channel in category.channels:
                    list_channels.append(channel.name)
                channels = ", ".join(list_channels)
                channels = channels[:50]
                categories_selects.append(SelectOption(label=category.name[:25],
                                                       value=category.id,
                                                       description=channels))

            res = await self.dynamic_menu(ctx, categories_selects,
                                          "Select category",
                                          "Select the category the desired channel is in (60s timeout)",
                                          max_values=1)

            if res is None:
                return

            category_id = res[0]
            category_channels = []

            for category in categories:
                if category_id == category.id:
                    category_channels = category.text_channels

            channel_selects = []
            for channel in category_channels:
                if channel.topic is None:
                    topic = "No topic set"
                else:
                    topic = channel.topic[:50]
                channel_selects.append(SelectOption(label=channel.name[:25],
                                                    value=channel.id,
                                                    description=topic))

            res2 = await self.dynamic_menu(ctx, channel_selects,
                                           "Select channel",
                                           setting_text,
                                           max_values=None)
            if res2 is None:
                return
            channel_ids = res2
            for channel in category_channels:
                if channel.id in channel_ids:
                    if channel in selected_channels:
                        selected_channels.remove(channel)
                    else:
                        selected_channels.append(channel)

            selected_msg = ""
            if len(selected_channels) == 0:
                selected_msg = "No channels"
            else:
                for channel in selected_channels:
                    selected_msg += "{} ".format(channel.mention)

            continue_loop = await self.continue_checker(ctx,
                                                        "Channels: {}- are currently selected, continue adding? "
                                                        "(60s timeout)".format(selected_msg))

        selected_ids = []
        channel_final_msg = ""
        for channel in selected_channels:
            selected_ids.append(channel.id)
            channel_final_msg += "{} ".format(channel.mention)
        self.bot.servers_config[str(ctx.guild.id)][settings_category][setting] = selected_ids
        self.bot.update_server_json()
        # await ctx.send("{}have been set as the {} {} channels".format(channel_final_msg, settings_category, setting))
        await ctx.send(embed=self.updated_embed(ctx, settings_category, setting, config,
                                                self.bot.servers_config[str(ctx.guild.id)][settings_category]))
示例#7
0
 async def party(self, ctx: commands.Context, game_id=None):
     if not await botchannel_check(ctx):
         Bot.dispatch(self.bot, "botchannelcheck_failure", ctx)
         return
     time = datetime.datetime.now()
     user = ctx.author.name
     if not ctx.author.voice:
         embed = discord.Embed(
             title="Fehler",
             description="Du befindest dich in keinem Sprachkanal!",
             colour=await get_embedcolour(ctx.message),
         )
         embed._footer = await get_embed_footer(ctx)
         embed._thumbnail = await get_embed_thumbnail()
         await ctx.send(embed=embed)
         await log(
             f"{time}: Der Nutzer {user} hat versucht den Befehl {await get_prefix_string(ctx.message)}"
             "activities zu benutzen, befand sich aber in keinem Sprachkanal!",
             guildid=ctx.guild.id,
         )
         return
     if not game_id:
         embed = discord.Embed(
             title="Activities",
             description=
             "Wähle unten ganz einfach über das Auswahlfenster eine Aktivität aus!",
             colour=await get_embedcolour(ctx.message),
         )
         embed._footer = await get_embed_footer(ctx)
         embed._thumbnail = await get_embed_thumbnail()
         msg = await ctx.send(
             embed=embed,
             components=[
                 Select(
                     placeholder="Aktivität Auswählen",
                     options=[
                         SelectOption(label="YouTube WatchTogether",
                                      value="youtube",
                                      emoji="🎥"),
                         SelectOption(label="Schach",
                                      value="chess",
                                      emoji="♟"),
                         SelectOption(label="Poker",
                                      value="poker",
                                      emoji="🃏"),
                         SelectOption(label="Fishington",
                                      value="fishing",
                                      emoji="🎣"),
                         SelectOption(label="Betrayal",
                                      value="betrayal",
                                      emoji="🔪"),
                         SelectOption(label="Doodle Crew",
                                      value="doodle_crew",
                                      emoji="🖍"),
                         SelectOption(label="Scrabble",
                                      value="letter_tile",
                                      emoji="🎓"),
                         SelectOption(label="Spell Cast",
                                      value="spell_cast",
                                      emoji="📱"),
                         SelectOption(label="Word Snack",
                                      value="word_snack",
                                      emoji="☕"),
                     ],
                     custom_id="activities_choose",
                 )
             ],
         )
         try:
             interaction = await self.bot.wait_for(
                 event="select_option",
                 timeout=15.0,
                 check=lambda inter: inter.custom_id == "activities_choose"
                 and inter.message.id == msg.id and inter.author.id == ctx.
                 author.id,
             )
             try:
                 embed.add_field(
                     name="Link",
                     value=await get_activity_invite(
                         ctx, await
                         convert_gamename_id(interaction.values[0])),
                 )
                 await interaction.respond(type=7, embed=embed)
             except Exception:
                 interaction.respond(
                     f"Beim erstellen des Invite-Links ist ein Fehler aufgetreten!"
                 )
             await log(
                 f"{time}: Der Nutzer {user} hat mit dem Select des Activitys-Befehl interagiert!",
                 ctx.guild.id,
             )
         except asyncio.TimeoutError:
             pass
         await msg.disable_components()
         return
     else:
         try:
             embed = discord.Embed(
                 title="Activities",
                 description=
                 f"Klicke auf den folgenden Link, um die Aktivität zu starten:\n{await get_activity_invite(ctx, game_id)}",
                 colour=await get_embedcolour(ctx.message),
             )
             embed._footer = await get_embed_footer(ctx)
             embed._thumbnail = await get_embed_thumbnail()
             await ctx.send(embed=embed)
         except Exception:
             embed = discord.Embed(
                 title="Fehler",
                 description=
                 f"Die Aktivität mit der ID `{game_id}` konnte nicht gefunden werden!",
                 colour=await get_embedcolour(ctx.message),
             )
             embed._footer = await get_embed_footer(ctx)
             embed._thumbnail = await get_embed_thumbnail()
             await ctx.send(embed=embed)
             await log(
                 text=
                 f"{time}: Der Nutzer {user} hat versucht den Befehl {await get_prefix_string(ctx.message)}activities zu nutzen, gab jedoch eine ungültige ID an!",
                 guildid=ctx.guild.id,
             )
             return
     await log(
         f"{time}: Der Nutzer {user} hat den Befehl {await get_prefix_string(ctx.message)}"
         "activities benutzt!",
         guildid=ctx.guild.id,
     )
示例#8
0
 async def trivia(self, ctx, difficulty: str = None):
     categories = {
         "General Knowledge":"9",
         "Books":"10",
         "Film":"11",
         "Music":"12",
         "Musicals & Theatres":"13",
         "Television":"14",
         "Videogames":"15",
         "Boardgames": "16",
         "Science and Nature": "17",
         "Computers":"18",
         "Mathematics":"19",
         "Mythology":"20",
         "Sports":"21",
         "Geography":"22",
         "History":"23",
         "Politics":"24",
         "Art":"25",
         "Celebrities":"26",
         "Animals":"27",
         "Vehicles":"28",
         "Comics":"29",
         "Gadgets":"30",
         "Anime and Manga":"31",
         "Cartoon and Animations":"32"
     }
     msg = await ctx.send("Choose a category",components = [
         Select(placeholder="Select something", options=[SelectOption(label=x[0], value=x[1]) for x in categories.items()])
     ])
     try:
         interaction = await self.bot.wait_for("select_option", check=lambda inter: inter.user.id == ctx.author.id)
         await interaction.respond(type=6)
         await msg.edit("Choose a category",components = [
         Select(placeholder="Select something", options=[SelectOption(label=x[0], value=x[1]) for x in categories.items()], disabled=True)
     ])
         if difficulty is None:
             url = f"https://opentdb.com/api.php?amount=1&category={interaction.values[0]}"
         else:
             url = f"https://opentdb.com/api.php?amount=1&difficulty={difficulty.lower()}&category={interaction.values[0]}"
         r = requests.get(url)
         results = r.json()["results"][0]
         category = results["category"]
         difficulty = results["difficulty"]
         question = html.unescape(results["question"])
         correct_answer = html.unescape(results["correct_answer"])
         incorrect_answers = [html.unescape(
             incorrect_answer) for incorrect_answer in results["incorrect_answers"]]
         triviaEmbed = Embed(title=f"Question for {ctx.author.display_name}",
                             description=f"**Category**: {category} **Difficulty**: {difficulty}", color=ctx.author.color)
         options = " "
         answers = incorrect_answers + [correct_answer]
         random.shuffle(answers)
         for thing in answers:
             options += f"{thing}\n"
         triviaEmbed.add_field(name="Question", value=question, inline=False)
         triviaEmbed.add_field(name="Options", value=options, inline=False)
         msg = await ctx.send(
             embed=triviaEmbed,
             components=[[Button(style=ButtonStyle.blue, label=answer) for answer in answers]])
         try:
             interaction = await self.bot.wait_for("button_click", check = lambda i: i.user.id == ctx.author.id)
             if interaction.component.label in incorrect_answers:
                 await interaction.respond(type=6)
                 await msg.edit(
                     components=[[Button(style=ButtonStyle.green, label=ans) if ans == correct_answer else Button(
                         style=ButtonStyle.red, label=ans) for ans in answers]]
                 )
                 await ctx.send("That was the wrong answer")
             else:
                 await interaction.respond(type=6)
                 await msg.edit(
                     components=[[Button(style=ButtonStyle.green, label=ans, disabled=True) if ans == correct_answer else Button(
                         style=ButtonStyle.red, label=ans, disabled=True) for ans in answers]]
                 )
                 await ctx.send("That was the right answer")
         except TimeoutError:
             await ctx.send("No answer received in time")
     except TimeoutError:
         await ctx.send("No response was given in time")