mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-25 06:56:40 +07:00
added config dump command
This commit is contained in:
parent
c709bbf94c
commit
f3e0062033
2 changed files with 26 additions and 2 deletions
|
@ -5,10 +5,15 @@ import { PostgresDB } from "../../service/db/postgres";
|
|||
import { Readable } from "stream";
|
||||
|
||||
export class TelegramApi {
|
||||
constructor(private telegram: TelegramService, private db: PostgresDB) {}
|
||||
constructor(
|
||||
private telegram: TelegramService,
|
||||
private db: PostgresDB,
|
||||
private config: Record<any, any>
|
||||
) {}
|
||||
|
||||
public listen() {
|
||||
this.telegram.bot.command("ping", TelegramApi.ping);
|
||||
this.telegram.bot.command("config", this.dumpConfig);
|
||||
this.telegram.bot.command("pop", this.pop);
|
||||
return;
|
||||
}
|
||||
|
@ -46,6 +51,25 @@ export class TelegramApi {
|
|||
return next();
|
||||
};
|
||||
|
||||
/**
|
||||
* Pops last recorded request from vk
|
||||
*/
|
||||
private dumpConfig = async (ctx, next) => {
|
||||
const username = ctx?.update?.message?.from?.username;
|
||||
|
||||
if (!username || !this.telegram.isOwner(`@${username}`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const source = JSON.stringify(this.config, null, 2);
|
||||
await ctx.replyWithDocument({
|
||||
source: Readable.from(source),
|
||||
filename: `config.txt`,
|
||||
});
|
||||
|
||||
return next();
|
||||
};
|
||||
|
||||
/**
|
||||
* Probes webhook url and falls back to polling mode on error
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue