Пример #1
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)
Пример #2
0
    async def reaction_loop(self):
        if self.game:
            loop = asyncio.get_running_loop()
            self.round += 1
            if (self.round > self.maxRound):
                await self.stop()
                return
            res = discord.Embed(
                title="Reaction Time Round " + str(self.round) + " of " +
                str(self.maxRound),
                description=
                "Wait to type something after this message changes!",
                color=util.generate_random_color())
            self.msgid = await self.ctx.send(embed=res)
            self.tooearly = []
            self.acceptingAnswer = False
            await asyncio.sleep(await rtu.generate_random_time(
                self.minTime, self.maxTime))
            self.acceptingAnswer = True
            res = discord.Embed(title="Reaction Time Round " +
                                str(self.round) + " of " + str(self.maxRound),
                                description="Type something now!",
                                color=util.generate_random_color())
            await self.msgid.edit(embed=res)

            self.timer = loop.time() + self.minTime
            while True:
                if (loop.time()) >= self.timer:
                    res = discord.Embed(title="Round Over!")
                    await self.ctx.send(embed=res)
                    await asyncio.sleep(2)
                    await self.reaction_loop()
                    break
                await asyncio.sleep(0.5)
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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
Пример #7
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)
Пример #8
0
    async def udder_on(self, ctx):
        # await ctx.send("Testing: " + str(self.round))
        # loop = asyncio.get_running_loop()
        # end_time = loop.time() + __SECONDS__[self.round] if self.round < len(__SECONDS__) - 1 else 5
        # que = queue.Queue()
        loop = asyncio.get_running_loop()

        if self.game:
            self.round += 1
            # global __ROUNDTIMER__

            res = discord.Embed(title="Round " + str(self.round),
                                color=util.generate_random_color())

            # if self.round == 1:
            for player in self.tracked_players:
                self.tracked_players[player] = False

            res.add_field(name='\u200b',
                          inline=False,
                          value="You have **" + str(self.round_timer) +
                          " seconds** to submit an entry!")

            # print(self.created_channels)
            for channel in self.created_channels:
                # print("inner loop")
                await channel.send(embed=res)
            """
            Logic for timer that recursively calls this function.
            Important for advancing rounds and resetting timer! 
            """
            self.timer = loop.time() + self.round_timer

            # await asyncio.sleep(1)

            while self.game:
                # print(self.timer, loop.time())
                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_on(ctx)
                    break
                await asyncio.sleep(1)
            # await ctx.send('Test success!')
        else:
            self.timer = 10e22
Пример #9
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()
Пример #10
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)
Пример #11
0
 async def alpha_check(self, ctx, arg1):
     """
     Returns "valid" or "invalid" based on the submission. 
     """
     c = "Valid" if alphafuseutil.in_wordlist(arg1) else "Invalid"
     res = discord.Embed(title=c, color=util.generate_random_color())
     await ctx.send(embed=res)
Пример #12
0
 async def stop(self):
     self.game = False
     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 self.ctx.send(embed=res)
     res = discord.Embed(title="Template Over!",
                         color=util.generate_random_color())
     await self.ctx.send(embed=res)
     self.ctx.bot.games.pop(self.ctx.guild.id)
Пример #13
0
 async def stop_pow(self, ctx):
     res = discord.Embed(title="Pow! Over!", color=util.generate_random_color())
     await ctx.send(embed=res)
     self.trackedPlayers = {}
     self.round = 0
     self.timer = 10e22
     self.game = False
