Exemplo n.º 1
0
    async def scrambivia_loop(self):
        if self.game:
            loop = asyncio.get_running_loop()
            self.round += 1
            if (self.round > self.maxRound):
                await self.stop()
                return

            self.question, self.answer = triviautil.fetch_question()
            self.accepting_answers = True

            res = discord.Embed(
                title="Scrambivia Round " + str(self.round) + " of " +
                str(self.maxRound),
                description=util.insert_zero_width_space(self.question) +
                "\nAnswer: \"" +
                util.bold(unscrambleutil.scramble(self.answer)) + "\"",
                color=util.generate_random_color())

            await self.ctx.send(embed=res)

            self.timer = loop.time() + self.roundTimer
            while self.game:
                if (loop.time()) >= self.timer:
                    self.accepting_answers = False
                    res = discord.Embed(title="Round over!",
                                        description="The answer was: " +
                                        util.bold(str(self.answer)),
                                        color=util.generate_random_color())

                    await self.ctx.send(embed=res)
                    await asyncio.sleep(2)
                    await self.scrambivia_loop()
                    break
                await asyncio.sleep(1)
Exemplo n.º 2
0
 async def start(self):
     res = discord.Embed(
         title="Reaction Time",
         description="A reaction game (or, maybe ping diff) for you!",
         color=util.generate_random_color())
     res.add_field(
         inline=False,
         name="Rules",
         value=
         "Type anything in chat to get a point, but only after my message changes!\nIf you type too early, you won't be able to get the points for the round!"
     )
     res.add_field(
         inline=False,
         name="Time Control",
         value="There are " + util.bold(self.maxRound) +
         " rounds in this game!\nMy messages will change between " +
         util.bold(self.minTime) + " and " + util.bold(self.maxTime) +
         " seconds!\nIf no one types within " + util.bold(self.minTime) +
         " seconds, no one gets the point!\nNote: I don't take into account my or your pings to discord servers, so that's added onto your reaction times! Blame internet, **not** food!"
     )
     res.add_field(inline=False,
                   name="\u200b",
                   value="The game begins in " + util.bold(self.delay) +
                   " seconds!")
     await self.ctx.send(embed=res)
     await asyncio.sleep(self.delay)
     if self.game:
         res = discord.Embed(title="Let's begin!")
         await self.ctx.send(embed=res)
         await self.reaction_loop()
Exemplo n.º 3
0
 async def handle_on_message(self, message):
     if not message.author.bot and self.game and message.channel in self.created_channels and not self.tracked_players[
             message.author] and message.content.isnumeric() and len(
                 message.content) == self.code_length:
         b, c = uddercodeutil.calculateDistance(message.content, self.code)
         self.tracked_players[message.author] = True
         if b == self.code_length:
             self.game = False
             for channel in self.created_channels:
                 for player in self.tracked_players:
                     self.tracked_players[player] = True
                 res = discord.Embed(title="Someone guessed my code!",
                                     color=util.generate_random_color())
                 res.add_field(name='\u200b',
                               inline=False,
                               value=util.bold(message.author.name) +
                               " found the code to be " +
                               util.bold(self.code) + "!")
                 res.add_field(name='\u200b',
                               inline=False,
                               value="The game will end in " +
                               util.bold(self.round_timer) + " seconds.")
                 await channel.send(embed=res)
                 await self.ctx.send(embed=res)
                 await asyncio.sleep(self.round_timer)
                 await self.stop()
         else:
             res = discord.Embed(
                 title="You have " + util.bold(b) +
                 (" Bull and " if b == 1 else " Bulls and ") +
                 util.bold(c) + (" Cow! " if c == 1 else " Cows!"),
                 color=util.generate_random_color())
             await message.channel.send(embed=res)
