-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshared.py
More file actions
115 lines (93 loc) · 3.75 KB
/
shared.py
File metadata and controls
115 lines (93 loc) · 3.75 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import discord
from discord import app_commands
import random
import re
def allowed_everywhere(command):
command = app_commands.allowed_installs(guilds=True, users=True)(command)
command = app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)(command)
return command
catmaid_mode = False
EMOTES = ["nya~", "mew~", ":3", ">w<", "uwu", "*purrs*", "*nuzzles*"]
INSERT_POINTS = [",", ".", "!", "?"]
def catify(text: str | None):
if text is None:
return None
if not catmaid_mode:
return text
# Step 1 — light phonetic modifications
def phonetics(w: str):
# r/l → w
w = re.sub(r"[rl]", "w", w)
w = re.sub(r"[RL]", "W", w)
# "na" "no" "nu" "ne" → nya/nyo/nyu/nye (25% chance each)
if random.random() < 0.25:
w = re.sub(r"\b(n)([aeiou])", r"ny\2", w, flags=re.IGNORECASE)
return w
lines = text.split('\n')
processed_lines = []
for line in lines:
words = line.split()
words = [phonetics(w) for w in words]
new = " ".join(words)
processed_lines.append(new)
new = '\n'.join(processed_lines)
# Step 2 — occasional stutter (10% chance)
if random.random() < 0.10:
new = re.sub(r"\b([a-zA-Z])", r"\1-\1", new, count=1)
# Step 3 — add cute suffix (30% chance)
if random.random() < 0.30:
new += " " + random.choice(EMOTES)
# Step 4 — insert meow/nya at natural pause points (20% chance)
for mark in INSERT_POINTS:
if mark in new and random.random() < 0.20:
new = new.replace(mark, f" {random.choice(EMOTES)}{mark}")
return new
async def send_message(
ctx: discord.InteractionResponse | discord.Webhook,
message: str | None = None,
embed: discord.Embed | None = None,
embeds: list[discord.Embed] | None = None,
view: discord.ui.View | None = None,
allowed_mentions: discord.AllowedMentions | None = None,
file: discord.File | None = None,
files: list[discord.File] | None = None,
ephemeral: bool = False
):
if embed is not None:
embeds = [embed]
if embeds is None:
embeds = []
if catmaid_mode:
if message:
message = catify(message)
if embeds is not None:
for embed in embeds:
if embed.title is not None:
embed.title = catify(embed.title)
if embed.description is not None:
embed.description = catify(embed.description)
for i, field in enumerate(embed.fields):
embed.set_field_at(
i,
name=catify(field.name) if field.name else field.name,
value=catify(field.value) if field.value else field.value,
inline=field.inline,
)
if message is None:
message = ""
if allowed_mentions is None:
allowed_mentions = discord.AllowedMentions.none()
if file is not None:
files = [file]
if files is None:
files = []
if isinstance(ctx, discord.InteractionResponse):
if view is not None:
await ctx.send_message(message, embeds=embeds, files=files, ephemeral=ephemeral, view=view, allowed_mentions=allowed_mentions)
else:
await ctx.send_message(message, embeds=embeds, files=files, ephemeral=ephemeral, allowed_mentions=allowed_mentions)
else:
if view is not None:
await ctx.send(message, embeds=embeds, files=files, ephemeral=ephemeral, view=view, allowed_mentions=allowed_mentions)
else:
await ctx.send(message, embeds=embeds, files=files, ephemeral=ephemeral, allowed_mentions=allowed_mentions)