Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/tg/bot.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions src/tg/utils.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
if (shutUpState.shut) {
await new Promise((unShutUp) => shutUpState.up.push(unShutUp));
}

if (endpoint == "sendMessage") {
options.chat_id ??= MAIN_CHAT_ID;
if (options.text) {
Expand Down
Loading