Пример #1
0
    async def addchannel(self, ctx):
        """
        Argument to add a team's channel
        Usage: ~addchannel <channel_name> <{1, 2, 3}>
        Note: use ~addchannel 0 <{1, 2, 3}> to set team's channel to NONE
        """
        print("Received ~addchannel")
        # Remove command
        user_args = ctx.message.content.replace(
            f'{constants.BOT_PREFIX}addchannel',
            '').strip().replace('#', '')  # TODO: remove replace('#', '')
        print(user_args)
        tokens = user_args.split()

        if tokens[0] == '0':
            self.team_channel_ids[int(tokens[1]) - 1] = None
            embed = utils.create_embed()
            embed.add_field(
                name="Success",
                value=f"Successfully removed channel from team {int(tokens[1])}"
            )
            await ctx.send(embed=embed)
            return

        # TODO: better way to do this? Removing brackets seems hacky
        channel = self.bot.get_channel(
            int(tokens[0].replace('<', '').replace('>', '')))

        embed = utils.create_embed()
        if 1 <= int(tokens[1]) <= 3:
            self.team_channel_ids[int(tokens[1]) - 1] = channel.id
            embed.add_field(
                name="Success",
                value=
                f"Successfully updated Team {int(tokens[1])}'s channel to {channel}"
            )
        else:
            embed.add_field(
                name='Incorrect Usage',
                value='Usage: ~addchannel <channel_name> <{1, 2, 3}>')

        await ctx.send(embed=embed)
Пример #2
0
 async def giveup(self, ctx):
     """
     Give the answer to the team as if they had solved it.
     Usage: ~giveup
     """
     #embed = utils.create_solved_embed("Team,", self.answer)
     #await ctx.send(embed=embed)
     # EDIT: no giveup no longer gives answer. No giving up, teams!
     embed = utils.create_embed()
     embed.add_field(
         name="Giving up?",
         value=
         f"No! Never give up, never surrender!\n\nIf you need help using the bot, tag @{constants.HINT}.\nIf you're unable to complete the race, consider using a {constants.HINT}."
     )
     await ctx.send(embed=embed)
Пример #3
0
 async def reset(self, ctx):
     """
     Reset the bot as if it has just loaded up
     Usage: ~reset
     Note: Does not reload google sheet. Use ~reload for that
     """
     for team in range(len(self.team_names)):
         self.current_level[team] = 1
         self.current_answers[team] = []
         self.used_code_ids[team] = []
         self.currently_puzzling[team] = False
     embed = utils.create_embed()
     embed.add_field(name="Success",
                     value="Bot has been reset. I feel brand new!")
     await ctx.send(embed=embed)
Пример #4
0
 async def reload_sheet(self, ctx):
     """
     Reload the Google Sheet so we can update our codes instantly.
     Usage: ~reload
     """
     self.sheet = self.client.open_by_key(self.sheet_key).sheet1
     self.codes = pd.DataFrame(self.sheet.get_all_values(),
                               columns=constants.COLUMNS)
     print(
         f"{constants.BOT_PREFIX}reload used. Reloaded {constants.CODE} sheet"
     )
     embed = utils.create_embed()
     embed.add_field(name="Sheet Reloaded",
                     value="Google sheet successfully reloaded")
     await ctx.send(embed=embed)
Пример #5
0
 async def getchannels(self, ctx):
     """
     Get all channels and team names
     Usage: ~getchannels
     """
     print("Received ~getchannels")
     embed = utils.create_embed()
     for team in range(len(self.team_channel_ids)):
         embed.add_field(name=f"Team {team+1} Name",
                         value=f"{self.team_names[team]}",
                         inline=False)
         embed.add_field(
             name=f"Team {team+1} Channel",
             value=f"{self.bot.get_channel(self.team_channel_ids[team])}",
             inline=False)
     await ctx.send(embed=embed)
Пример #6
0
 async def getname(self, ctx):
     """
     Get a team name
     Usage: ~getname <{1, 2, 3}>
     """
     print("Received ~getname")
     # Remove command from message input
     teamnum = ctx.message.content.replace(f'{constants.BOT_PREFIX}getname',
                                           '').strip()
     embed = utils.create_embed()
     if 1 <= int(teamnum) <= 3:
         embed.add_field(
             name="Sucess",
             value=
             f"Team {teamnum}'s name is {self.team_names[int(teamnum)-1]}")
     else:
         embed.add_field(name='Incorrect Usage',
                         value='Usage: ~getname <{1, 2, 3}>')
     await ctx.send(embed=embed)
Пример #7
0
 async def pigpenpls(self, ctx):
     """
     Gives a cipher of a specific type
     Usage: ~pigpenpls <cipher_name>
     """
     print("Received ~pigpenpls")
     toks = ctx.message.content.split()
     cipher_abbrev = None
     embed = utils.create_embed()
     if len(toks) < 2:
         # pigpen default
         cipher_abbrev = 'pi'
     elif len(toks) == 2:
         for cipher in constants.CIPHERS:
             if toks[1].lower() == cipher:
                 cipher_abbrev = toks[1][:2]
         if cipher_abbrev is None:
             embed.add_field(name="Incorrect Usage",
                             value="Usage: ~pigpenpls or "
                             "~pigpenpls <braille, morse, semaphore>")
             await ctx.send(embed=embed)
             return
     else:
         embed.add_field(name="Incorrect Usage",
                         value="Usage: ~pigpenpls or "
                         "~pigpenpls <braille, morse, semaphore>")
         await ctx.send(embed=embed)
         return
     code_proposal = self.codes.sample()
     while cipher_abbrev not in code_proposal[constants.CODE].item():
         code_proposal = self.codes.sample()
     embed.add_field(name="Pigpen",
                     value=f"{code_proposal[constants.CODE].item()}")
     embed.add_field(
         name="Answer",
         value=f"|| {code_proposal[constants.ANSWER].item()} ||")
     embed.set_image(url=code_proposal[constants.CODE].item())
     await ctx.send(embed=embed)
