efelinto

get-command-args.ts

Apr 15th, 2021 (edited)
98
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, command: string): string => {
  6.   const messageText = deunionize(ctx.message).text;
  7.  
  8.   const argsFromCommandRegex = new RegExp(
  9.     `/${command}(?:@.*_bot)? (?<args>.*)`,
  10.   );
  11.   const args = argsFromCommandRegex.exec(messageText);
  12.   return args.groups.args.trim();
  13. };
  14.  
Add Comment
Please, Sign In to add comment