Пример #14
0
    async def embed_creator(self, ctx, command_name):
        prefix = ctx.bot.command_prefix
        if not self.command_name:
            # Default help construction goes here!
            desc = ""
            for cog in ctx.bot.cogs:
                for command in ctx.bot.get_cog(cog).walk_commands():
                    if not command.hidden:
                        desc += command.name
                        desc += "\n"
            res = discord.Embed(title="General Help",
                                description=discord.Embed.Empty,
                                color=util.generate_random_color())
            for cog in ctx.bot.cogs:
                val = ""
                for command in ctx.bot.get_cog(cog).walk_commands():
                    if not command.hidden:
                        val += command.name
                        val += "\n"
                if val != "":
                    res.add_field(name=cog, value=val, inline=True)
                res.set_footer(
                    text=
                    f'{prefix}help for a list of commands\n{prefix}help <command> for detailed help'
                )
            return res
        elif ctx.bot.get_command(self.command_name):
            cmd = ctx.bot.get_command(self.command_name)
            desc = cmd.short_doc
            aliases = ", ".join(["`" + c + "`" for c in cmd.aliases
                                 ]) if len(cmd.aliases) != 0 else ""
            details = "\n".join(cmd.help.splitlines()[1:])
            res = discord.Embed(title=f'{cmd.name}',
                                description=desc,
                                color=util.generate_random_color())
            if aliases:
                res.add_field(name="Aliases", value=aliases, inline=False)
            if details != "":
                res.add_field(name="Options", value=details, inline=False)

            res.set_footer(
                text=
                f'{prefix}help for a list of commands\n{prefix}help <command> for detailed help'
            )
            return res
        else:
            return await ctx.send("Command doesn't exist!")
Пример #15
0
 async def stop_gamerizer(self, ctx):
     self.round = 0
     self.game = False
     self.queue.clear()
     res = discord.Embed(title="Gamerizer over!",
                         description="Thanks for playing!",
                         color=util.generate_random_color())
     await ctx.send(embed=res)
Пример #16
0
 async def stop_unscramble(self, ctx):
     res = discord.Embed(title="Unscramble Over!",
                         color=util.generate_random_color())
     await ctx.send(embed=res)
     self.trackedPlayers = {}
     self.round = 0
     self.timer = 10e22
     self.game = False
     self.currentWord = ""
Пример #17
0
 async def stop_alpha(self, ctx):
     res = discord.Embed(title="Stopping Alpha Fuse!",
                         color=util.generate_random_color())
     await ctx.send(embed=res)
     self.usedWords = {}
     self.trackedPlayers = {}
     self.round = 0
     self.timer = 10e22
     self.game = False
Пример #18
0
    async def schwootsh_on(self, ctx):

        loop = asyncio.get_running_loop()
        if self.game:
            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_schwootsh(ctx)
                return
            self.round += 1

            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: **" +
                self.currentWord.upper() + "**",
                color=util.generate_random_color())
            await 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 ctx.send(embed=res)
                    await self.schwootsh_on(ctx)
                    break
                await asyncio.sleep(1)
        else:
            self.timer = 10e22
Пример #19
0
 async def schwootsh_25(self, arg1):
     """
     Returns a list of up to 25 neighboring words of the given word.
     """
     res = discord.Embed(
         title=discord.Embed.Empty,
         description=", ".join(
             wooshutil.get_levenshtein_neighbors_possibility(arg1)),
         color=util.generate_random_color())
     await self.ctx.send(embed=res)
Пример #20
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)
Пример #21
0
 async def queue(self, ctx, arg1):
     if self.game:
         if arg1 in self.bot.cogs:
             self.queue.append(arg1)
         self.games += 1
         await ctx.message.add_reaction('✅')
     else:
         res = discord.Embed(
             title="Gamerizer not currently active, I can't queue games!",
             color=util.generate_random_color())
         await ctx.send(embed=res)
