efelinto

get-command-args.ts

Apr 15th, 2021 (edited)
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { deunionize } from 'telegraf';
  2.  
  3. import { Context } from '../interfaces';
  4.  
  5. export const getCommandArgs = (ctx: Context): string => {
  6.   const messageText = deunionize(ctx.message).text;
  7.  
  8.   const argsFromCommandRegex = /\/(?:\w+)(?:@\w+?_bot)? (?<args>.*)/i;
  9.   const args = argsFromCommandRegex.exec(messageText);
  10.  
  11.   if (!args) {
  12.     return '';
  13.   }
  14.  
  15.   return args.groups.args.trim();
  16. };
  17.  
Add Comment
Please, Sign In to add comment