Exemplo n.º 4
0
    async def unscramble_on(self, ctx):
        self.game = True
        self.guessed = False
        loop = asyncio.get_running_loop()
        if self.game:
            if self.round == self.maxRound:
                sorted_leaderboard = sorted(self.trackedPlayers.items(),
                                            key=lambda x: x[1],
                                            reverse=True)
                res = discord.Embed(title="Leaderboard",
                                    description="\n".join([
                                        util.bold(str(k) + ": " + str(v))
                                        for (k, v) in sorted_leaderboard
                                    ]),
                                    color=util.generate_random_color())
                await ctx.send(embed=res)
                await self.stop_unscramble(ctx)
                return
            # if self.round == self.maxRound:
            #     sortedPlayers = sorted(self.trackedPlayers.items(), key=lambda x: x[1], reverse=True)
            #     res = discord.Embed(title="Leaderboards", description="\n".join([(str(i[0]) + ": " + str(i[1])) for i in sortedPlayers]), color=util.generate_random_color())
            #     await ctx.send(embed=res)
            #     await self.stop_chainage(ctx)
            #     return
            self.round += 1

            spaceInsertedWord, self.currentWord = unscrambleutil.generate_random_word_scrambled(
                self.mode, self.minL, self.maxL)
            res = discord.Embed(
                title="Unscramble Round " + str(self.round) + " of " +
                str(self.maxRound),
                description="You have " + util.bold(str(self.roundTimer)) +
                " seconds to unscramble: " + util.bold(spaceInsertedWord),
                color=util.generate_random_color())
            await ctx.send(embed=res)

            # start the timer ONLY when all of the above are complete
            self.timer = loop.time() + self.roundTimer
            """
            Logic for timer that recursively calls this function.
            Important for advancing rounds and resetting timer! 
            """
            while self.game:
                if (loop.time()) >= self.timer:
                    res = discord.Embed(title="Round over! The word was: " +
                                        self.currentWord,
                                        color=util.generate_random_color())
                    self.game = False
                    await ctx.send(embed=res)
                    await asyncio.sleep(1)
                    await self.unscramble_on(ctx)
                    # self.timer = 10e22
                    break
                await asyncio.sleep(0.5)
            await asyncio.sleep(3)
        else:
            self.timer = 10e22
Exemplo n.º 5
0
    async def trivia_loop(self):
        if self.game:
            loop = asyncio.get_running_loop()

            self.round += 1

            if (self.round > self.maxRound):
                await self.stop()
                return

            self.question, self.answer = powutil.insert_zero_width_space(
                self.questionList[self.round - 1]
                ["question"]), self.questionList[self.round -
                                                 1]["answer"].lower().replace(
                                                     "<i>",
                                                     "").replace("</i>", "")
            if self.answer.startswith("the "):
                self.answer = self.answer[4:]
            if self.answer.startswith("an "):
                self.answer = self.answer[3:]
            if self.answer.startswith("a "):
                self.answer = self.answer[2:]

            self.accepting_answers = True

            desc = util.insert_zero_width_space(self.question)
            if self.scramble:
                desc += "\nUnscramble: \"" + util.bold(
                    unscrambleutil.scramble(self.answer)) + "\""
            res = discord.Embed(title="jsTrivia Round " + str(self.round) +
                                " of " + str(self.maxRound),
                                description=desc,
                                color=util.generate_random_color())
            await self.ctx.send(embed=res)

            self.timer = loop.time() + self.roundTimer
            while self.game:
                if (loop.time()) >= self.timer:
                    self.accepting_answers = False
                    res = discord.Embed(title="Round over!",
                                        description="The answer was: " +
                                        util.bold(str(self.answer)),
                                        color=util.generate_random_color())

                    await self.ctx.send(embed=res)
                    await asyncio.sleep(2)
                    await self.trivia_loop()
                    break
                await asyncio.sleep(1)
Exemplo n.º 6
0
    async def schwootsh_loop(self):
        if self.game:
            loop = asyncio.get_running_loop()
            self.round += 1
            if self.round > self.maxRound:
                await self.stop()
                return

            self.currentWord = wooshutil.generate_random_start()
            res = discord.Embed(
                title="Schwootsh Round " + str(self.round) + "/" +
                str(self.maxRound),
                description="Type in neighboring words to my word: " +
                util.bold(self.currentWord.upper()),
                color=util.generate_random_color())
            await self.ctx.send(embed=res)
            self.usedWords = set()
            self.usedWords.add(self.currentWord)
            self.timer = loop.time() + self.roundTimer
            """
            Logic for timer that recursively calls this function.
            Important for advancing rounds and resetting timer! 
            """
            while self.game:
                if (loop.time()) >= self.timer:
                    res = discord.Embed(title="Round over!",
                                        color=util.generate_random_color())
                    await self.ctx.send(embed=res)
                    await self.schwootsh_loop()
                    break
                await asyncio.sleep(1)
