summaryrefslogtreecommitdiff
path: root/src/teawie_bot/utils.py
diff options
context:
space:
mode:
authorseth <[email protected]>2023-01-24 18:28:18 -0500
committerseth <[email protected]>2023-01-24 22:03:37 -0500
commit5deaf0cc1580e13c48f3dbc7ff4c76d35640fcfc (patch)
tree5c015a1a43bb6fc79c5ec4e264111abc006c8dd4 /src/teawie_bot/utils.py
parent95961b27a88230a22a74ae9de6cdd60d3beda95d (diff)
feat: moyaiBot -> teawieBot
Diffstat (limited to 'src/teawie_bot/utils.py')
-rw-r--r--src/teawie_bot/utils.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/teawie_bot/utils.py b/src/teawie_bot/utils.py
new file mode 100644
index 0000000..99f2a13
--- /dev/null
+++ b/src/teawie_bot/utils.py
@@ -0,0 +1,69 @@
+import importlib.resources
+import random
+from math import ceil
+
+from discord.ext import commands
+import discord
+
+from teawie_bot import copypastas
+
+CHAR_LIMIT: int = 2000
+
+
+class Teawies:
+ """
+ wrapper class around list[discord.Emoji]
+ """
+
+ def __init__(self, bot: commands.Bot):
+ names = [
+ "teawiecry", "teawiederp", "teawiedizzy",
+ "teawienerdcroppedanddownsized", "teawieneutral", "teawiepet",
+ "teawiepetfast", "teawiepop", "teawiesmile", "teawiesmug",
+ "teawiestarstruck", "tei", "wavy", "wie", "wie~1",
+ "manythoughtsheadfull"
+ ]
+
+ self.emojis: list[str] = []
+ for name in names:
+ emoji = discord.utils.get(bot.emojis, name=name)
+ if emoji:
+ self.emojis.append(str(emoji))
+
+ def random(self) -> str:
+ return random.choice(self.emojis)
+
+
+def get_random_response(bot: commands.Bot, teawies: Teawies) -> str:
+ responses = [
+ "soon", "maybe", "perhaps", "elaborate",
+ str(discord.utils.get(bot.emojis, name="moyai")),
+ ]
+ responses = responses + teawies.emojis
+ return random.choice(responses)
+
+
+def split_msg(msg: str) -> list[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: str) -> list[str]:
+ try:
+ res = importlib.resources.read_text(copypastas, name + ".txt")
+ except OSError:
+ 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