diff --git a/src/client.ts b/src/client.ts index ebb6140..954c32f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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; diff --git a/src/modules/moderate.ts b/src/modules/moderate.ts new file mode 100644 index 0000000..2fd186d --- /dev/null +++ b/src/modules/moderate.ts @@ -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.`); + } +}