15 lines
549 B
TypeScript
15 lines
549 B
TypeScript
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();
|
|
};
|
|
} |