Exemple #1
0
async def pageify_and_send(ctx, strings,
						   cog_config=None, has_link=False,
						   max_len=1900, page_limit_dm=99, page_limit_server=2, code="py",
						   prefix="", suffix="",):

	# inits
	bot_config= utils.load_bot_config()
	gist_link= get_gist_link(bot_config)

	if has_link:
		_code=None
	else:
		_code=code

	# group strings into pages
	if prefix:
		strings[0]= prefix + strings[0]
	if suffix:
		strings[-1]+= suffix
	pages= Pprint.get_pages(strings, max_len=max_len)

	# send pages
	await send_pages(ctx, pages, has_link=has_link, code=_code,
					 page_limit_dm=cog_config['page_limit_dm'] if cog_config else page_limit_dm,
					 page_limit_server=cog_config['page_limit_server'] if cog_config else page_limit_server,
					 gist_link=gist_link)

	# update gist
	if gist_link:
		dump= "\n".join(strings)
		if _code:
			dump= f"```{code}\n{dump}\n```"

		await update_data_gist(dump, bot_config)
Exemple #2
0
    async def scan_equip(self, ctx):
        matches = self.get_matches(ctx.message.content, "equip")
        has_failed = False

        msgs = []
        for x in matches:
            await ctx.trigger_typing()
            has_excl, isekai, equip_id, equip_key = x

            # try parsing, add reaction to original message on fail
            try:
                t = await preview_utils.parse_equip_match(equip_id=equip_id,
                                                          equip_key=equip_key,
                                                          level=len(has_excl),
                                                          isekai=bool(isekai),
                                                          session=self.session)
            except Exception as e:
                CONFIG = utils.load_yaml(utils.PREVIEW_CONFIG)
                traceback.print_tb(e.__traceback__)

                if not has_failed:
                    await ctx.message.add_reaction(
                        CONFIG['fail_reaction_emote'])
                    has_failed = True
                    continue

            msgs.append(t)

        texts = [
            f"```py\n{x.strip()}\n```" for x in msgs if isinstance(x, str)
        ]
        embeds = [x for x in msgs if isinstance(x, discord.Embed)]

        sent = []
        for x in get_pages("".join(texts), no_orphan=10, join_char="\n"):
            if x:
                sent.append(await ctx.send(x))

        for x in embeds:
            sent.append(await ctx.send(embed=x))

        self.bot.track(ctx.message, sent, post_func=self.on_message)
Exemple #3
0
def _clean_body(body, CONFIG=None):
    if CONFIG is None:
        CONFIG = utils.load_yaml(utils.PREVIEW_CONFIG)

    # limit preview length
    tmp = [x.strip() for x in body.split("\n")]
    pages = get_pages(tmp,
                      max_len=CONFIG['max_body_length'],
                      no_orphan=0,
                      join_char="\n\n")
    body = pages[0]

    split = body.split("\n")
    body = "\n".join(split[:CONFIG['max_body_lines']])
    if len(pages) > 1 or len(split) > CONFIG['max_body_lines']:
        body += "\n\n[...]"

    # clean up
    while "\n\n\n" in body:
        body = body.replace("\n\n\n", "\n\n")

    return body