示例#1
0
def is_command(message_content):
    shortprefix = dbcommon.get_bot_setting(botcommon.key_bot_prefix, '$')
    if message_content.startswith("<@!" + str(client.user.id) + "> ") or \
            message_content.startswith("<@" + str(client.user.id) + "> ") or \
            message_content.startswith(shortprefix):
        return True
    return False
示例#2
0
async def _do_specific_help(message, arg_stack, botuser):
    shortprefix = dbcommon.get_bot_setting(botcommon.key_bot_prefix, "$")
    try:
        cmdimport = importlib.import_module(
            '.' + arg_stack[1],
            'src.dcbot.commands')
    except ModuleNotFoundError:
        # TODO: Translate this
        await message.channel.send("Command not found")
        return False
    else:
        try:
            if botuser.user_permission_level >= \
                    cmdimport.CMD_METADATA['required_permlevel']:
                cmdhelp = await cmdimport.get_help(
                    arg_stack, botuser, shortprefix)
                if cmdhelp is None or cmdhelp == []:
                    await message.channel.send(
                        "This command does not implement help functions.")
                    return False
                for embed in cmdhelp:
                    await message.channel.send(embed=embed)
            else:
                await message.channel.send(
                    "You have no permission to get help for this command.")
                return True
        except Exception:
            await message.channel.send(
                "This command has no function to print help.")
            return False
        return True
    return False
示例#3
0
def get_processed_argstack(message):
    shortprefix = dbcommon.get_bot_setting(botcommon.key_bot_prefix, '$')
    fullstring = "<<Error!>>"
    if message.startswith("<@!" + str(client.user.id) + ">") or \
            message.startswith("<@" + str(client.user.id) + ">"):
        fullstring = " ".join(message.split(" ")[1:])
    elif message.startswith(shortprefix):
        fullstring = message[1:]
    argstack = stavlexer.get_argv(fullstring)
    return argstack
示例#4
0
async def _log_action(message, arg_stack, botuser):
    newprefix = dbcommon.get_bot_setting(botcommon.key_bot_prefix, '$')
    embed = Embed(
        title="New command prefix set",
        description="`" + newprefix + "` is now the new "
                    "short prefix for commands.",
        color=botcommon.key_color_warning)
    footertext = "Requested by " + str(message.author.name) + "#" \
        + str(message.author.discriminator) + " (" \
        + str(message.author.id) + ")"
    embed.set_footer(text=footertext)
    await botcommon.trytolog(message, arg_stack, botuser, embed)
示例#5
0
async def send_init_help(channel_obj, botuser):
    shortprefix = dbcommon.get_bot_setting(botcommon.key_bot_prefix, "$")
    tc = client.get_channel(channel_obj['textchannel'])
    embed = Embed(title=transget("event.voice.inithelp.embed.title",
                                 botuser.user_pref_lang),
                  description=transget(
                      "event.voice.inithelp.embed.description",
                      botuser.user_pref_lang),
                  color=botcommon.key_color_info)
    embed.add_field(
        name='`' + shortprefix +
        transget("command.voice.help.toggle.syntax", botuser.user_pref_lang) +
        '`',
        value=transget("command.voice.help.toggle.description",
                       botuser.user_pref_lang))
    embed.add_field(
        name='`' + shortprefix +
        transget("command.voice.help.name.syntax", botuser.user_pref_lang) +
        '`',
        value=transget("command.voice.help.name.description",
                       botuser.user_pref_lang))
    embed.add_field(name='`' + shortprefix + transget(
        "command.voice.help.transfer.syntax", botuser.user_pref_lang) + '`',
                    value=transget("command.voice.help.transfer.description",
                                   botuser.user_pref_lang))
    embed.add_field(
        name='`' + shortprefix +
        transget("command.voice.help.invite.syntax", botuser.user_pref_lang) +
        '`',
        value=transget("command.voice.help.invite.description",
                       botuser.user_pref_lang))
    embed.add_field(
        name='`' + shortprefix +
        transget("command.voice.help.kick.syntax", botuser.user_pref_lang) +
        '`',
        value=transget("command.voice.help.kick.description",
                       botuser.user_pref_lang))
    embed.add_field(
        name='`' + shortprefix +
        transget("command.voice.help.close.syntax", botuser.user_pref_lang) +
        '`',
        value=transget("command.voice.help.close.description",
                       botuser.user_pref_lang))
    embed.add_field(name=transget("event.voice.inithelp.embed.more_info.title",
                                  botuser.user_pref_lang),
                    value=transget(
                        "event.voice.inithelp.embed.more_info.value",
                        botuser.user_pref_lang))
    await tc.send(embed=embed)
