async def cmd_edit_timer(msg: Message, *args):
    if len(args) < 3:
        raise InvalidArgumentsException()

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

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

    mode = args[1].lower()

    if mode not in ('msg', 'interval'):
        raise InvalidArgumentsException()

    if mode == 'interval':
        try:
            interval = int(args[2])
        except ValueError:
            raise InvalidArgumentsException()

        set_message_timer_interval(msg.channel_name, name, interval)
        restart_message_timer(msg.channel_name, name)

        return await msg.reply(f'updated timer interval for "{name}"')

    elif mode == 'msg':
        value = ' '.join(args[2:])

        set_message_timer_message(msg.channel_name, name, value)
        restart_message_timer(msg.channel_name, name)

        return await msg.reply(f'updated timer message for "{name}"')
Esempio n. 2
0
async def cmd_quote_add(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    optionals = ' '.join(args[1:])

    user = alias = None
    if 'user='******'user=(\w+)', msg.content)
        if not m:
            await msg.reply('invalid user')
            return

        user = m.group(1)

    if 'alias=' in optionals:
        m = re.search('alias=(\w+)', msg.content)
        if not m:
            await msg.reply('invalid alias')
            return

        alias = m.group(1)
        if get_quote_by_alias(msg.channel_name, alias) is not None:
            await msg.reply('there is already a quote with that alias')
            return

    if add_quote(Quote.create(channel=msg.channel_name, value=args[0], user=user, alias=alias)):
        resp = 'successfully added quote'
    else:
        resp = 'failed to add quote, already exist'

    await msg.reply(resp)
async def cmd_give(msg: Message, *args):
    if len(args) != 2:
        raise InvalidArgumentsException()

    if args[0] not in msg.channel.chatters:
        await msg.reply(msg=f'no viewer found by the name "{args[0]}"')
        return

    caller = get_balance_from_msg(msg)
    target = get_balance(msg.channel_name, args[0])

    try:
        give = int(args[1])
    except ValueError:
        await msg.reply('invalid give amount')
        return

    cur_name = get_currency_name(msg.channel_name).name

    if caller.balance < give:
        await msg.reply(f"@{msg.author} you don't have enough {cur_name}")
        return

    caller.balance -= give
    target.balance += give

    session.commit()

    await msg.reply(
        f"@{msg.author} you gave @{args[0]} {give} {cur_name}, @{args[0]}'s balance is now {target.balance}"
    )
async def cmd_set_currency_name(msg: Message, *args):
    if len(args) != 1:
        raise InvalidArgumentsException()

    set_currency_name(msg.channel_name, args[0])

    await msg.reply(
        f"this channel's currency name is now \"{get_currency_name(msg.channel_name).name}\""
    )