Пример #8
0
    async def nameteam(self, ctx):
        """
        Change the name of a team
        Usage: ~nameteam <{1, 2, 3}> <new_name>
        """
        print("Received ~namedteam")
        # Remove command from the input message.
        user_args = ctx.message.content.replace(
            f'{constants.BOT_PREFIX}nameteam', '').strip()
        tokens = user_args.split()

        embed = utils.create_embed()
        if 1 <= int(tokens[0]) <= 3:
            self.team_names[int(tokens[0]) - 1] = " ".join(tokens[1:])
            embed.add_field(
                name="Success",
                value=
                f"Successfully updated Team {int(tokens[0])}'s name to to {' '.join(tokens[1:])}"
            )
        else:
            embed.add_field(name='Incorrect Usage',
                            value='Usage: ~nameteam <{1, 2, 3}> <new_name>')
        await ctx.send(embed=embed)
Пример #9
0
    async def startpuzzle(self, ctx):
        """
        Start your race! You will have 60 seconds per level to solve the codes
        Usage: ~startrace
        """
        team = self.get_team(ctx.channel.id)
        if team < 0:
            print("startrace called from an invalid channel!")
            embed = utils.create_embed()
            embed.add_field(
                name="Can't do that!",
                value="Cannot solve that puzzle from this channel.")
            await ctx.send(embed=embed)
            return
        # Housekeeping
        print(f"Received startrace from team {self.team_names[team]}")
        if self.currently_puzzling[team]:
            return
        else:
            self.reset_code(team)
            self.currently_puzzling[team] = True

        # Creates the embeds containing the codes for that level as well as updates the IDs we're using and the acceptable answers for the level
        embeds, self.used_code_ids[team], self.current_answers[
            team] = utils.create_code_embed(1, self.codes, self.used_code_ids)
        self.current_answers[team] = [
            answer.replace(' ', '') for answer in self.current_answers[team]
        ]

        await ctx.send(embed=utils.get_opening_statement(self.team_names[team])
                       )
        # In a short time, send the codes
        time = Timer(constants.BREAK_TIME,
                     self.start_new_level,
                     callback_args=(ctx, team, embeds),
                     callback_async=True)
Пример #10
0
    async def answer(self, ctx):
        """
        Check your  answer
        Usage: ~answer <your answer>
        """
        team = self.get_team(ctx.channel.id)
        if team < 0:
            print("answer called from an invalid channel!")
            embed = utils.create_embed()
            embed.add_field(
                name="Can't do that!",
                value="Cannot solve that puzzle from this channel.")
            await ctx.send(embed=embed)
            return
        # log command in console
        print(f"Received answer from {self.team_names[team]}")
        print(f"All current answers: {self.current_answers}")
        # if the team isn't puzzling then we need to instruct them to use startpuzzle command first.
        if not self.currently_puzzling[team]:
            embed = utils.create_no_code_embed()
            await ctx.send(embed=embed)
            return
        # Remove the command and whitespace from the answer.
        user_answer = ctx.message.content.replace(
            f'{constants.BOT_PREFIX}answer', '').replace(' ', '')
        result = utils.get_answer_result(team, user_answer,
                                         self.current_answers[team])

        if result == constants.CORRECT:
            await ctx.message.add_reaction(EMOJIS[constants.CORRECT_EMOJI])
        else:
            await ctx.message.add_reaction(EMOJIS[constants.INCORRECT_EMOJI])

        # We pop off the correct answers as they are given, so at some point current_answers will be an empty list.
        # If there are more answers left, don't do any of that level complete nonsense.
        if len(self.current_answers[team]) >= 1:
            return
        # If there are no answers left for the round, then either the team has completed the level, or the team has completed the entire puzzle.
        if self.current_level[team] >= 5:
            # Congratulate Team for solving the puzzle
            embed = utils.create_solved_embed(self.team_names[team],
                                              self.answer)
            self.currently_puzzling[team] = False
            print(f"{self.team_names[team]} has solved the puzzle!")
            await ctx.send(embed=embed)
            return
        else:
            # Create the next level prep embed
            embed = utils.create_level_prep_embed(self.current_level[team],
                                                  self.team_names[team])
            # Proceed to next level. Perform computation ahead of time.
            self.current_level[team] += 1
            # Creates all code embeds, updates used code IDS, and refreshes current answers for the next level.
            embeds, self.used_code_ids[team], self.current_answers[
                team] = utils.create_code_embed(self.current_level[team],
                                                self.codes,
                                                self.used_code_ids[team])

            await ctx.send(embed=embed)
            time = Timer(constants.BREAK_TIME,
                         self.start_new_level,
                         callback_args=(ctx, team, embeds),
                         callback_async=True)