Exemplo n.º 7
0
 async def udder_loop(self):
     loop = asyncio.get_running_loop()
     if self.game:
         self.round += 1
         res = discord.Embed(title="Round " + str(self.round),
                             color=util.generate_random_color())
         for player in self.tracked_players:
             self.tracked_players[player] = False
         res.add_field(name='\u200b',
                       inline=False,
                       value="You have " +
                       util.bold(str(self.round_timer) + " seconds") +
                       " to submit an entry!")
         for channel in self.created_channels:
             await channel.send(embed=res)
         self.timer = loop.time() + self.round_timer
         while self.game:
             if (loop.time()) >= self.timer:
                 res = discord.Embed(title="Round over!",
                                     color=util.generate_random_color())
                 for channel in self.created_channels:
                     await channel.send(embed=res)
                 await asyncio.sleep(1)
                 await self.udder_loop()
                 break
             await asyncio.sleep(1)
Exemplo n.º 8
0
    async def findsolution(self, arg1, arg2):
        if arg2 == "r":
            arg2 = uddercodeutil.generateRandomCode(len(arg1))
        if len(arg1) == len(arg2) <= 6:
            stack = queue.deque()
            solutionList = [
                str(x).zfill(len(arg1))
                for x in range(len(uddercodeutil.numeric)**len(arg1))
            ]
            start = time.time()
            uddercodeutil.TPOA(10, 2, 1, uddercodeutil.TPOANode(arg1), arg2,
                               solutionList, stack)
            stop = time.time()
            uddercodeutil.reverseStack(stack)
            res = discord.Embed(title="UdderCode found!",
                                color=util.generate_random_color())
            stringBuild, guess = "", 0
            while stack:
                a = stack.pop()
                guess += 1
                stringBuild += "Guess " + str(guess) + ": " + util.bold(
                    a[0].code) + ", " + str(
                        a[1]) + (" Bull, " if a[1] == 1 else " Bulls, ") + str(
                            a[2]) + (" Cow\n" if a[2] == 1 else " Cows\n")

            res.add_field(name="Solution found at depth " + str(guess),
                          inline=False,
                          value=stringBuild)
            res.add_field(name="Time elapsed",
                          inline=False,
                          value=str(stop - start))
            await self.ctx.send(embed=res)
Exemplo n.º 9
0
 async def start(self):
     res = discord.Embed(title="Starting PowRacer!",
                         color=util.generate_random_color())
     res.add_field(
         name="Rules",
         inline=False,
         value=
         "Players have some time per round to type my randomly generated words!\nThere are "
         + util.bold(self.delayTime) +
         " seconds before it starts!\nI'll accept your message if it's at least "
         + util.bold(self.similarity) + "% similar!")
     await self.ctx.send(embed=res)
     await asyncio.sleep(self.delayTime)
     res = discord.Embed(title="Let's begin!")
     self.brokenText, self.text = await powutil.generate_k_random_words(
         self.minL, self.maxL, self.wordCount)
     await self.ctx.send(embed=res)
     await self.powracer_loop()
Exemplo n.º 10
0
 async def stop(self):
     self.game = False
     sorted_leaderboard = sorted(self.trackedPlayers.items(),
                                 key=lambda x: x[1],
                                 reverse=True)
     res = discord.Embed(
         title="Leaderboard",
         description="\n".join(
             (util.bold(k) + " WPM: " + util.bold(v[0]) + ", Similarity: " +
              util.bold(v[1]) + "%, Typos: " + util.bold(v[2]))
             for (k, v) in sorted_leaderboard),
         color=util.generate_random_color())
     await self.ctx.send(embed=res)
     res = discord.Embed(title="Stopping PowRacer!",
                         color=util.generate_random_color())
     await self.ctx.send(embed=res)
     self.usedWords = {}
     self.trackedPlayers = {}
     self.timer = 1e22
     self.ctx.bot.games.pop(self.ctx.guild.id)
