Beispiel #1
0
async def pound_countdown(
        bot):  # Background task to countdown to when the pound opens
    await bot.wait_until_ready(
    )  # Wait until bot has loaded before starting background task
    while not bot.is_closed():  # While bot is still running
        if not Variables.cooldown:  # If command is not on cooldown
            data = await cs.get_pound_string()  # Get pound text
            pound_type = data[0]
            string = data[1]
            seconds = cs.get_pound_time(string)  # Extract total seconds

        seconds, sleep_amount, send_msg = library.calculate_sleep_amount(
            seconds)

        if send_msg:  # If sending message is needed
            time = round(seconds / 60)
            if time in Variables.autoremind_times:
                channel_ids = await library.get_sending_channels(time)
                for channel in channel_ids:
                    sending_channel = bot.get_channel(channel)
                    messages = await library.prepare_message(
                        channel, time, pound_type)
                    try:
                        for message in messages:
                            await sending_channel.send(message)
                    except (AttributeError, discord.errors.Forbidden):
                        pass

        await asyncio.sleep(sleep_amount)  # Sleep for sleep amount
 def test_on_cooldown_less_than_1_hour(self):
     Variables.cooldown = True
     assert calculate_sleep_amount(1) == (-59, 60, True)
     assert calculate_sleep_amount(3599) == (3539, 60, True)
     assert calculate_sleep_amount(3600) == (3540, 60, True)
     assert calculate_sleep_amount(0) == (0, 3600, False)
 def test_off_cooldown_10_hours(self):
     Variables.cooldown = False
     assert calculate_sleep_amount(36000) == (36000, 3600, False)
 def test_off_cooldown_less_than_1_hour(self):
     Variables.cooldown = False
     assert calculate_sleep_amount(3599) == (3599, 0, False)
     Variables.cooldown = False
     assert calculate_sleep_amount(1) == (1, 0, False)
 def test_off_cooldown_between_1_and_2_hours(self):
     Variables.cooldown = False
     assert calculate_sleep_amount(3601) == (3600, 1, False)
     Variables.cooldown = False
     assert calculate_sleep_amount(3600) == (3600, 0, False)
 def test_off_cooldown_more_than_2_hours(self):
     Variables.cooldown = False
     assert calculate_sleep_amount(7201) == (7201, 1, False)
     assert calculate_sleep_amount(7200) == (7200, 0, False)
 def test_off_cooldown_no_time(self):
     Variables.cooldown = False
     assert calculate_sleep_amount(-1) == (-1, 3600, False)
     assert calculate_sleep_amount(0) == (0, 3600, False)