efelinto

get-command-args.ts

Apr 15th, 2021 (edited)
91
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+)(?:@.*_bot)? (?<args>.*)/;
  9.   const args = argsFromCommandRegex.exec(messageText);
  10.   return args.groups.args.trim();
  11. };
  12.  
Add Comment
Please, Sign In to add comment