示例#6
0
async def _send_application(embed):
    destchannel_id = dbcommon.get_bot_setting(
        botcommon.key_bot_applydestchannel, 0)
    try:
        destchannel = await client.fetch_channel(destchannel_id)
    except Exception:
        return False
    else:
        if destchannel is None:
            return False
        else:
            message = await destchannel.send(embed=embed)
            await message.add_reaction("✅")
            await message.add_reaction("❌")
            return True
示例#7
0
async def on_message(message):

    if botcommon.is_bot_stopping is True:
        return

    if message.author == client.user:
        return
    cmd_arg_stack = get_processed_argstack(message.content)

    init_stage = int(dbcommon.get_bot_setting(botcommon.key_bot_init_stage, 0))
    if init_stage <= DD_MAX_INIT_STAGE:
        await on_message_init_mode(message, cmd_arg_stack, init_stage)
    elif is_command(message.content):
        await on_message_command_mode(message, cmd_arg_stack)
    else:
        await on_process_message_mode(message)
示例#8
0
async def _do_general_help(message, arg_stack, botuser):
    shortprefix = dbcommon.get_bot_setting(botcommon.key_bot_prefix, "$")
    helpmsg = transget(
        'command.help.general_help.header',
        botuser.user_pref_lang).format(
            shortprefix=shortprefix) + "\n```md\n"
    for command in botcommon.registered_bot_commands:
        cmdimport = importlib.import_module(
            '.' + command,
            'src.dcbot.commands')
        cmdmeta = cmdimport.CMD_METADATA
        if botuser.user_permission_level >= cmdmeta['required_permlevel']:
            helpmsg += "<" + command + "> " + transget(
                'command.' + command + '.meta.description',
                botuser.user_pref_lang) + "\n"
    helpmsg += "```"
    await message.channel.send(helpmsg)
    return True
示例#9
0
async def trytolog(message, arg_stack, botuser, embed):
    logchannel_id = dbcommon.get_bot_setting(key_bot_logchannel, 0)
    try:
        logchannel = await client.fetch_channel(logchannel_id)
    except Exception:
        await message.channel.send(
            transget('dcbot.log.error.channel', botuser.user_pref_lang))
        await message.channel.send(embed=embed)
        return
    else:
        if logchannel is None:
            await message.channel.send(
                transget('dcbot.log.error.channel', botuser.user_pref_lang))
            await message.channel.send(embed=embed)
            return
        else:
            await logchannel.send(embed=embed)
            return
