Skip to content

Commit cc26227

Browse files
committed
better author shat
1 parent cb3f2cb commit cc26227

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

app/services/discord/modules/shitposting.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function getWord(msg?: string) {
6161

6262
export const Shat = async (options?: {
6363
msg?: string;
64-
fallback?: string;
6564
forceImage?: boolean;
6665
forceReply?: boolean;
6766
forceMessage?: string | Discord.MessageCreateOptions;
@@ -84,7 +83,7 @@ export const Shat = async (options?: {
8483
search = getWord(message);
8584
}
8685

87-
let shat = await markov?.generate(getWord(search ?? options?.fallback));
86+
let shat = await markov?.generate(getWord(search));
8887

8988
if (!shat) shat = await markov?.generate();
9089

@@ -151,7 +150,7 @@ const COMMON_EMOJIS = [
151150
"🙄",
152151
"🙏",
153152
"🥀",
154-
"<:h_:536265505649197066>"
153+
"<:h_:536265505649197066>",
155154
];
156155

157156
const lastMsgs: Discord.Message<boolean>[] = [];
@@ -160,6 +159,7 @@ const lastReactedUsers = new Set<string>();
160159

161160
export default async (bot: DiscordBot) => {
162161
const data = await bot.container.getService("Data");
162+
const mk = await bot.container.getService("Markov");
163163
const db = await (await bot.container.getService("SQL")).getLocalDatabase();
164164
db.exec("CREATE TABLE IF NOT EXISTS media_urls (url VARCHAR(255) NOT NULL UNIQUE);");
165165
const now = Date.now();
@@ -201,10 +201,9 @@ export default async (bot: DiscordBot) => {
201201
const shouldSendEmoji = Math.random() <= EMOJI_REPLY_FREQ;
202202
const shat = await Shat({
203203
msg: shouldUseAuthor
204-
? (options.msg?.author.globalName?.toLowerCase() ??
205-
options.msg?.author.username?.toLowerCase())
204+
? ((await mk.exists(options.msg?.author.globalName?.toLowerCase())) ??
205+
(await mk.exists(options.msg?.author.username?.toLowerCase())))
206206
: options.msg?.content,
207-
fallback: shouldUseAuthor ? options.msg?.content : undefined,
208207
forceImage: options.forceImage,
209208
forceReply: options.forceReply,
210209
forceMessage: shouldSendSticker
@@ -262,9 +261,7 @@ export default async (bot: DiscordBot) => {
262261
const prefix = selection.ctx[(Math.random() * selection.ctx.length) | 0];
263262

264263
if (prefix !== "custom") {
265-
const sentence = await (
266-
await bot.container.getService("Markov")
267-
).generate(prefix, {
264+
const sentence = await mk.generate(prefix, {
268265
continuation: false,
269266
});
270267

@@ -283,7 +280,7 @@ export default async (bot: DiscordBot) => {
283280
: joint + sentence;
284281
}
285282
}
286-
const state = (await (await bot.container.getService("Markov")).generate()) ?? "wtf";
283+
const state = (await mk.generate()) ?? "wtf";
287284

288285
lastSetActivity = {
289286
name: status,
@@ -381,12 +378,10 @@ export default async (bot: DiscordBot) => {
381378
!lastReactedUsers.has(user.id) &&
382379
Math.random() <= (reaction.emoji.name === "h_" ? 0.01 : MSG_REPLY_REACTION_FREQ)
383380
) {
384-
const mk = await (
385-
await bot.container.getService("Markov")
386-
).generate(reaction.emoji.toString());
387-
if (mk) {
381+
const theFunny = await mk.generate(reaction.emoji.toString());
382+
if (theFunny) {
388383
await (message.channel as Discord.TextChannel)
389-
.send(`${user.mention} ` + mk)
384+
.send(`${user.mention} ` + theFunny)
390385
.catch();
391386
}
392387
lastReactedMessages.add(message.id);

0 commit comments

Comments
 (0)