Пример #22
0
 async def handle_on_reaction_add(self, reaction, user):
     if reaction.message.id == self.msgid and not user.bot and user not in self.tracked_players:
         self.tracked_players.append(user)
     if reaction.message.channel in self.created_channels and not user.bot:
         board = self.created_channels[reaction.message.channel]
         if not board.placePiece(self.emojiMap[reaction.emoji], user):
             pass
         else:
             res = discord.Embed(title=board.player1.name + " vs. " +
                                 board.player2.name,
                                 description=board.getBoard())
             await reaction.message.edit(embed=res)
             (p1, p2) = board.checkWin()
             if p1:
                 self.finished_games += 1
                 res = discord.Embed(title=board.player1.name + " Wins!",
                                     color=util.generate_random_color())
                 await reaction.message.channel.send(embed=res)
                 if self.finished_games == len(self.created_channels):
                     for channel in self.created_channels:
                         res = discord.Embed(
                             title="Everyone's finished playing!",
                             description="Fourplay will end in 15 seconds!",
                             color=util.generate_random_color())
                         await channel.send(embed=res)
                         await asyncio.sleep(15)
                         await self.stop()
             if p2:
                 self.finished_games += 1
                 res = discord.Embed(title=board.player2.name + " Wins!",
                                     color=util.generate_random_color())
                 await reaction.message.channel.send(embed=res)
                 if self.finished_games == len(self.created_channels):
                     for channel in self.created_channels:
                         res = discord.Embed(
                             title="Everyone's finished playing!",
                             description="Fourplay will end in 15 seconds!",
                             color=util.generate_random_color())
                         await channel.send(embed=res)
                         await asyncio.sleep(15)
                         await self.stop()
Пример #23
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)
Пример #24
0
 async def start_sigma(self, ctx, *args):
     res = discord.Embed(title="Starting Sigma Fuse!", color=util.generate_random_color())
     res.add_field(name="Rules", inline=False, value="Players have some time per round to find a word that contains the displayed letters **in order**.\nIf you repeat a word someone else used, you lose a life!\nIf you repeat your own word, there's no penalty.")
     await ctx.send(embed=res)
     self.round = 0
     self.gameMode = int(args[0]) if len(args) > 0 else 0
     self.game = True
     self.timer = 10e22
     self.context = ctx
     self.usedWords = {}
     self.trackedPlayers = {}
     await self.sigma_on(ctx)
Пример #25
0
 async def start(self):
     self.game = True
     res = discord.Embed(
         title="Starting Scrambivia!",
         description=
         "Players answer my question correctly to get one point! There are "
         + str(self.maxRound) +
         " rounds in this Scrambivia!\nI'll display the answer randomly scrambled, use !scramble to shuffle the answer!\nIf the answer is tricky, I'll let some typos slide (1 per 8 characters and 1 for non-alphanumeric characters)!",
         color=util.generate_random_color())
     await self.ctx.send(embed=res)
     await asyncio.sleep(10)
     await self.scrambivia_loop()
