Initial commit
This commit is contained in:
15
src/middlewares/ignore-old.ts
Normal file
15
src/middlewares/ignore-old.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Context } from "#root/context.js";
|
||||
import { logger } from "#root/logger.js";
|
||||
import { Middleware } from "grammy";
|
||||
|
||||
export function ignoreOld(threshold = 5 * 60): Middleware<Context> {
|
||||
return async (ctx, next) => {
|
||||
if (ctx.message?.date && new Date().getTime() / 1000 - ctx.message.date > threshold) {
|
||||
logger.warn(`Ignoring message from user ${ctx.from?.id} at chat ${ctx.chat?.id} (${new Date().getTime() / 1000
|
||||
}:${ctx.message.date})`);
|
||||
return;
|
||||
}
|
||||
|
||||
return next();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user