diff --git a/src/client.ts b/src/client.ts index a7c6059..feecf1e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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); diff --git a/src/modules/antiBot.ts b/src/modules/antiBot.ts new file mode 100644 index 0000000..4cf48e1 --- /dev/null +++ b/src/modules/antiBot.ts @@ -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); + } + }); +} diff --git a/src/modules/moderate.ts b/src/modules/moderate.ts index 2fd186d..0a191e2 100644 --- a/src/modules/moderate.ts +++ b/src/modules/moderate.ts @@ -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);