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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ jobs:
gh api \
--method POST \
/repos/${{ github.repository }}/commits/${{ github.sha }}/comments \
-f 'body=Bruh, learn to code'
-f 'body=Bruh, learn to code: https://github.com/0d9e-tech/web/actions/runs/${{ github.run_id }}/job/${{ job.check_run_id }}#step:5:1'
git reset --hard $before
git push origin HEAD:${{ github.ref }} --force
30 changes: 6 additions & 24 deletions src/tg/bot.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
BOT_TOKEN,
DOMAIN,
genRandomToken,
řekniTomovi,
getFileBase64,
MAIN_CHAT_ID,
PRINTER_TOKEN,
STICEKR_SET_NAME,
STICEKR_SET_OWNER,
tgCall,
Expand Down Expand Up @@ -169,7 +170,7 @@ export async function* handleTgUpdate(data: any) {
});
}

const chungus_balls_extended = "No tak kde je to tvoje";
const chungus_balls_extended = "No tak kde je to tvoje ";
if (
data.message.chat.id === MAIN_CHAT_ID &&
!(data.message.message_id % 100000)
Expand Down Expand Up @@ -338,34 +339,15 @@ Be grateful for your abilities and your incredible success and your considerable

const trig = "/řekni_tomovi";
if (text.startsWith(trig) && data.message.chat.id === MAIN_CHAT_ID) {
const response = await fetch("https://printomat.slama.dev/submit", {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
message: `${data.message.from.first_name} říká: ${
text.slice(trig.length).trim()
}`,
image: "",
token: PRINTER_TOKEN,
}).toString(),
method: "POST",
});
const txt = await response.text();
await tgCall({
chat_id: data.message.chat.id,
reply_to_message_id: data.message.message_id,
text: `Tom říká (${response.status}): ${
/<p>(.*?)<\/p>/.exec(txt)?.[1] ?? txt
}`,
});
const image = await getFileBase64(data.message.reply_to_message ?? data.message);
řekniTomovi(data.message.from.first_name, text.slice(trig.length).trim(), image, data.message.chat.id);
}

if (data.message.from.id == (13*(2*29811374 + 1)) &&
!data.message.text.toLowerCase().includes(smrdis)) {
await tgCall({
chat_id: data.message.chat.id,
text: penis + smrdis + "ení?",
text: penis + " " + smrdis + "ení?",
});
}

Expand Down
75 changes: 75 additions & 0 deletions src/tg/utils.deno.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// deno-lint-ignore-file no-explicit-any
// The authors disclaim copyright to this source code (they are ashamed to
// admit they wrote it)
import { encodeBase64 } from "jsr:@std/encoding@^1.0.10";

export const BOT_TOKEN = Deno.env.get("TG_BOT_TOKEN");
export const MAIN_CHAT_ID = parseInt(Deno.env.get("TG_MAIN_CHAT_ID")!);
Expand Down Expand Up @@ -104,3 +105,77 @@ export async function tgCall(
}
return req;
}

export async function řekniTomovi(
sender: string,
message: string,
image: string = "",
chat_id: number = MAIN_CHAT_ID,
) {
if (sender) {
message = `${sender} říká: ${message}`;
}

const response = await fetch("https://printomat.slama.dev/submit", {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
message: message,
image: image,
token: PRINTER_TOKEN,
}).toString(),
method: "POST",
});
const txt = await response.text();
if (chat_id) {
await tgCall({
chat_id: chat_id,
reply_to_message_id: chat_id,
text: `Tom říká (${response.status}): ${
/<p>(.*?)<\/p>/.exec(txt)?.[1] ?? txt
}`,
});
}
}

export async function getFileBase64(message: any, maxSize = Infinity) {
function* files() {
yield message.sticker?.thumb;
yield message.sticker?.thumbnail;
yield message.sticker;
yield message.video_note?.thumb;
yield message.video_note?.thumbnail;
yield message.video_note;
yield message.video?.thumb;
yield message.video?.thumbnail;
yield message.video;
yield message.document;
if (message.photo) {
yield* message.photo;
}
}

let bestCandidate = undefined;
for (const file of files()) {
if (
!file || file.file_size > maxSize ||
file.file_size < bestCandidate?.file_size
) continue;
bestCandidate = file;
}

if (!bestCandidate) {
return;
}

const fileData = await tgCall(
{ file_id: bestCandidate.file_id },
"getFile",
);
const response = await fetch(
`https://api.telegram.org/file/bot${BOT_TOKEN}/${fileData.result.file_path}`,
);
const fileContent = new Uint8Array(await response.arrayBuffer());
return encodeBase64(fileContent);
}
Loading