Esempio n. 5
0
async def cmd_get_quote(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    quote = get_quote(msg.channel_name, args[0])
    if quote is None:
        await msg.reply(f'no quote found')
        return

    await msg.reply(f'"{quote.value}" user: {quote.user} alias: {quote.alias}')
async def cmd_get_custom_command(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    cmd = get_custom_command(msg.channel_name, args[0].lower())
    if cmd is None:
        await msg.reply('no command found')
        return

    await msg.reply(f'the response for "{cmd.name}" is "{cmd.response}"')
async def cmd_del_group(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    group = args[0]
    if perms.delete_group(msg.channel_name, group):
        await msg.reply(whisper=WHISPER,
                        msg=f'deleted permission group "{group}"')
    else:
        await msg.reply(whisper=WHISPER,
                        msg=f'no group found by the "{group}"')
async def cmd_add_group(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    group = args[0]
    if perms.add_group(msg.channel_name, group):
        await msg.reply(whisper=WHISPER,
                        msg=f'added permission group "{group}"')
    else:
        await msg.reply(whisper=WHISPER,
                        msg=f'permission group "{group}" already exist')
async def cmd_del_perm(msg: Message, *args):
    if len(args) != 2:
        raise InvalidArgumentsException()

    group, perm = args
    if perms.delete_permission(msg.channel_name, group, perm):
        await msg.reply(whisper=WHISPER,
                        msg=f'deleted permission "{perm}" from "{group}"')
    else:
        await msg.reply(whisper=WHISPER,
                        msg=f'no group found by the "{group}"')
Esempio n. 10
0
async def cmd_del_quote(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    quote = get_quote(msg.channel_name, args[0])
    if quote is None:
        await msg.reply(f'no quote found')
        return

    delete_quote_by_id(msg.channel_name, quote.id)

    await msg.reply(f'successfully deleted quote, id: {quote.id}, alias: {quote.alias}')
async def cmd_add_custom_command(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    cmd = get_custom_command(msg.channel_name, args[0].lower())
    if cmd is None:
        await msg.reply('no command found')
        return

    if delete_custom_command(msg.channel_name, cmd.name):
        await msg.reply(f'successfully deleted command {cmd.name}')
    else:
        await msg.reply(f'failed to delete command {cmd.name}')
async def cmd_add_member(msg: Message, *args):
    if len(args) != 2:
        raise InvalidArgumentsException()

    group, member = args

    if member.startswith('@'):
        member = member[1:]

    if perms.add_member(msg.channel_name, group, member):
        await msg.reply(whisper=WHISPER, msg=f'added "{member}" to "{group}"')
    else:
        await msg.reply(whisper=WHISPER,
                        msg=f'failed to add member, group does not exist')
async def cmd_del_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}"')

    if delete_message_timer(msg.channel_name, name):
        await msg.reply(f'successfully deleted timer "{name}"')
    else:
        await msg.reply(f'failed to delete timer "{name}"')
async def cmd_enable_cmd(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    name = args[0].lower()

    if not get_command(name):
        return await msg.reply(
            f'no command found for "{name}", are you missing the prefix?')

    if not is_command_disabled(msg.channel_name, name):
        return await msg.reply(f'{name} is not disabled')

    enable_command(msg.channel_name, name)

    await msg.reply(f'enabled command "{name}"')
async def cmd_del_member(msg: Message, *args):
    if len(args) != 2:
        raise InvalidArgumentsException()

    group, member = args

    if member.startswith('@'):
        member = member[1:]

    if perms.delete_member(msg.channel_name, group, member):
        await msg.reply(whisper=WHISPER,
                        msg=f'removed "{member}" from "{group}"')
        return

    g = perms.get_group(msg.channel_name, group)
    await msg.reply(whisper=WHISPER,
                    msg='failed to remove member, group does not exist'
                    if not g else f'"{member}" is not in that group')
async def cmd_add_timer(msg: Message, *args):
    if len(args) < 3:
        raise InvalidArgumentsException()

    valid, interval = await _parse_interval(msg, args[1])
    if not valid:
        return

    timer_msg = ' '.join(args[2:])
    timer_name = args[0].lower()

    if message_timer_exist(msg.channel_name, timer_name):
        await msg.reply(f'a timer already exist by the name of "{timer_name}"')
        return

    set_message_timer(msg.channel_name, timer_name, timer_msg, interval)

    await msg.reply(f'created timer successfully')
async def cmd_add_custom_command(msg: Message, *args):
    if len(args) < 2:
        raise InvalidArgumentsException()

    name, resp = args[0], ' '.join(args[1:])
    name = name.lower()

    if not await _verify_resp_text(msg, resp):
        return

    if custom_command_exist(msg.channel_name, name):
        await msg.reply('custom command already exist by that name')
        return

    if add_custom_command(CustomCommand.create(msg.channel_name, name, resp)):
        await msg.reply('successfully added command')
    else:
        await msg.reply('failed to add command')
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 cmd_gamble(msg: Message, *args):
    if len(args) != 2:
        raise InvalidArgumentsException()

    try:
        sides = int(args[0])
        bet = int(args[1])
    except ValueError:
        await msg.reply(f'invalid value for sides or bet')
        return

    if bet < 10:
        await msg.reply('bet cannot be less then 10')
        return

    elif sides < 2:
        await msg.reply('sides cannot be less than 2')
        return

    bal = get_balance_from_msg(msg)
    if bal.balance < bet:
        await msg.reply(
            f"you don't have enough {get_currency_name(msg.channel_name).name}"
        )
        return

    n = randbelow(sides) + 1
    cur_name = get_currency_name(msg.channel_name).name

    if n == 1:
        if sides >= 6:
            bet *= 2
        gain = bet + int(bet * (sides / 6))
        bal.balance += gain
        await msg.reply(f'you rolled {n} and won {gain} {cur_name}')

    else:
        bal.balance -= bet
        await msg.reply(f'you rolled {n} and lost your bet of {bet} {cur_name}'
                        )

    session.commit()
async def cmd_update_custom_command(msg: Message, *args):
    if len(args) < 2:
        raise InvalidArgumentsException()

    name, resp = args[0], ' '.join(args[1:])
    name = name.lower()

    if not await _verify_resp_text(msg, resp):
        return

    cmd = get_custom_command(msg.channel_name, name)

    if cmd is None:
        await msg.reply(f'custom command {name} does not exist')
        return

    cmd.response = resp
    session.commit()

    await msg.reply(f'successfully updated {cmd.name}')
async def cmd_set_bal(msg: Message, *args):
    if not len(args):
        raise InvalidArgumentsException()

    elif len(args) == 2:
        target = args[1]

        if target not in msg.channel.chatters:
            await msg.reply(msg=f'no viewer found by the name of "{args[1]}"')
            return
    else:
        target = msg.author

    try:
        set_balance(msg.channel_name, target, int(args[0]))
    except ValueError:
        await msg.reply(f'invalid target balance: {args[0]}')
        return

    await msg.reply(f'@{target} now has {args[0]} '
                    f'{get_currency_name(msg.channel_name).name}')
async def cmd_color(msg: Message, *args):
    if not args:
        raise InvalidArgumentsException()

    await msg.channel.color(args[0])
    await msg.reply(f'set color to {args[0]}')
async def cmd_choose(msg: Message, *args):
    if len(args) < 2:
        raise InvalidArgumentsException()

    await msg.reply(f'result: {choice(args)}')