anti bot
This commit is contained in:
parent
119e975849
commit
317a1e343e
3 changed files with 66 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { Telegraf } from "telegraf";
|
import { Telegraf } from "telegraf";
|
||||||
import { message } from "telegraf/filters";
|
import { message } from "telegraf/filters";
|
||||||
|
|
||||||
import config from "./config";
|
import { config } from "./config";
|
||||||
import { minky } from "./commands/minky";
|
import { minky } from "./commands/minky";
|
||||||
import { Command } from "./utils/types";
|
import { Command } from "./utils/types";
|
||||||
import { forgejoDown } from "./commands/forgejo-down";
|
import { forgejoDown } from "./commands/forgejo-down";
|
||||||
|
@ -10,13 +10,27 @@ import { sql } from "./commands/sql";
|
||||||
import { help } from "./commands/help";
|
import { help } from "./commands/help";
|
||||||
import { moderateMessage } from "./modules/moderate";
|
import { moderateMessage } from "./modules/moderate";
|
||||||
import { howgay } from "./commands/howgay";
|
import { howgay } from "./commands/howgay";
|
||||||
|
import { pendingVerificationUsers, setUpAntiBot } from "./modules/antiBot";
|
||||||
|
|
||||||
export const commands: Command[] = [forgejoDown, minky, source, sql, help, howgay];
|
export const commands: Command[] = [forgejoDown, minky, source, sql, help, howgay];
|
||||||
const OWNER_ID = 1911826384;
|
const OWNER_ID = 1911826384;
|
||||||
const VEE_ID = 6515935819;
|
const VEE_ID = 6515935819;
|
||||||
export const bot = new Telegraf(config.token);
|
export const bot = new Telegraf(config.token);
|
||||||
|
|
||||||
|
setUpAntiBot();
|
||||||
|
|
||||||
bot.on(message("text"), async (ctx) => {
|
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;
|
const msg = ctx.message;
|
||||||
await moderateMessage(ctx);
|
await moderateMessage(ctx);
|
||||||
const author = await ctx.getChatMember(msg.from.id);
|
const author = await ctx.getChatMember(msg.from.id);
|
||||||
|
|
49
src/modules/antiBot.ts
Normal file
49
src/modules/antiBot.ts
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -2,8 +2,8 @@ import { message } from "telegraf/filters";
|
||||||
import { bot } from "../client";
|
import { bot } from "../client";
|
||||||
import { Context } from "telegraf";
|
import { Context } from "telegraf";
|
||||||
|
|
||||||
const automoddedWords = ["meow", "miau", "mreow", "mrow", "mrrp", "mrrrp", "mrrrrp", "nya", "nyaa"];
|
const automoddedWords = [];
|
||||||
const automoddedRegexes = ["mr*eo*w+", "mr+p", "nya+", "mrow+", "purr+"];
|
const automoddedRegexes = [];
|
||||||
|
|
||||||
export async function moderateMessage(ctx: Context) {
|
export async function moderateMessage(ctx: Context) {
|
||||||
const author = await ctx.getChatMember(ctx.from.id);
|
const author = await ctx.getChatMember(ctx.from.id);
|
||||||
|
|
Loading…
Reference in a new issue