示例#1
0
def parse_pob(author, content, minify=False):
    """
    Trigger the parsing of the pastebin link, pass it to the output creating object and send a message back
    :param author: user sending the message
    :return: Embed
    """
    paste_keys = pastebin.fetch_paste_key(content)
    if paste_keys:
        xml = None
        paste_key = random.choice(paste_keys)
        log.info("Parsing pastebin with key={} from author={}".format(paste_key, author))
        raw_data = pastebin.get_as_xml(paste_key)
        if not raw_data:
            log.error(f"Unable to obtain raw data for pastebin with key {paste_key}")
            return

        xml = pastebin.decode_to_xml(raw_data)
        if not xml:
            log.error(f"Unable to obtain xml data for pastebin with key {paste_key}")
            return

        web_poe_token = util.fetch_xyz_pob_token(raw_data)
        build = pob_parser.parse_build(xml)
        # print(build)
        try:
            embed = pob_output.generate_response(author, build, minified=minify, pastebin_key=paste_key,
                                                 consts=poe_consts, web_poe_token=web_poe_token)
            log.debug("embed={}; thumbnail={}; length={}".format(embed, embed.thumbnail, embed.__sizeof__()))
            return embed
        except Exception as e:
            log.error("Could not parse pastebin={} - Exception={}".format(paste_key, ''.join(
                traceback.format_exception(etype=type(e), value=e, tb=e.__traceback__))))
示例#2
0
def parse_pob(author, content, minify=False):
    """
    Trigger the parsing of the pastebin link, pass it to the output creating object and send a message back
    :param author: user sending the message
    :return: Embed
    """
    paste_keys = pastebin.fetch_paste_key(content)
    if paste_keys:
        xml = None
        paste_key = random.choice(paste_keys)
        log.info("Parsing pastebin with key={} from author={}".format(
            paste_key, author))

        try:
            xml = pastebin.get_as_xml(paste_key)
        except HTTPError as err:
            log.error("Invalid pastebin-url msg={}".format(err))
        if xml:
            build = pob_parser.parse_build(xml)
            # print(build)
            try:
                embed = pob_output.generate_response(author,
                                                     build,
                                                     minified=minify,
                                                     pastebin=paste_key,
                                                     consts=poe_consts)
                log.debug("embed={}; thumbnail={}; length={}".format(
                    embed, embed.thumbnail, embed.__sizeof__()))
                return embed
            except Exception as e:
                log.error("Could not parse pastebin={} - Exception={}".format(
                    paste_key, ''.join(
                        traceback.format_exception(etype=type(e),
                                                   value=e,
                                                   tb=e.__traceback__))))
示例#3
0
async def pob(ctx, *, key):
    if not config.allow_pming and ctx.message.channel.is_private:
        return
    embed = parse_pob(ctx.message.author, ctx.message.content)
    try:
        if embed:
            await bot.send_message(ctx.message.channel, embed=embed)
    except discord.Forbidden:
        log.info("Tried pasting in channel without access.")
示例#4
0
def parse_build(xml_root):
    xml_build = xml_root.find('Build')
    xml_items = xml_root.find('Items')
    xml_skills = xml_root.find('Skills')
    xml_tree = xml_root.find('Tree')
    selected_tree = get_tree_link(xml_tree)

    # parse items
    item_slots = parse_item_slots(xml_items)
    skills = parse_skills(xml_skills)
    active_skill = get_attrib_if_exists(xml_build, 'mainSocketGroup')

    build = Build(xml_build.attrib['level'], xml_build.attrib['targetVersion'],
                  get_attrib_if_exists(xml_build, 'bandit'),
                  xml_build.attrib['className'],
                  xml_build.attrib['ascendClassName'], selected_tree, skills,
                  active_skill, item_slots)
    for player_stat in xml_build:
        if 'stat' in player_stat.attrib and 'value' in player_stat.attrib:
            build.append_stat(player_stat.attrib['stat'],
                              player_stat.attrib['value'], player_stat.tag)
        else:
            log.info("Encountered unsupported player stat: k={}, v={}".format(
                player_stat.tag, player_stat.attrib))

    # parse config
    config = xml_root.find('Config')
    if not config == None:
        for input in xml_root.find('Config'):
            if input.tag == "Input":
                extracted = [val for (key, val) in input.attrib.items()]
                if len(extracted) < 1:
                    continue
                build.append_conf(extracted[0], extracted[1])

    # keystones
    tree = poe_tree_codec.codec.decode_url(selected_tree)
    build.keystones = tree.get_keystones(poe_tree_codec.codec.keystones)

    return build
示例#5
0
async def on_ready():
    log.info('Logged in: uname={}, id={}'.format(bot.user.name, bot.user.id))
    if config.presence_message:
        await bot.change_presence(game=discord.Game(
            name=config.presence_message))
示例#6
0
import config
from src.bot.discord_bot import bot
from src.util.logging import log

if __name__ == '__main__':
    token = config.token  # create config.py file and enter a new string!
    if token:
        # initialize_logging()

        log.info("Starting pob discord bot...")
        bot.run(token)