Exemplo n.º 11
0
 async def stop(self):
     sorted_leaderboard = sorted(self.trackedPlayers.items(), key=lambda x: x[1], reverse=True)
     res = discord.Embed(title="Leaderboard", description="\n".join([util.bold(str(k) + ": " + str(v)) for (k, v) in sorted_leaderboard]), color=util.generate_random_color())
     await self.ctx.send(embed=res)
     res = discord.Embed(title="Unscramble Over!", color=util.generate_random_color())
     await self.ctx.send(embed=res)
     self.trackedPlayers = {}
     self.round = 0
     self.timer = 1e22
     self.game = False
     self.currentWord = ""
     self.ctx.bot.games.pop(self.ctx.guild.id)
Exemplo n.º 12
0
    async def start_gamerizer(self, ctx, *args):
        self.game = True
        self.context = ctx
        cogs = list(self.bot.cogs)
        self.games = 5 if len(args) == 0 else int(args[0])
        cogs.remove("Gamerizer")  # don't include self

        for item in cogs:
            self.queue.append(item)

        res = discord.Embed(title="Gamerizer Started!",
                            description=util.bold("Loaded " + str(self.games) +
                                                  " games!"),
                            color=util.generate_random_color())
        await ctx.send(embed=res)
        await asyncio.sleep(self.sleep)
        await self.gamerizer_on(ctx)
Exemplo n.º 13
0
 async def handle_on_message(self, message):
     channel = message.channel
     word = message.content.lower()
     if alphafuseutil.check_valid(self.currentLetters,
                                  word) and self.acceptingAnswers:
         if message.author.name in self.trackedPlayers:
             if word in self.usedWords.keys():
                 await message.add_reaction('❌')
                 user, rnd = self.usedWords[word]
                 if message.author.name == user:
                     await channel.send(
                         "What " + user +
                         "? You already used this word in round " +
                         util.bold(rnd) +
                         "! Use another word! (no penalty)")
                 else:
                     self.trackedPlayers[message.author.name][0] -= 1
                     self.trackedPlayers[message.author.name][1] = True
                     await channel.send("Unlucky, " + util.bold(word) +
                                        " was already used by " +
                                        util.bold(user) + " on round " +
                                        util.bold(rnd) + "! (-1 life)")
             else:
                 await message.add_reaction('✅')
                 self.usedWords[word] = [message.author.name, self.round]
                 self.trackedPlayers[message.author.name][1] = True
         else:
             if 1 <= self.round <= 3:
                 if word in self.usedWords.keys():
                     await message.add_reaction('❌')
                     user, rnd = self.usedWords[word]
                     self.trackedPlayers[message.author.name] = [
                         self.defaultLifeCount - self.round + 1, True
                     ]
                     self.trackedPlayers[message.author.name][0] -= 1
                     await channel.send("Unlucky, " + util.bold(word) +
                                        " was already used by " +
                                        util.bold(user) + " on round " +
                                        util.bold(rnd) + "! (-1 life)")
                 else:
                     await message.add_reaction('✅')
                     self.usedWords[word] = [
                         message.author.name, self.round
                     ]
                     self.trackedPlayers[message.author.name] = [
                         self.defaultLifeCount - self.round + 1, True
                     ]
Exemplo n.º 14
0
    async def start(self):
        self.game = True
        res = discord.Embed(
            title="Starting jsTrivia!",
            description=
            "Players answer my question correctly to get one point! There are "
            + str(self.maxRound) +
            " rounds in this Trivia!\nI'll give you the point as long as your answer is >="
            + util.bold(self.similarity) + "% similar!",
            color=util.generate_random_color())
        await self.ctx.send(embed=res)
        self.questionList = triviautil.fetch_questions_jservice()
        await asyncio.sleep(5)

        if len(self.questionList) == 0:
            await self.ctx.send("Unable to load questions, sorry!")
            await self.stop()
            return

        res = discord.Embed(title="Let's begin!")
        await self.ctx.send(embed=res)
        await self.trivia_loop()
