1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-05-04 11:16:41 +07:00

added wtf command

This commit is contained in:
Fedor Katurov 2021-05-28 16:26:36 +07:00
parent 0839684fff
commit b28c34878b
5 changed files with 99 additions and 0 deletions
src/api/telegram

View file

@ -15,6 +15,8 @@ export class TelegramApi {
this.telegram.bot.command("ping", TelegramApi.ping);
this.telegram.bot.command("config", this.dumpConfig);
this.telegram.bot.command("pop", this.pop);
this.telegram.bot.command("wtf", this.wtf);
return;
}
@ -76,6 +78,32 @@ export class TelegramApi {
return next();
};
/**
* Sends recent logs
*/
private wtf = async (ctx, next) => {
const username = ctx?.update?.message?.from?.username;
if (!username || !this.telegram.isOwner(`@${username}`)) {
return;
}
const logs = await this.db.popLogs();
if (!logs || !logs.length) {
await ctx.reply(`sorry, no logged errors yet`);
return next();
}
const source = JSON.stringify(logs, null, 2);
await ctx.replyWithDocument({
source: Readable.from(source),
filename: `logs-${new Date().toISOString()}.txt`,
});
return next();
};
/**
* Probes webhook url and falls back to polling mode on error
*/