This commit is contained in:
nin0dev 2024-12-29 17:57:19 -05:00
parent 119e975849
commit 317a1e343e
Signed by: nin0
SSH key fingerprint: SHA256:Is2DvJdw1OkSopR4wKJfdWV0fZhMLxpnCs1P1nPhIgA
3 changed files with 66 additions and 3 deletions

View file

@ -1,7 +1,7 @@
import { Telegraf } from "telegraf";
import { message } from "telegraf/filters";
import config from "./config";
import { config } from "./config";
import { minky } from "./commands/minky";
import { Command } from "./utils/types";
import { forgejoDown } from "./commands/forgejo-down";
@ -10,13 +10,27 @@ import { sql } from "./commands/sql";
import { help } from "./commands/help";
import { moderateMessage } from "./modules/moderate";
import { howgay } from "./commands/howgay";
import { pendingVerificationUsers, setUpAntiBot } from "./modules/antiBot";
export const commands: Command[] = [forgejoDown, minky, source, sql, help, howgay];
const OWNER_ID = 1911826384;
const VEE_ID = 6515935819;
export const bot = new Telegraf(config.token);
setUpAntiBot();
bot.on(message("text"), async (ctx) => {
const pendingUser = pendingVerificationUsers.find((user) => user.user === ctx.message.from.id);
if (pendingUser) {
const answer = pendingUser.val1 * pendingUser.val2 + pendingUser.val3;
if (ctx.text.includes(answer.toString())) {
await ctx.reply("You have now been verified. Welcome!");
pendingVerificationUsers.splice(pendingVerificationUsers.indexOf(pendingUser), 1);
} else {
await ctx.reply("Wrong answer.");
}
}
const msg = ctx.message;
await moderateMessage(ctx);
const author = await ctx.getChatMember(msg.from.id);

49
src/modules/antiBot.ts Normal file
View file

@ -0,0 +1,49 @@
import { bot } from "../client";
export const pendingVerificationUsers: {
user: number;
val1: number;
val2: number;
val3: number;
}[] = [];
export function setUpAntiBot() {
bot.on("new_chat_members", async (ctx) => {
const newMember = ctx.update.message.new_chat_members[0];
const randomNumber1 = Math.floor(Math.random() * 10) + 1;
const randomNumber2 = Math.floor(Math.random() * 10) + 1;
const randomNumber3 = Math.floor(Math.random() * 10) + 1;
await ctx.reply(`Hi ${newMember.first_name}! As part of our anti-bot protection, you will have to answer the following math challenge within a minute:
${randomNumber1} * ${randomNumber2} + ${randomNumber3}
Simply send the answer to the challenge in chat to get verified. If you do not do this, or send something else, or send the wrong answer, you will be kicked.`);
pendingVerificationUsers.push({
user: newMember.id,
val1: randomNumber1,
val2: randomNumber2,
val3: randomNumber3
});
setTimeout(async () => {
const index = pendingVerificationUsers.findIndex((user) => user.user === newMember.id);
if (index !== -1) {
await ctx.reply("Seems like you haven't verified. Goodbye!");
await ctx.banChatMember(newMember.id);
pendingVerificationUsers.splice(index, 1);
}
}, 10000);
});
bot.on("left_chat_member", (ctx) => {
const index = pendingVerificationUsers.findIndex(
(user) => user.user === ctx.message.left_chat_member.id
);
if (index !== -1) {
pendingVerificationUsers.splice(index, 1);
}
});
}

View file

@ -2,8 +2,8 @@ import { message } from "telegraf/filters";
import { bot } from "../client";
import { Context } from "telegraf";
const automoddedWords = ["meow", "miau", "mreow", "mrow", "mrrp", "mrrrp", "mrrrrp", "nya", "nyaa"];
const automoddedRegexes = ["mr*eo*w+", "mr+p", "nya+", "mrow+", "purr+"];
const automoddedWords = [];
const automoddedRegexes = [];
export async function moderateMessage(ctx: Context) {
const author = await ctx.getChatMember(ctx.from.id);