Skip to content

Commit 6cbdbd9

Browse files
committed
move random db images to forceimage in shat
1 parent 8ee2ac0 commit 6cbdbd9

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

app/services/discord/modules/shitposting.ts

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,37 @@ export const Shat = async (options?: {
102102
? { files: [{ attachment: result, description: imgur.title }] }
103103
: undefined;
104104
} else {
105-
let res: AxiosResponse<TenorResponse>;
106-
try {
107-
res = await (
108-
await globalThis.MetaConcord.container.getService("Tenor")
109-
).search(word ?? "random", 4);
110-
} catch {
105+
if (rng <= DISCORD_IMAGE_FREQ) {
106+
try {
107+
const db = await (
108+
await globalThis.MetaConcord.container.getService("SQL")
109+
).getLocalDatabase();
110+
111+
const url = (
112+
await db.get<any>("SELECT url FROM media_urls ORDER BY RANDOM() LIMIT 1")
113+
).url;
114+
115+
return { content: url ?? "wtf" };
116+
} catch {
117+
return { content: "wtf" };
118+
}
119+
} else {
120+
let res: AxiosResponse<TenorResponse>;
121+
try {
122+
res = await (
123+
await globalThis.MetaConcord.container.getService("Tenor")
124+
).search(word ?? "random", 4);
125+
} catch {
126+
return {
127+
content: await markov?.generate(), // fallback to msg if tenor failed
128+
};
129+
}
111130
return {
112-
content: await markov?.generate(), // fallback to msg if tenor failed
131+
content:
132+
res.data.results[(Math.random() * res.data.results.length) | 0].url ??
133+
"wtf tenor error",
113134
};
114135
}
115-
return {
116-
content:
117-
res.data.results[(Math.random() * res.data.results.length) | 0].url ??
118-
"wtf tenor error",
119-
};
120136
}
121137
}
122138
};
@@ -204,18 +220,15 @@ export default async (bot: DiscordBot) => {
204220
? ((await mk.exists(options.msg?.author.globalName?.toLowerCase())) ??
205221
(await mk.exists(options.msg?.author.username?.toLowerCase())))
206222
: options.msg?.content,
207-
forceImage: options.forceImage,
223+
forceImage: shouldSendImg || options.forceImage,
208224
forceReply: options.forceReply,
209225
forceMessage: shouldSendSticker
210226
? ({
211227
stickers: [bot.getGuild()?.stickers.cache.random()],
212228
} as Discord.MessageCreateOptions)
213-
: shouldSendImg
214-
? (await db.get<any>("SELECT url FROM media_urls ORDER BY RANDOM() LIMIT 1"))
215-
.url
216-
: shouldSendEmoji
217-
? getRandomEmoji().toString()
218-
: undefined,
229+
: shouldSendEmoji
230+
? getRandomEmoji().toString()
231+
: undefined,
219232
});
220233
if (shat) {
221234
if (options.msg) {

0 commit comments

Comments
 (0)