added automod

This commit is contained in:
nin0dev 2024-09-23 20:57:47 -04:00
parent 7c4bd12a14
commit 9b083e1c61
Signed by: nin0
GPG key ID: 3FA8F96ABAE04214
2 changed files with 34 additions and 0 deletions

View file

@ -8,12 +8,14 @@ import { forgejoDown } from "./commands/forgejo-down";
import { source } from "./commands/source";
import { sql } from "./commands/sql";
import { help } from "./commands/help";
import { moderateMessage } from "./modules/moderate";
export const commands: Command[] = [forgejoDown, minky, source, sql, help];
export const bot = new Telegraf(config.token);
bot.on(message("text"), async (ctx) => {
const msg = ctx.message;
await moderateMessage(ctx);
const author = await ctx.getChatMember(msg.from.id);
config.prefixes.forEach((p) => {
if (msg.text[0] !== p) return;

32
src/modules/moderate.ts Normal file
View file

@ -0,0 +1,32 @@
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+"];
export async function moderateMessage(ctx: Context) {
const author = await ctx.getChatMember(ctx.from.id);
if (author.status === "administrator" || author.status === "creator") return;
if (
automoddedWords.some((word) => ctx.text.includes(word)) ||
automoddedRegexes.some((pattern) => new RegExp(pattern, "i").test(ctx.text))
) {
await ctx.deleteMessage();
await ctx.restrictChatMember(ctx.from.id, {
until_date: Math.floor(Date.now() / 1000) + 60,
permissions: {
can_send_messages: false,
can_send_audios: false,
can_send_documents: false,
can_send_photos: false,
can_send_videos: false,
can_send_video_notes: false,
can_send_voice_notes: false,
can_send_other_messages: false,
can_invite_users: false
}
});
await ctx.reply(`Muted ${ctx.from.first_name} for 1 minute for using an automodded word.`);
}
}