Exemplo n.º 15
0
 async def stop(self):
     self.game = False
     sorted_leaderboard = sorted(self.trackedPlayers.items(),
                                 key=lambda x: x[1],
                                 reverse=True)
     res = discord.Embed(title="Leaderboard",
                         description="\n".join([
                             str(k) + ": " + str(v)
                             for (k, v) in sorted_leaderboard
                         ]),
                         color=util.generate_random_color())
     await self.ctx.send(embed=res)
     await asyncio.sleep(1)
     res = discord.Embed(
         title="Fastest Reaction",
         description=util.bold(
             str(self.minReactionSpeed[1]) + ": `" +
             str(round(self.minReactionSpeed[0] * 1000, 3)) + "ms`"),
         color=util.generate_random_color())
     await self.ctx.send(embed=res)
     res = discord.Embed(title="Reaction Time Over!")
     await self.ctx.send(embed=res)
     self.ctx.bot.games.pop(self.ctx.guild.id)
Exemplo n.º 16
0
 async def powracer_loop(self):
     self.game = True
     loop = asyncio.get_running_loop()
     if self.game:
         res = discord.Embed(
             title="Type the words below as quickly as possible!",
             description=self.brokenText + "\n\nYou have " +
             util.bold(self.wordCount * self.timePerWord) + " seconds!")
         await self.ctx.send(embed=res)
         self.startTime = loop.time()
         self.timer = loop.time() + self.wordCount * self.timePerWord
         """
         Logic for timer that recursively calls this function.
         Important for advancing rounds and resetting timer! 
         """
         while self.game:
             if (loop.time()) >= self.timer:
                 res = discord.Embed(title="PowRacer over!",
                                     color=util.generate_random_color())
                 await self.ctx.send(embed=res)
                 await asyncio.sleep(2)
                 await self.stop()
                 break
             await asyncio.sleep(1)
Exemplo n.º 17
0
 async def start(self):
     res = discord.Embed(title="Starting Unscramble!", color=util.generate_random_color())
     res.add_field(name="Rules", inline=False, value="Players have some time per round to unscramble the word I display!\nEach correct guess is 1 point.\nUse " + util.bold("!scramble") + "(rate limited) to shuffle the current word!\nEach round lasts 30 seconds, if you can't get the word by then, no one gets a point!\nLet's start!")
     await self.ctx.send(embed=res)
     # self.maxRound = int(args[0]) if (len(args) > 0 and (1 <= int(args[0]) <= 20)) else 10
     # self.minL = int(args[0]) if len(args) > 0 and 3 <= int(args[0]) <= 7 else 3
     # self.maxL = int(args[1]) if len(args) > 1 and 10 <= int(args[1]) <= 50 else 20
     # self.maxRound = int(args[0]) if len(args) > 0 else 50
     # self.mode = int(args[1]) if len(args) > 0 else 0
     self.timer = 1e22
     self.game = True
     await asyncio.sleep(5)
     res = discord.Embed(title="Let's begin!")
     await self.ctx.send(embed=res)
     await self.unscramble_loop()
