Ejemplo n.º 1
0
async def remove_user(db: DatabaseManager, context: Context) -> None:
    args = get_command_args(context)

    if len(args) != 1:
        tosend = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.message.channel, tosend, embed_color=0xD81948, embed_name="ERROR")
        return

    tosend = await show.display_remove_user(db, context.guild.id, context.bot, args[0])
    await interrupt(context.message.channel, tosend, embed_color=0xD81D32, embed_name="Remove user")
Ejemplo n.º 2
0
async def diff_with(db: DatabaseManager, context: Context) -> None:
    args = get_command_args(context)

    if len(args) != 1:
        tosend = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.message.channel, tosend, embed_color=0xD81948, embed_name="ERROR")
        return

    pseudo = args[0]
    tosend_list = await show.display_diff_with(db, context.guild.id, context.bot, pseudo)
    await display_by_blocks_diff(context.message.channel, tosend_list, 0xFF00FF)
Ejemplo n.º 3
0
async def diff(context: commands.context.Context) -> None:
    args = get_command_args(context)

    if len(args) != 2:
        to_send = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.channel, to_send, embed_color=0xD81948, embed_name="ERROR")
        return

    pseudo1, pseudo2 = args[0], args[1]
    to_send_list = show.display_diff(context.bot.db, pseudo1, pseudo2)
    await display_by_blocks_diff(context, to_send_list, 0xFF00FF)
Ejemplo n.º 4
0
async def category(db: DatabaseManager, context: Context) -> None:
    lang = await db.get_server_language(context.guild.id)
    args = get_command_args(context)

    if len(args) != 1:
        tosend = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.message.channel, tosend, embed_color=0xD81948, embed_name="ERROR")
        return

    tosend = await show.display_category(lang, args[0])
    embed_name = f"Category {args[0]}"
    await interrupt(context.message.channel, tosend, embed_color=0xB315A8, embed_name=embed_name)
Ejemplo n.º 5
0
async def who_solved(context: commands.context.Context) -> None:
    args = get_command_args(context)
    challenge = ' '.join(args)
    challenge_selected = unescape(challenge.strip())
    if not challenge_selected:
        to_send = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.channel, to_send, embed_color=0xD81948, embed_name="ERROR")
        return

    to_send = show.display_who_solved(context.bot.db, challenge_selected)
    embed_name = f"Who solved {challenge_selected} ?"
    await interrupt(context.channel, to_send, embed_color=0x29C1C5, embed_name=embed_name)
Ejemplo n.º 6
0
async def category(context: commands.context.Context) -> None:
    args = get_command_args(context)
    category_name = ' '.join(args)
    category_name = unescape(category_name.strip())
    if len(args) < 1:
        to_send = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.channel, to_send, embed_color=0xD81948, embed_name="ERROR")
        return

    to_send = show.display_category(context.bot.db, category_name)
    embed_name = f"Category {category_name}"
    await interrupt(context.channel, to_send, embed_color=0xB315A8, embed_name=embed_name)
Ejemplo n.º 7
0
async def lang(db: DatabaseManager, context: Context) -> None:
    args = get_command_args(context)

    if len(args) != 1:
        tosend = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.message.channel, tosend, embed_color=0xD81948, embed_name="ERROR")
        return

    tosend, response = await show.display_lang_check(db, context.guild.id, context.bot, args[0])
    await interrupt(context.message.channel, tosend, embed_color=0x16B841, embed_name="Update lang")
    if response:
        tosend = await show.display_lang(db, context.guild.id, context.bot, args[0])
        await interrupt(context.message.channel, tosend, embed_color=0x16B841, embed_name="Update lang")
Ejemplo n.º 8
0
async def problem(context: commands.context.Context) -> None:
    args = get_command_args(context)
    challenge = ' '.join(args)
    challenge_selected = unescape(challenge.strip())
    if not challenge_selected:
        to_send = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.channel, to_send, embed_color=0xD81948, embed_name="ERROR")
        return

    to_send = show.display_problem(context.bot.db, context, challenge_selected)
    if to_send.startswith('Ping:'):
        await interrupt(context.channel, to_send, embed_color=None, embed_name=None)
    else:
        embed_name = f'Problem with "{challenge_selected}" ?'
        await interrupt(context.channel, to_send, embed_color=0x29C1C5, embed_name=embed_name)
