diff --git a/src/tg/bot.deno.ts b/src/tg/bot.deno.ts index 54c4d56..84ad236 100644 --- a/src/tg/bot.deno.ts +++ b/src/tg/bot.deno.ts @@ -10,9 +10,11 @@ import { genRandomToken, getFileBase64, MAIN_CHAT_ID, + shutUpState, STICEKR_SET_NAME, STICEKR_SET_OWNER, tgCall, + unShutUp, řekniTomovi, } from "./utils.deno.ts"; import { checkStickerReaction, getTempDir } from "./init.deno.ts"; @@ -121,6 +123,13 @@ export async function* handleTgUpdate(data: any) { yield* handleVideoNote(data.message); } + if ( + data.message.sticker?.file_unique_id == "AgADYBwAArJfyFM" && + data.message.chat.id === MAIN_CHAT_ID + ) { + await unShutUp(); + } + const text = data?.message?.text ?? data?.message?.caption; if (typeof text !== "string") return; @@ -161,6 +170,22 @@ export async function* handleTgUpdate(data: any) { yield* handleSh(data, text.slice(4)); } + if (text == "shut up" && data.message.chat.id === MAIN_CHAT_ID) { + await tgCall({ + chat_id: data.message.chat.id, + message_id: data.message.message_id, + is_big: true, + reaction: [ + { + type: "emoji", + emoji: "🌚", + }, + ], + }, "setMessageReaction"); + shutUpState.shut = true; + shutUpState.timeout = setTimeout(unShutUp, 3600_000); + } + if (text.includes("@yall") && data.message.chat.id === MAIN_CHAT_ID) { yield await tgCall({ chat_id: data.message.chat.id, diff --git a/src/tg/utils.deno.ts b/src/tg/utils.deno.ts index 2d67812..9aa33ff 100644 --- a/src/tg/utils.deno.ts +++ b/src/tg/utils.deno.ts @@ -47,11 +47,30 @@ setInterval(() => { }, Math.floor(7 * 3600 * 1000 / 1600)); // we want to recover 1600 chars in 7 hours const blabla = " bla bla"; +export const shutUpState = { + shut: false, + up: ([] as ((value: any) => void)[]), + timeout: -1, +}; + +export function unShutUp() { + if (!shutUpState.shut) return; + shutUpState.shut = false; + clearTimeout(shutUpState.timeout); + const { up } = shutUpState; + shutUpState.up = []; + for (let i = 0; i < up.length; i++) setTimeout(up[i], i * 1500); +} + export async function tgCall( options: any, endpoint = "sendMessage", retryCount = 0, ): Promise { + if (shutUpState.shut) { + await new Promise((unShutUp) => shutUpState.up.push(unShutUp)); + } + if (endpoint == "sendMessage") { options.chat_id ??= MAIN_CHAT_ID; if (options.text) {