Exemplo n.º 18
0
    async def alpha_loop(self):
        if self.game:
            # need a submission every round, so we can check that here:
            loop = asyncio.get_running_loop()
            self.round += 1
            if self.round >= 2:
                if self.round >= 4 and len(self.trackedPlayers) == 0:
                    await self.ctx.send("No one joined!")
                    await self.stop()
                    return
                self.trackedPlayersPrevious = self.trackedPlayers.copy()
                for k, v in list(self.trackedPlayers.items()):
                    # v is a list of [lives, submitted_previous]
                    lives, submitted_previous = v
                    if not submitted_previous:
                        self.trackedPlayers[k][0] -= 1
                    self.trackedPlayers[k][1] = False
                    if self.trackedPlayers[k][0] == 0:
                        del self.trackedPlayers[k]

                if len(self.trackedPlayers) == 0:
                    res = discord.Embed(
                        title="Winners",
                        description="\n".join(
                            [x for x in self.trackedPlayersPrevious.keys()]),
                        color=util.generate_random_color())
                    await self.ctx.send(embed=res)
                    await self.stop()
                    loop.close()
                    return

            if self.gameMode == 0:
                self.currentLetters = alphafuseutil.generate_random_string_of_length_unbiased(
                    self.letters[self.round]
                    if self.round < len(self.letters) - 1 else self.maxLetters)
            else:
                self.currentLetters = alphafuseutil.generate_random_string_of_length_biased(
                    self.letters[self.round]
                    if self.round < len(self.letters) - 1 else self.maxLetters)
            self.combinations = alphafuseutil.combinations(self.currentLetters)

            res = discord.Embed(title="Alpha Fuse Round " + str(self.round),
                                color=util.generate_random_color())
            if self.round == 1:
                res.add_field(name='\u200b',
                              inline=False,
                              value="You have " + util.bold(self.roundTimer) +
                              " second(s) to find a word! Good luck!")
                res.add_field(
                    name='\u200b',
                    inline=False,
                    value="\nEnter a word containing the letter(s): " +
                    util.bold(", ".join(
                        [x.upper() for x in self.currentLetters])))
                res.add_field(name='\u200b',
                              inline=False,
                              value="\nValid combinations: " +
                              util.bold(self.combinations))
            else:
                res.add_field(name='\u200b',
                              inline=False,
                              value="You have " + util.bold(self.roundTimer) +
                              " second(s) to find a word! Good luck!")
                res.add_field(
                    name='\u200b',
                    inline=False,
                    value="\nEnter a word containing the letter(s): " +
                    util.bold(", ".join(
                        [x.upper() for x in self.currentLetters])))
                res.add_field(name='\u200b',
                              inline=False,
                              value="\nValid combinations: " +
                              util.bold(self.combinations))
                res.add_field(
                    name='\u200b',
                    inline=False,
                    value="\nRemaining players: " + ", ".join(
                        list([
                            util.bold(str(x)) + ": " + str(y[0]) +
                            " lives" if y[0] > 1 else util.bold(str(x)) +
                            ": " + str(y[0]) + " life"
                            for (x, y) in self.trackedPlayers.items()
                        ])))

            await self.ctx.send(embed=res)
            self.acceptingAnswers = True

            # make timer last for the designated round

            if self.round != 1:
                self.roundTimer = round(
                    self.roundTimer * self.factor,
                    2) if round(self.roundTimer * self.factor,
                                2) > self.minTime else self.minTime
            self.timer = loop.time() + self.roundTimer
            """
            Logic for timer that recursively calls this function.
            Important for advancing rounds and resetting timer! 
            """
            while self.game:
                if (loop.time()) >= self.timer:
                    res = discord.Embed(title="Round over!",
                                        color=util.generate_random_color())
                    await self.ctx.send(embed=res)
                    self.acceptingAnswers = False
                    await asyncio.sleep(2)
                    await self.alpha_loop()
                    break
                await asyncio.sleep(1)
Exemplo n.º 19
0
    async def unscramble_loop(self):
        self.accepting_answer = False
        loop = asyncio.get_running_loop()

        self.round += 1

        if self.game:
            if self.round > self.maxRound:
                await self.stop()
                return
            
            spaceInsertedWord, self.currentWord = unscrambleutil.generate_random_word_scrambled(self.mode, self.minL, self.maxL)
            res = discord.Embed(title="Unscramble Round " + str(self.round) + " of " + str(self.maxRound), description="You have " + util.bold(str(self.roundTimer)) + " seconds to unscramble: " + util.bold(spaceInsertedWord), color=util.generate_random_color())
            await self.ctx.send(embed=res)
            self.accepting_answer = True
            # start the timer ONLY when all of the above are complete
            self.timer = loop.time() + self.roundTimer
            """
            Logic for timer that recursively calls this function.
            Important for advancing rounds and resetting timer! 
            """
            while self.game:
                if (loop.time()) >= self.timer:
                    res = discord.Embed(title="Round over! The word was: " + self.currentWord, color=util.generate_random_color())
                    await self.ctx.send(embed=res)
                    self.accepting_answer = False
                    await asyncio.sleep(1)
                    await self.unscramble_loop()
                    break
                await asyncio.sleep(0.5)