Пример #26
0
    async def start_fourplay(self, ctx):
        self.context = ctx
        res = discord.Embed(title="Starting Fourplay!", color=util.generate_random_color())
        res.add_field(name="Rules", inline=False, value="You have **" + str(self.ready_up) + "** seconds to join! React to this message to play!\nIf there are an odd number of players, one of you won't have an opponent. That one person will play me instead!")
        res.add_field(name="How to Win", inline=False, value="Line up **4** chips against your opponent, and you win!")
        res.add_field(name="Time Control", inline=False, value="If your opponent doesn't respond within **15** seconds, I will make a move for them!")
        # res.add_field(name="\u200b", inline=False, value="I have a code of length **" + str(self.code_length) + "**, you're meant to guess it!")
        # res.add_field(name="\u200b", inline=False, value="Each round is **20** seconds, I'll tell you how many Bulls and Cows you have.")
        # res.add_field(name="\u200b", inline=False, value="A **Bull** is a **correct number and in correct place.**\nA **Cow** is a **correct number but in an incorrect place.**\nFor example, if my code is **5688** and you guess **1234**, I'll tell you you have **0** Bulls and **0** Cows!\nIf you guess **6518**, I'll tell you you have **1** Bull and **2** Cows!")
        # res.add_field(name="\u200b", inline=False, value="To minimize peeking, I'll make a channel just for you! (and sneaky admins)\nI will only respond to messages in that channel, so enter your submissions there!")
        msg = await ctx.send(embed=res)
        self.msgid = msg.id
        self.game = True
        self.context = ctx
        self.created_channels = {}
        self.tracked_players = []

        await msg.add_reaction("\u2705")
        await asyncio.sleep(self.ready_up)

        guild = ctx.guild

        if len(self.tracked_players) == 0: 
            await ctx.send("No one joined!")
            await self.stop_fourplay(ctx)

        # print(type(self.tracked_players))
        # random.shuffle(self.tracked_players)
        # need to check for odd players
        for i in range(0, (len(self.tracked_players) if len(self.tracked_players) % 2 == 0 else (len(self.tracked_players) - 1)), 2):
            uuid_short = str(uuid.uuid4())[:8]
            role = await guild.create_role(name=uuid_short)
            uuid_role = discord.utils.get(guild.roles, name=uuid_short)

            overwrites = {
                guild.default_role: discord.PermissionOverwrite(read_messages=False),
                guild.me: discord.PermissionOverwrite(read_messages=True),
                uuid_role: discord.PermissionOverwrite(read_messages=True)
            }

            channel = await guild.create_text_channel(uuid_short, overwrites=overwrites, topic="Secret channel just for and your opponent! (and admins)")
            
            b = fourplayutil.Board()
            b.player1 = self.tracked_players[i]
            b.player2 = self.tracked_players[i+1]

            self.created_channels.setdefault(channel, b)
            self.created_roles.append(role)
            
            await self.tracked_players[i].add_roles(uuid_role)
            await self.tracked_players[i+1].add_roles(uuid_role)
        await self.fourplay_on(ctx)
Пример #27
0
    async def stop_fourplay(self, ctx):
        res = discord.Embed(title="Fourplay over!", color=util.generate_random_color())
        await ctx.send(embed=res)

        for channel in self.created_channels:
            await channel.delete()
        for role in self.created_roles:
            await role.delete()
        self.created_channels = {}
        self.created_roles = []
        self.tracked_players = []
        self.timer = 1e22
        self.game = False
Пример #28
0
 async def omega_poss(
     self,
     ctx,
     arg1,
     brief="Usage: !omega_poss <string>",
     description="Usage: !omega_poss <strings>, returns the number of valid possibilities for the given character combination."
 ):
     """
     Returns the number of valid combinations for the given letter combination.
     """
     res = discord.Embed(title=alphafuseutil.combinations(arg1),
                         color=util.generate_random_color())
     await ctx.send(embed=res)
Пример #29
0
 async def omega_random(
     self,
     ctx,
     arg1,
     brief="Usage: !omega_random <string>",
     description="Usage: !omega_random <string>, returns a single valid possibility if there exists one at random for the given character combination."
 ):
     """
     Returns one valid word at random that satisfies the given letter combination. 
     """
     res = discord.Embed(title=alphafuseutil.get_random_possibility(arg1),
                         color=util.generate_random_color())
     await ctx.send(embed=res)
Пример #30
0
 async def on_reaction_add(self, reaction, user):
     if reaction.message.id == self.msgid and not user.bot and user not in self.tracked_players:
         self.tracked_players.append(user)
     # print(reaction)
     # print(reaction.emoji)
     # not the bot game
     if reaction.message.channel in self.created_channels and not user.bot:
         board = self.created_channels[reaction.message.channel]
         if not board.placePiece(self.emojiMap[reaction.emoji], user):
             pass
         else: 
             res = discord.Embed(title=board.player1.name + " vs. " + board.player2.name, description=board.getBoard())
             await reaction.message.edit(embed=res)
             (p1, p2) = board.checkWin()
             if p1:
                 self.finished_games += 1
                 res = discord.Embed(title=board.player1.name + " Wins!", color=util.generate_random_color())
                 await reaction.message.channel.send(embed=res)
             if p2: 
                 self.finished_games += 1
                 res = discord.Embed(title=board.player2.name + " Wins!", color=util.generate_random_color())
                 await reaction.message.channel.send(embed=res)