Ejemplo n.º 9
0
async def duration(db: DatabaseManager, context: Context, duration_command: str = 'today',
                   duration_msg: str = 'since last 24h') -> None:
    args = get_command_args(context)

    if len(args) > 1:
        tosend = f'Use !{duration_command} (<username>)'
        await interrupt(context.message.channel, tosend, embed_color=0xD81948, embed_name="ERROR")
        return

    if duration_command == 'week':
        tosend_list = await show.display_week(db, context, args)
    elif duration_command == 'today':
        tosend_list = await show.display_today(db, context, args)
    else:
        return
    await display_by_blocks_duration(context, tosend_list, 0x00C7FF, duration_msg=duration_msg)
Ejemplo n.º 10
0
async def remain(db: DatabaseManager, context: Context) -> None:
    args = get_command_args(context)
    if len(args) < 1 or len(args) > 2:
        tosend = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.message.channel, tosend, embed_color=0xD81948, embed_name="ERROR")
        return

    username = args[0]
    if len(args) == 1:
        embed_name = f"Challenges remaining for {username}"
        tosend = await show.display_remain(db, context.guild.id, context.bot, username)
    else:
        category = args[1]
        embed_name = f"Challenges remaining in {category} for {username}"
        tosend = await show.display_remain(db, context.guild.id, context.bot, username, category=category)

    await interrupt(context.message.channel, tosend, embed_color=0x29C1C5, embed_name=embed_name)
Ejemplo n.º 11
0
async def api_query(context: Context) -> None:
    args = get_command_args(context)

    if len(args) != 1:
        tosend = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.message.channel,
                        tosend,
                        embed_color=0xD81948,
                        embed_name="ERROR")
        return

    tosend = await show.display_api_query(args[0])
    tosend = json.dumps(tosend, indent=4)
    await interrupt(context.message.channel,
                    tosend,
                    embed_color=0xD81D32,
                    embed_name="API custom query")
Ejemplo n.º 12
0
async def recent(context: commands.context.Context) -> None:
    args = get_command_args(context)

    days_num = args[0] if len(args) > 0 else 1

    try:
        days_num = float(days_num)
        if days_num < 0.1:
            raise ValueError('days_num invalid')
    except:
        to_send = f'<number_of_days> is a number >= 0.1.\nUse {context.bot.command_prefix}recent {context.command.help.strip()}'
        await interrupt(context.channel, to_send, embed_color=0xD81948, embed_name="ERROR")
        return

    username = None
    if len(args) == 2:
        username = unescape(args[1]).strip()

    to_send = show.display_recent(context.bot.db, days_num, username)
    await interrupt(context.channel, to_send, 0x00C7FF, embed_name=f'Solves in the last {round(days_num * 24, 2)} hours')
Ejemplo n.º 13
0
async def last_days(context: commands.context.Context) -> None:
    args = get_command_args(context)

    if len(args) < 1 or len(args) > 2:
        to_send = f'Use {context.bot.command_prefix}{context.command} {context.command.help.strip()}'
        await interrupt(context.channel, to_send, embed_color=0xD81948, embed_name="ERROR")
        return

    days_num = args[0]
    if not days_num.isdigit() or int(days_num) < 1:
        to_send = f'<number_of_days> is an integer >= 1.\nUse {context.bot.command_prefix}solved_last_days ' \
            f'{context.command.help.strip()}'
        await interrupt(context.channel, to_send, embed_color=0xD81948, embed_name="ERROR")
        return

    days_num = int(days_num)
    hours = f'{days_num * 24}h'
    username = None
    if len(args) == 2:
        username = unescape(args[1]).strip()

    to_send_list = show.display_last_days(context.bot.db, days_num, username)
    await display_by_blocks_duration(context, to_send_list, 0x00C7FF, duration_msg=f'since last {hours}')