Example #1
0
async def timer(ctx):
    global timer1
    global timer2

    await ctx.send("time starts now")

    async def warning():
        await ctx.send("5 seconds remaining")
    async def time():
        await ctx.send("time")

    timer1 = Timer(17, warning)
    timer2 = Timer(22, time)
Example #2
0
async def timer_task():
    try:
        await update_status()
    except:
        pass
    global timer
    timer = Timer(10, timer_task)
Example #3
0
async def timer_task_sec():
    try:
        await ping_secondary()
    except:
        pass
    global timer_sec
    timer_sec = Timer(20, timer_task_sec)
Example #4
0
 async def end_timer_callback(self, channel):
     """
     Regulary checks whether everyone in the vc should be muted
     :param channel: The voice channel the author is in
     """
     self.end_timer = Timer(END_TIMEOUT * MINUTES,
                            self.unmute,
                            callback_args=(channel, ))
Example #5
0
async def on_ready():
    channel = await bot.fetch_channel(STATUS_CHANNEL_ID)
    global message
    message = await channel.fetch_message(STATUS_MESSAGE_ID)

    global timer, timer_sec
    global sec1_online, sec1_motd
    global sec2_online, sec2_motd
    if SEC1_IP:
        sec1_motd = SEC_PINGING_TEXT
    if SEC2_IP:
        sec2_motd = SEC_PINGING_TEXT

    try:
        await update_status()
        await ping_secondary()
    except:
        pass
    timer = Timer(10, timer_task)
    timer_sec = Timer(20, timer_task_sec)
Example #6
0
async def game(ctx):
    ''' Start a game of mahjong
    '''
    if str(ctx.message.channel.type) == "private":
        await ctx.send("This command does not work in DMs")
    else:
        global pending_games
        msg = await ctx.send("React to this message with ✅ to join the game. You cannot join a game while participating in another one.")
        pending_games[msg.id] = []
        await msg.add_reaction('✅')
        timer = Timer(1800, remove_react, callback_args = (msg,))
Example #7
0
 async def start_new_level(self, ctx, team, embeds):
     """
     Send the codes for the next level. Used on a timer
     So the next level is sent out after a predetermined
     Break time after the previous level was completed.
     Then, starts the timer for the level to end
     """
     for embed in embeds:
         await ctx.send(embed=embed)
     timer = Timer(constants.TIME_LIMIT,
                   self.send_times_up_message,
                   callback_args=(ctx, team, self.current_level[team]),
                   callback_async=True)
     return
Example #8
0
 async def start_new_level(self, ctx, channel, embeds):
     """Send the codes for the next level. Used on a timer
     So the next level is sent out after a predetermined
     Break time after the previous level was completed.
     Then, starts the timer for the level to end
     """
     for embed in embeds:
         await ctx.send(embed=embed)
     timer = Timer(
         cipher_race_utils.compute_level_time(
             self.current_races[channel][cipher_race_constants.LEVEL]),
         self.send_times_up_message,
         callback_args=(
             ctx, channel,
             self.current_races[channel][cipher_race_constants.LEVEL]),
         callback_async=True)
     return
Example #9
0
    async def startrace(self, ctx, sheet: str = cipher_race_constants.HP):
        """
        Start your race! You will have 60 seconds per level to solve the codes
        Usage: ~startrace <optional sheet> where sheet is {hp, challenge, common}
        """
        logging_utils.log_command("startrace", ctx.channel, ctx.author)
        channel = ctx.channel.id
        if channel in self.current_races:
            print("startrace called from a channel that's already racing!!")
            embed = discord_utils.create_embed()
            embed.add_field(
                name="Already Racing!",
                value=
                f"Stop trying to start a new race while you have one going!",
                inline=False)
            await ctx.send(embed=embed)
            return
        # Create entry in current_races
        self.current_races[channel] = dict()
        self.current_races[channel][cipher_race_constants.LEVEL] = 1
        # ~startrace challenge gives you 1000 random english word sheet
        # ~startrace hp gives you the harry potter sheet
        # ~startrace common gives you 1000 very common english words
        if sheet not in self.sheet_map:
            sheet = cipher_race_constants.HP

        self.current_races[channel][
            cipher_race_constants.CODE] = self.sheet_map[sheet]
        embeds, self.current_races[channel][
            cipher_race_constants.
            ANSWERS] = cipher_race_utils.create_code_embed(
                self.current_races[channel][cipher_race_constants.LEVEL],
                self.current_races[channel][cipher_race_constants.CODE],
                ctx.prefix)

        await ctx.send(embed=cipher_race_utils.get_opening_statement(sheet))
        # In a short time, send the codes
        time = Timer(cipher_race_constants.BREAK_TIME,
                     self.start_new_level,
                     callback_args=(ctx, channel, embeds),
                     callback_async=True)
Example #10
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)
Example #11
0
    async def answer(self, ctx, *args):
        """
        Check your  answer
        Usage: ~answer <your answer>
        """
        channel = ctx.channel.id
        logging_utils.log_command("answer", ctx.channel, ctx.author)

        # if the team isn't puzzling then we need to instruct them to use startpuzzle command first.
        if channel not in self.current_races:
            embed = discord_utils.create_embed()
            embed.add_field(
                name="No race!",
                value=
                "This channel doesn't have a race going on. You can't answer anything!",
                inline=False)
            embed.add_field(
                name="Start Race",
                value=f"To start a race, use {ctx.prefix}startrace",
                inline=False)
            await ctx.send(embed=embed)
            return
        print(
            f"All current answers: {self.current_races[channel][cipher_race_constants.ANSWERS]}"
        )

        # Remove the command and whitespace from the answer.
        user_answer = ''.join(args)
        result = cipher_race_utils.get_answer_result(
            user_answer,
            self.current_races[channel][cipher_race_constants.ANSWERS])

        if result == cipher_race_constants.CORRECT:
            await ctx.message.add_reaction(
                EMOJIS[cipher_race_constants.CORRECT_EMOJI])
        else:
            await ctx.message.add_reaction(
                EMOJIS[cipher_race_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_races[channel][
                cipher_race_constants.ANSWERS]) >= 1:
            return
        # If there are no answers left for the round, then the team has completed the level
        # Create the next level prep embed
        embed = cipher_race_utils.create_level_prep_embed(
            self.current_races[channel][cipher_race_constants.LEVEL])
        # Proceed to next level. Perform computation ahead of time.
        self.current_races[channel][cipher_race_constants.LEVEL] += 1
        # Creates all cipher_race embeds, updates used cipher_race IDS, and refreshes current answers for the next level.
        if cipher_race_constants.CODE in self.current_races[channel]:
            embeds, self.current_races[channel][
                cipher_race_constants.
                ANSWERS] = cipher_race_utils.create_code_embed(
                    self.current_races[channel][cipher_race_constants.LEVEL],
                    self.current_races[channel][cipher_race_constants.CODE],
                    ctx.prefix)
        else:
            embeds, self.current_races[channel][
                cipher_race_constants.
                ANSWERS] = cipher_race_utils.create_code_embed(
                    self.current_races[channel][cipher_race_constants.LEVEL],
                    self.codes, ctx.prefix)

        await ctx.send(embed=embed)
        Timer(cipher_race_constants.BREAK_TIME,
              self.start_new_level,
              callback_args=(ctx, channel, embeds),
              callback_async=True)
Example #12
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)