示例#10
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)
示例#11
0
async def on_voice_state_update(member, before, after):

    # If bot is currently shutting down, don't do anything at all.
    if botcommon.is_bot_stopping:
        return

    botuser = dbcommon.get_user_or_create(member.id)

    cid_new_publicvoice = int(
        dbcommon.get_bot_setting(botcommon.key_bot_newpublicvoicechannel))
    cid_new_privatevoice = int(
        dbcommon.get_bot_setting(botcommon.key_bot_newprivatevoicechannel))

    if botcommon.is_bot_stopping is True:
        return

    # When new channel is the "Create new Public Talk" channel
    if after.channel is not None and after.channel.id == cid_new_publicvoice:
        channel_obj = await new_voice.create_public(member, before, after)
        botcommon.bot_voice_channels.append(channel_obj)
        try:
            await voicecommon.move_to(member, channel_obj)
        except Exception:
            await voicecommon.delete_channel(channel_obj)
        await voicecommon.send_init_help(channel_obj, botuser)

    # When new channel is the "Create new Private Talk" channel
    if after.channel is not None and after.channel.id == cid_new_privatevoice:
        channel_obj = await new_voice.create_private(member, before, after)
        botcommon.bot_voice_channels.append(channel_obj)
        role = botcommon.main_guild.get_role(channel_obj['role'])
        await member.add_roles(role)
        try:
            await voicecommon.move_to(member, channel_obj)
        except Exception:
            await voicecommon.delete_channel(channel_obj)
        await voicecommon.send_init_help(channel_obj, botuser)

    # When old channel is dynamic
    if voicecommon.get_channel_obj_by_channel(before.channel) is not None \
            and after.channel != before.channel:
        channel_obj = voicecommon.get_channel_obj_by_channel(before.channel)
        if channel_obj['type'] == "public":
            # Only take away role when channel is public.
            # Roles for private channels are taken away by commands only.
            role = botcommon.main_guild.get_role(channel_obj['role'])
            await member.remove_roles(role)
        # Remove channel if it is empty now
        vc = await client.fetch_channel(channel_obj['voicechannel'])
        if len(vc.members) == 0:
            await voicecommon.delete_channel(channel_obj)

    # Check if new channel is dynamic
    if voicecommon.get_channel_obj_by_channel(after.channel) is not None \
            and before.channel != after.channel:
        channel_obj = voicecommon.get_channel_obj_by_channel(after.channel)
        if channel_obj['type'] == "public":
            # Only give role when channel is public.
            # Roles for private channels are given by commands only.
            role = botcommon.main_guild.get_role(channel_obj['role'])
            await member.add_roles(role)
示例#12
0
async def invoke(message, arg_stack, botuser):
    embed = Embed(
        title=transget(
            'command.info.embed.title',
            botuser.user_pref_lang).format(
                bot_title=transget(
                    'bot.title',
                    botuser.user_pref_lang)),
        description=transget(
            'command.info.embed.desc',
            botuser.user_pref_lang),
        color=0xdfdfdf)

    embed.set_thumbnail(
        url=str(client.user.avatar_url))

    embed.add_field(
        name=transget(
            'dcbot.features.title',
            botuser.user_pref_lang),
        value=transget(
            'dcbot.features.features',
            botuser.user_pref_lang),
        inline=False)

    embed.add_field(
        name=transget(
            'command.info.embed.field.author.title',
            botuser.user_pref_lang),
        value="<@285720078031388673>",
        inline=True)

    embed.add_field(
        name=transget(
            'dcbot.contributor.title',
            botuser.user_pref_lang),
        value=transget(
            'dcbot.contributor.contributors',
            botuser.user_pref_lang),
        inline=True)

    versiontag = os.popen('git describe --tags --abbrev=0').read().rstrip('\n')
    versioncommit = os.popen('git rev-parse --short HEAD').read().rstrip('\n')

    versionstring = str(versiontag) + " (" + str(versioncommit) + ")"

    embed.add_field(
        name=transget(
            'command.info.embed.field.version.title',
            botuser.user_pref_lang),
        value=versionstring,
        inline=True)

    embed.add_field(
        name=transget(
            'command.info.embed.field.upstream.title',
            botuser.user_pref_lang),
        value=transget(
            'command.info.embed.field.upstream.value',
            botuser.user_pref_lang),
        inline=False)

    embed.add_field(
        name=transget(
            'command.info.embed.field.prefix.title',
            botuser.user_pref_lang),
        value=transget(
            'command.info.embed.field.prefix.value',
            botuser.user_pref_lang).format(
            longprefix="<@" + str(client.user.id) + ">",
            shortprefix=dbcommon.get_bot_setting(
                botcommon.key_bot_prefix,
                '$'
            )
        ),
        inline=True)

    embed.add_field(
        name=transget(
            'command.info.embed.field.bugreports.title',
            botuser.user_pref_lang),
        value=transget(
            'command.info.embed.field.bugreports.value',
            botuser.user_pref_lang),
        inline=False)

    footertext = "Requested by " + str(message.author.name) + "#" \
        + str(message.author.discriminator) + " (" \
        + str(message.author.id) + ")"
    embed.set_footer(text=footertext)

    await message.channel.send(embed=embed)