Example #1
0
async def cmd_stop_timer(msg: Message, *args):
    if not args:
        raise InvalidArgumentsError(reason='missing required argument', cmd=cmd_stop_timer)

    name = args[0].lower()
    timer = get_message_timer(msg.channel_name, name)

    if not timer:
        raise InvalidArgumentsError(reason=f'no timer was found by "{name}"', cmd=cmd_stop_timer)

    if not timer.running:
        await msg.reply(f'that timer is not running')
        return

    if set_message_timer_active(msg.channel_name, name, False):
        await msg.reply(f'successfully stopped the timer "{name}"')
    else:
        await msg.reply(f'failed to stop the timer "{name}"')
async def cmd_start_timer(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    name = args[0]
    timer = get_message_timer(msg.channel_name, name)

    if not timer:
        await msg.reply(f'no timer was found by "{name}"')
        return

    if not timer.running:
        await msg.reply(f'that timer is not running')
        return

    if set_message_timer_active(msg.channel_name, name, False):
        await msg.reply(f'successfully stopped the timer "{name}"')
    else:
        await msg.reply(f'failed to stop the timer "{name}"')
    async def on_channel_joined(self, channel: Channel):
        timers = get_all_message_timers(channel.name)
        for timer in timers:
            set_message_timer_active(channel.name, timer.name, True)

        print(f'started the following timers for channel "{channel.name}": {", ".join(timer.name for timer in timers)}')