Esempio n. 1
0
 async def vote(self, ctx, *, message):
     """Vote on something."""
     options = message.split("|")
     if not 3 <= (len(options)) < 21:
         return await ctx.send(
             f"You must have a minimum of **2** options and a maximum of **20**! Remember to split your question and options with a `|`, e.g. `what is your favourite food?|pizza|cake|fries`")
     question = options[0]
     _options = options[1:]
     if len(question) >= 100:
         return await ctx.send("Your question is too long, please make it less than 100 characters.")
     if any(len(v) > 80 for v in _options):
         return await ctx.send(
             "One of your options is too long. Note that each option must be less than 80 characters.")
     question += "?" if not (question.endswith(('.', '?', '!'))) else '\u200b'
     embed = discord.Embed(colour=self.bot.colour)
     embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
     embed.title = question
     votes = []
     for x in range(len(_options)):
         emoji = cyberformat.to_emoji(x)
         _vote_dict = {'emoji': str(emoji), 'question': _options[x], 'votes': 0}
         votes.append(_vote_dict)
     _q_format = []
     for item in votes:
         if not item['question']:
             votes.remove(item)
             continue
         _q_format.append(f"{item['emoji']} **{item['question']}** • {cyberformat.bar(0, 10, '■', '□')}")
     embed.description = f"\n".join(_q_format)
     _msg = await ctx.send(embed=embed)
     for a in votes:
         await _msg.add_reaction(a['emoji'])
     gvotes = self.bot.global_votes  # convenience
     gvotes[_msg.id] = {'embed': embed, 'data': votes}
Esempio n. 2
0
    async def trivia(self, ctx, difficulty: str = None):
        trivia = aiotrivia.TriviaClient()
        difficulty = difficulty or random.choice(['easy', 'medium', 'hard'])
        try:
            question = await trivia.get_random_question(difficulty)
        except aiotrivia.AiotriviaException:
            return await ctx.send(
                f'**{difficulty}** is not a valid difficulty!')
        embed = discord.Embed(colour=ctx.bot.colour)
        embed.title = question.question
        responses = question.responses
        random.shuffle(responses)
        embed.description = "\n".join([
            f':regional_indicator_{lists.NUMBER_ALPHABET[i].lower()}: **{v}**'
            for i, v in enumerate(responses, 1)
        ])
        embed.add_field(
            name="Info",
            value=
            f'Difficulty: **{question.difficulty.title()}**\nCategory: **{question.category}**'
        )
        embed.set_footer(
            text="React with the correct answer! | You have 15 seconds")
        emojis = [cyberformat.to_emoji(x) for x in range(len(responses))]
        index = responses.index(question.answer)
        msg = await ctx.send(embed=embed)
        await trivia.close()
        for e in emojis:
            await msg.add_reaction(e)

        def check(reaction: discord.Reaction, user: discord.User):
            return reaction.message.id == msg.id and user.id == ctx.author.id and str(
                reaction.emoji) in emojis

        correct = emojis[index]

        try:
            r, u = await self.bot.wait_for('reaction_add',
                                           check=check,
                                           timeout=15)
            if str(r.emoji) == correct:
                await msg.edit(embed=discord.Embed(
                    colour=self.bot.colour,
                    description=
                    f"{ctx.tick()} Correct! The answer was {correct}, **{question.answer}**"
                ))
            else:
                await msg.edit(embed=discord.Embed(
                    colour=self.bot.colour,
                    description=
                    f"{ctx.tick(False)} Incorrect! The correct answer was {correct}, **{question.answer}**"
                ))
        except asyncio.TimeoutError:
            await msg.edit(embed=discord.Embed(
                colour=self.bot.colour,
                description=
                f"{ctx.tick(False)} You ran out of time! The correct answer was {correct}, **{question.answer}**"
            ))
Esempio n. 3
0
 if len(question) >= 100:
     return await ctx.send(
         "Your question is too long, please make it less than 100 characters."
     )
 if any(len(v) > 80 for v in _options):
     return await ctx.send(
         "One of your options is too long. Note that each option must be less than 80 characters."
     )
 question += "?" if not (question.endswith(
     ('.', '?', '!'))) else '\u200b'
 embed = discord.Embed(colour=self.bot.colour)
 embed.set_author(name=str(ctx.author), icon_url=ctx.author.avatar_url)
 embed.title = question
 votes = []
 for x in range(len(_options)):
     emoji = cyberformat.to_emoji(x)
     _vote_dict = {
         'emoji': str(emoji),
         'question': _options[x],
         'votes': 0
     }
     votes.append(_vote_dict)
 _q_format = []
 for item in votes:
     if not item['question']:
         votes.remove(item)
         continue
     _q_format.append(
         f"{item['emoji']} **{item['question']}** • {cyberformat.bar(0, 10, '■', '□')}"
     )
 embed.description = f"\n".join(_q_format)