Exemplo n.º 1
0
async def invoke(message, arg_stack, botuser):
    if len(arg_stack) != 3:
        return False
    channel = await botcommon.get_channel_by_id_or_ping(arg_stack[2])
    if channel is None:
        return False

    channelid = channel.id

    channelkey = None

    if arg_stack[1] == "admin":
        channelkey = botcommon.key_bot_adminchannel
    elif arg_stack[1] == "log":
        channelkey = botcommon.key_bot_logchannel
    elif arg_stack[1] == "apply":
        channelkey = botcommon.key_bot_applychannel
    elif arg_stack[1] == "applydest":
        channelkey = botcommon.key_bot_applydestchannel
    elif arg_stack[1] == "voice_newpublic":
        channelkey = botcommon.key_bot_newpublicvoicechannel
    elif arg_stack[1] == "voice_newprivate":
        channelkey = botcommon.key_bot_newprivatevoicechannel
    else:
        await message.channel.send(
            transget('command.chanset.info.unknown_channelkey',
                     botuser.user_pref_lang))
        channelkey = 'bot_' + arg_stack[1] + '_channel'

    dbcommon.set_bot_setting(channelkey, channelid)

    await _log_action(message, arg_stack, botuser, channelkey, channelid)

    return True
Exemplo n.º 2
0
async def invoke(message, arg_stack, botuser):
    if len(arg_stack) == 1:
        return False
    if len(arg_stack) == 2:
        if len(arg_stack[1]) == 1:
            allowed_prefixes = "!§$%&/=?.:#+*|\\"
            if not arg_stack[1] in allowed_prefixes:
                return False
            dbcommon.set_bot_setting(
                botcommon.key_bot_prefix,
                arg_stack[1])
            await _log_action(message, arg_stack, botuser)
            return True
        else:
            return False
Exemplo n.º 3
0
async def invoke(message, arg_stack, botuser):
    if len(arg_stack) == 1:
        return False
    if len(arg_stack) == 2:
        if arg_stack[1].startswith("<#") and arg_stack[1].endswith(">"):
            new_channelid = int(arg_stack[1].lstrip("<#").rstrip(">"))
            channel_list = dbcommon.get_channel_ids_from_key(
                botcommon.key_bot_userchannel)
            channel_list.append(new_channelid)
            channel_list = list(dict.fromkeys(channel_list))
            channelstring = dbcommon.set_channelsetting_value_from_list(
                channel_list)
            dbcommon.set_bot_setting(botcommon.key_bot_userchannel,
                                     channelstring)
            await _log_action(message, arg_stack, botuser)
            return True
        else:
            return False
Exemplo n.º 4
0
async def invoke(message, arg_stack, botuser):
    remove_messages = [message]
    metadata = {'discord_id': message.author.id}

    if len(arg_stack) == 2 and arg_stack[1] == "on" and \
            botuser.user_permission_level >= botcommon.key_permlevel_moderator:
        # TODO: Check if apply command actually can be enabled!
        #       Key bot_gapplydest_channel must be properly set and available!
        dbcommon.set_bot_setting("bot_gapply_enabled", "true")
        # TODO: Log the changing apply state
        return await _success_and_delete(remove_messages)
    if len(arg_stack) == 2 and arg_stack[1] == "off" and \
            botuser.user_permission_level >= botcommon.key_permlevel_moderator:
        dbcommon.set_bot_setting("bot_gapply_enabled", "false")
        # TODO: Log the changing apply state
        return await _success_and_delete(remove_messages)

    if dbcommon.get_bot_setting("bot_gapply_enabled",
                                default="false") == "false":
        remove_messages.append(await message.channel.send(
            transget('command.apply.err.disabled', botuser.user_pref_lang)))
        return await _error_and_delete(remove_messages)

    # Check if command contains no argument (stack size 1)
    # This means no player name was provided
    if len(arg_stack) == 1:

        remove_messages.append(await message.channel.send(
            transget('command.apply.err.noname', botuser.user_pref_lang)))
        return await _error_and_delete(remove_messages)

    # Check if command contains only one argument (stack size 2)
    # This means no profile name was provided
    if len(arg_stack) == 2:
        remove_messages.append(await message.channel.send(
            transget('command.apply.err.noprofile', botuser.user_pref_lang)))
        return await _error_and_delete(remove_messages)

    # Get the player from the Hypixel API
    hypixelplayer = hypixel.getplayer_by_name(arg_stack[1])
    player_uuid = hypixelplayer['player']['uuid']

    metadata['mc_username'] = arg_stack[1]
    metadata['mc_uuid'] = player_uuid

    # Get a personal applicant message, if provided in command
    private_message = None
    if len(arg_stack) > 2:
        private_message = " ".join(arg_stack[3:])

    metadata['private_message'] = private_message

    # Check if the player actually exists
    if hypixelplayer['player'] is None:
        remove_messages.append(await message.channel.send(
            transget('command.apply.err.playernotfound',
                     botuser.user_pref_lang).format(playername=arg_stack[1])))
        return await _error_and_delete(remove_messages)

    # Build the Socialtag for the applying discord user
    actual_dc_tag = message.author.name + "#" + message.author.discriminator

    # Check if the player has linked a discord profile
    if ('socialMedia' not in hypixelplayer['player']) or \
            ('DISCORD' not in
             hypixelplayer['player']['socialMedia']['links']):
        remove_messages.append(await message.channel.send(
            transget(
                'command.apply.err.playernotlinked',
                botuser.user_pref_lang).format(actual_dc_tag=actual_dc_tag)))
        return await _error_and_delete(remove_messages)

    # Get the Socialtag the player provided in the Hypixel API
    api_dc_tag = hypixelplayer['player']['socialMedia']['links']['DISCORD']

    # Check if the player has linked actually his own discord profile
    if api_dc_tag != actual_dc_tag:
        remove_messages.append(await message.channel.send(
            transget('command.apply.err.playerwronglinked',
                     botuser.user_pref_lang).format(
                         api_dc_tag=api_dc_tag, actual_dc_tag=actual_dc_tag)))
        return await _error_and_delete(remove_messages)

    # Check if provided Profile name actually exists
    profile_uuid = None
    for profile in \
            hypixelplayer['player']['stats']['SkyBlock']['profiles'].values():
        if profile['cute_name'].lower() == arg_stack[2].lower():
            profile_uuid = profile['profile_id']

    if profile_uuid is None:
        remove_messages.append(await message.channel.send(
            transget('command.apply.err.profilenotfound',
                     botuser.user_pref_lang).format(profile=arg_stack[2])))
        return await _error_and_delete(remove_messages)

    metadata['profile_name'] = arg_stack[2]
    metadata['profile_uuid'] = profile_uuid
    # Gather profile stats to show if current requirements are met
    profile_data = None
    try:
        profile_data = _get_profile_data(metadata)
    except Exception:
        profile_data = None

    if profile_data is not None:
        metadata['pdata_err'] = False
        metadata['slayer_xp'] = profile_data['data']['slayer_xp']
        metadata['skill_avg'] = profile_data['data']['average_level']
        metadata['alchemy_lvl'] = \
            profile_data['data']['levels']['alchemy']['level']
        metadata['fairy_souls'] = \
            profile_data['data']['fairy_souls']['collected']
    else:
        metadata['pdata_err'] = True

    # Check for HGG Entries
    try:
        hgg_check = hgg.check_hgg_by_uuid(player_uuid)
    except Exception:
        hgg_check = "Error"
    if hgg_check == "Error":
        metadata['hgg_report_count'] = "Error"
    elif hgg_check['found'] is False:
        metadata['hgg_report_count'] = 0
    else:
        metadata['hgg_report_count'] = len(hgg_check['user']['reports'])

    embed = _create_embed(metadata)
    if await _send_application(embed) is False:
        remove_messages.append(await message.channel.send(
            transget('command.apply.err.sendfailure',
                     botuser.user_pref_lang).format(playername=arg_stack[1])))
        return await _error_and_delete(remove_messages)
    return await _success_and_delete(remove_messages)
