added automod
This commit is contained in:
parent
7c4bd12a14
commit
9b083e1c61
2 changed files with 34 additions and 0 deletions
|
@ -8,12 +8,14 @@ import { forgejoDown } from "./commands/forgejo-down";
|
||||||
import { source } from "./commands/source";
|
import { source } from "./commands/source";
|
||||||
import { sql } from "./commands/sql";
|
import { sql } from "./commands/sql";
|
||||||
import { help } from "./commands/help";
|
import { help } from "./commands/help";
|
||||||
|
import { moderateMessage } from "./modules/moderate";
|
||||||
|
|
||||||
export const commands: Command[] = [forgejoDown, minky, source, sql, help];
|
export const commands: Command[] = [forgejoDown, minky, source, sql, help];
|
||||||
export const bot = new Telegraf(config.token);
|
export const bot = new Telegraf(config.token);
|
||||||
|
|
||||||
bot.on(message("text"), async (ctx) => {
|
bot.on(message("text"), async (ctx) => {
|
||||||
const msg = ctx.message;
|
const msg = ctx.message;
|
||||||
|
await moderateMessage(ctx);
|
||||||
const author = await ctx.getChatMember(msg.from.id);
|
const author = await ctx.getChatMember(msg.from.id);
|
||||||
config.prefixes.forEach((p) => {
|
config.prefixes.forEach((p) => {
|
||||||
if (msg.text[0] !== p) return;
|
if (msg.text[0] !== p) return;
|
||||||
|
|
32
src/modules/moderate.ts
Normal file
32
src/modules/moderate.ts
Normal 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.`);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue