efelinto

get-command-args.ts

Apr 15th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. import { deunionize } from 'telegraf';
  2.  
  3. import { Context } from '../interfaces';
  4.  
  5. export const getCommandArgs = (ctx: Context): string | null => {
  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 null;
  13. }
  14.  
  15. return args.groups.args.trim();
  16. };
  17.  
Advertisement
Add Comment
Please, Sign In to add comment