diff options
Diffstat (limited to 'src/moyai_bot')
| -rw-r--r-- | src/moyai_bot/bot.py | 13 | ||||
| -rw-r--r-- | src/moyai_bot/lib.py | 27 |
2 files changed, 32 insertions, 8 deletions
diff --git a/src/moyai_bot/bot.py b/src/moyai_bot/bot.py index 8ba5ac0..f4b2f25 100644 --- a/src/moyai_bot/bot.py +++ b/src/moyai_bot/bot.py @@ -54,8 +54,13 @@ async def moyaispam(ctx: commands.Context): app_commands.Choice(name="happymeal", value="happymeal"), app_commands.Choice(name="ismah", value="ismah"), app_commands.Choice(name="sus", value="sus"), - app_commands.Choice(name="ticktock", value="ticktock") + app_commands.Choice(name="ticktock", value="ticktock"), ]) -async def copypasta(i: discord.Interaction, choices: app_commands.Choice[str]): - msg = get_copypasta(choices.value) - await i.response.send_message(msg) +async def copypasta(interaction: discord.Interaction, + choices: app_commands.Choice[str]): + msgs = get_copypasta(choices.value) + for i, msg in enumerate(msgs): + if i == 0: + await interaction.response.send_message(msg) + else: + await interaction.channel.send(msg) diff --git a/src/moyai_bot/lib.py b/src/moyai_bot/lib.py index 45f2099..65360a1 100644 --- a/src/moyai_bot/lib.py +++ b/src/moyai_bot/lib.py @@ -1,10 +1,13 @@ import importlib.resources import random +from math import ceil import discord from moyai_bot import copypastas +CHAR_LIMIT: int = 2000 + def get_random_response(moyai): responses = [ @@ -24,11 +27,27 @@ def get_random_response(moyai): return random.choice(responses) +def split_msg(msg: str): + """ + splits a message into multiple parts so that it + can fit into the discord character limit + """ + split = ceil(len(msg) / ceil(len(msg) / CHAR_LIMIT)) + return [msg[i:i + split] for i in range(0, len(msg), split)] + + def get_copypasta(name): try: res = importlib.resources.read_text(copypastas, name + ".txt") - if res != "": - return res except OSError: - pass - return f"couldn't send copypasta: {name} :(" + return "something went wrong :(" + + if res == "": + return f"couldn't send copypasta: {name} :(" + + if len(res) >= CHAR_LIMIT: + res = split_msg(res) + else: + res = [res] + + return res |
