Advertisement
MrModest

TgBotDecorator.js

Sep 9th, 2020
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { logToAdmin } = require('./helpers');
  2.  
  3. class TgBotDecoratorClass {
  4.     constructor(botToken, config) {
  5.         bot = new Telegraf(botToken, config);
  6.     }
  7.  
  8.     command = (commandName, commandHandler) => {
  9.         bot.command(commandName, addCatch(commandHandler));
  10.     }
  11.  
  12.     addCatch = (commandHandler) => {
  13.         return ctx => {
  14.             try {
  15.                 commandHandler(ctx);
  16.             } catch(error) {
  17.                 logToAdmin(bot)(error);
  18.             }
  19.         }
  20.     }
  21. }
  22.  
  23. module.exports.TgBotDecorator = (botToken, config) => {
  24.     return new TgBotDecoratorClass(botToken, config);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement