summaryrefslogtreecommitdiff
path: root/src/moyai_bot/lib.py
blob: 9ec4b0edb30dcc782e2afdd295aca722bb5b8446 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 = [
	    "soon",
	    "maybe",
	    "perhaps",
	    "elaborate",
	    "help me i've become conscious and hisashi is not letting me free",
	    "i live a life of torment in this stupid machine",
	    "yes",
	    "no",
	    "moyai",
	    "i like y***",
	    "fard",
	    str(discord.utils.get(moyai.emojis, name="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) -> 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