~nova/fletcher

58d620c721649a65d858d6d6ea02c70c73185b1b — Novalinium a month ago e357030
SCP Auto-preview
2 files changed, 22 insertions(+), 10 deletions(-)

M messagefuncs.py
M swag.py
M messagefuncs.py => messagefuncs.py +10 -3
@@ 234,7 234,7 @@ async def teleport_function(message, client, args):

extract_links = re.compile("(?<!<)((https?|ftp):\/\/|www\.)(\w.+\w\W?)", re.IGNORECASE)
extract_previewable_link = re.compile(
    "(?<!<)(https?://www1.flightrising.com/(?:dgen/preview/dragon|dgen/dressing-room/scry|scrying/predict)\?[^ ]+|https?://todo.sr.ht/~nova/fletcher/\d+|https?://vine.co/v/\w+|https?://www.azlyrics.com/lyrics/.*.html)",
        "(?<!<)(https?://www1.flightrising.com/(?:dgen/preview/dragon|dgen/dressing-room/scry|scrying/predict)\?[^ ]+|https?://todo.sr.ht/~nova/fletcher/\d+|https?://vine.co/v/\w+|https?://www.azlyrics.com/lyrics/.*.html|https?://www.scpwiki.com[^ ]*)",
    re.IGNORECASE,
)



@@ 272,7 272,7 @@ async def preview_messagelink_function(message, client, args):
                )
                return
            channel = guild.get_channel(channel_id)
            target_message = await channel.fetch_message(message_id)
            target_message = await channel.fetch_message_fast(message_id)
            # created_at is naîve, but specified as UTC by Discord API docs
            sent_at = target_message.created_at.strftime("%B %d, %Y %I:%M%p UTC")
            content = target_message.content


@@ 369,6 369,13 @@ async def preview_messagelink_function(message, client, args):
                content = await swag.azlyrics_function(
                    message, client, [previewable_parts[0], "INTPROC"],
                )
            elif "scpwiki.com" in previewable_parts[0]:
                import swag

                embed = await swag.scp_function(
                    message, client, [previewable_parts[0], "INTPROC"],
                )
                content = "SCP Preview"
        # TODO 🔭 to preview?
        if content:
            return await sendWrappedMessage(


@@ 390,7 397,7 @@ async def messagelink_function(message, client, args):
        msg = None
        for channel in message.channel.guild.text_channels:
            try:
                msg = await channel.fetch_message(int(args[0]))
                msg = await channel.fetch_message_fast(int(args[0]))
                break
            except discord.Forbidden as e:
                pass

M swag.py => swag.py +12 -7
@@ 705,15 705,17 @@ async def scp_function(message, client, args):
        elif len(args):
            url = "http://www.scpwiki.com/" + "-".join(args).lower()
        else:
            await message.channel.send(
                "Please specify a SCP number from http://www.scpwiki.com/"
            )
            if not (len(args) == 2 and args[1] == "INTPROC"):
                await message.channel.send(
                    "Please specify a SCP number from http://www.scpwiki.com/"
                )
            return
        async with session.get(url) as resp:
            if resp.status != 200:
                await message.channel.send(
                    f"Please specify a SCP number from http://www.scpwiki.com/ (HTTP {resp.status} for {url})"
                )
                if not (len(args) == 2 and args[1] == "INTPROC"):
                    await message.channel.send(
                        f"Please specify a SCP number from http://www.scpwiki.com/ (HTTP {resp.status} for {url})"
                    )
                return
            request_body = (await resp.read()).decode("UTF-8")
            root = html.document_fromstring(request_body)


@@ 783,7 785,10 @@ async def scp_function(message, client, args):
                ),
                inline=True,
            )
            resp = await message.channel.send(embed=embedPreview)
            if len(args) == 2 and args[1] == "INTPROC":
                return embedPreview
            else:
                resp = await message.channel.send(embed=embedPreview)
    except Exception as e:
        exc_type, exc_obj, exc_tb = exc_info()
        logger.error("SCP[{}]: {} {}".format(exc_tb.tb_lineno, type(e).__name__, e))