Exemplo n.º 5
0
async def on_message_init_mode(message, cmd_arg_stack, init_stage):
    if not is_command(message.content):
        return
    if init_stage == 0:
        if cmd_arg_stack[0] == "init":
            newuser = BotUser(
                user_discord_id=message.author.id,
                user_pref_lang=botcommon.default_user_preferred_language,
                user_permission_level=botcommon.key_permlevel_owner)
            sqlsession.add(newuser)
            sqlsession.commit()
            from src.dcbot.commands import chanset
            await chanset.invoke(
                message,
                ['chanset', 'admin', '<#' + str(message.channel.id) + '>'],
                newuser)
            dbcommon.set_bot_setting(botcommon.key_bot_mainserver,
                                     message.guild.id)
            dbcommon.set_bot_setting(botcommon.key_bot_init_stage, 1)
            await message.channel.send(
                transget('init.stage0.successful', newuser.user_pref_lang))
            await message.channel.send(
                transget('init.stage1.intro', newuser.user_pref_lang))

    elif init_stage == 1:
        currentuser = dbcommon.get_user_or_create(message.author.id)
        if cmd_arg_stack[0] == "init":
            await message.channel.send(
                transget('init.stage1.intro', currentuser.user_pref_lang))

        elif cmd_arg_stack[0] == "setprefix":
            from src.dcbot.commands import setprefix
            if await setprefix.invoke(message, cmd_arg_stack, currentuser):
                dbcommon.set_bot_setting(botcommon.key_bot_init_stage, 2)
                await message.channel.send(
                    transget('init.stage1.successful',
                             currentuser.user_pref_lang))
                await message.channel.send(
                    transget('init.stage2.intro', currentuser.user_pref_lang))

    elif init_stage == 2:
        currentuser = dbcommon.get_user_or_create(message.author.id)
        if cmd_arg_stack[0] == "init":
            await message.channel.send(
                transget('init.stage2.intro', currentuser.user_pref_lang))

        elif cmd_arg_stack[0] == "chanset":
            from src.dcbot.commands import chanset
            if await chanset.invoke(message, cmd_arg_stack, currentuser):
                dbcommon.set_bot_setting(botcommon.key_bot_init_stage, 3)
                await message.channel.send(
                    transget('init.stage2.successful',
                             currentuser.user_pref_lang))
                await message.channel.send(
                    transget('init.stage3.intro', currentuser.user_pref_lang))

    elif init_stage == 3:
        currentuser = dbcommon.get_user_or_create(message.author.id)
        if cmd_arg_stack[0] == "init":
            await message.channel.send(
                transget('init.stage3.intro', currentuser.user_pref_lang))

        if cmd_arg_stack[0] == "addcmdchan":
            from src.dcbot.commands import addcmdchan
            if await addcmdchan.invoke(message, cmd_arg_stack, currentuser):
                dbcommon.set_bot_setting(botcommon.key_bot_init_stage, 4)
                await message.channel.send(
                    transget('init.stage3.successful',
                             currentuser.user_pref_lang))
                await message.channel.send(
                    transget('init.completed', currentuser.user_pref_lang))

    elif init_stage == 4:
        pass