Skip to content

Instantly share code, notes, and snippets.

@poeti8
Created April 25, 2021 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poeti8/c3057f973466676ca8dbbb1183cd0624 to your computer and use it in GitHub Desktop.
Save poeti8/c3057f973466676ca8dbbb1183cd0624 to your computer and use it in GitHub Desktop.
the-guard-x-post-plugin
import ms = require("millisecond");
import R = require("ramda");
import type { ExtendedContext } from "../typings/context";
const messages = new Set<string>();
const strip = R.omit([
"message_id",
"date",
"chat",
"reply_to_message",
"media_group_id",
]);
setInterval(() => messages.clear(), ms("1h"));
export = (ctx: ExtendedContext, next: () => Promise<void>) => {
if (
ctx.from?.status === "admin" ||
ctx.updateType !== "message" ||
!ctx.chat?.type.endsWith("group") ||
(ctx.updateSubTypes[0]?.includes("_") &&
ctx.updateSubTypes[0] !== "video_note") ||
ctx.message?.text?.length < 20
) {
return next();
}
const cooked = JSON.stringify(strip(ctx.message));
if (messages.has(cooked)) {
return ctx.deleteMessage();
}
messages.add(cooked);
return next();
};
@C0rn3j
Copy link

C0rn3j commented Sep 18, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment