Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const updateFunctions = {
  2.  
  3.     // Message
  4.     message(update, props) {
  5.  
  6.         // Any event status: ['*', '/*']
  7.         let anyEventFlags = [false, false];
  8.  
  9.         let promise = Promise.resolve();
  10.         let mod = this.modRun('message', {message: update, props});
  11.  
  12.         update = mod.message;
  13.         props = mod.props;
  14.         promise = promise.then(() => mod.promise);
  15.  
  16.         for (let type of MESSAGE_TYPES) {
  17.  
  18.             // Check for Telegram API documented types
  19.             if (!(type in update)) continue;
  20.  
  21.             // Shortcut
  22.             if (SHORTCUTS[type]) type = SHORTCUTS[type];
  23.  
  24.             // Set message type
  25.             props.type = type;
  26.  
  27.             // Run message type mod
  28.             mod = this.modRun(type, {message: update, props});
  29.  
  30.             update = mod.message;
  31.             props = mod.props;
  32.             promise = promise.then(() => mod.promise);
  33.  
  34.             const eventList = [type];
  35.             if (!anyEventFlags[0]) {
  36.                 eventList.push('*');
  37.                 anyEventFlags[0] = true;
  38.             }
  39.  
  40.             promise = promise.then(() => {
  41.                 return this.event(eventList, update, props);
  42.             });
  43. ################################################################################
  44.             // Check for command
  45.             if (type === 'command') {
  46.  
  47.                 const match = REGEXP_COMMAND.exec(update.text);
  48.                 if (!match) continue;
  49.  
  50.                 // Command found
  51.                 props.type = 'text';
  52.  
  53.                 const eventList = ['*' + match[1]];
  54.                 if (!anyEventFlags[1]) {
  55.                     eventList.push(['/*']);
  56.                     anyEventFlags[1] = true;
  57.                 }
  58.  
  59.                 promise = promise.then(() => {
  60.                     return this.event(eventList, update, props);
  61.                 });
  62.  
  63.             }
  64. ################################################################################
  65.             break;
  66.  
  67.         }
  68.  
  69.         return promise;
  70.     },
  71.  
  72.     // Channel post
  73.     channel_post(update, props) {
  74.         return updateFunctions.message.call(this, update, props);
  75.     },
  76.  
  77.     // Edited hannel post
  78.     edited_channel_post(update, props) {
  79.         return updateFunctions.message.call(this, update, props);
  80.     },
  81.  
  82.     // Edited message
  83.     edited_message(update, props) {
  84.         return updateFunctions.message.call(this, update, props);
  85.     },
  86.  
  87.     // Inline query
  88.     inline_query(update, props) {
  89.         props.type = 'inlineQuery';
  90.         return this.event('inlineQuery', update, props);
  91.     },
  92.  
  93.     // Inline choice
  94.     chosen_inline_result(update, props) {
  95.         props.type = 'chosenInlineResult';
  96.         return this.event([props.type, 'inlineChoice'], update, props);
  97.     },
  98.  
  99.     // Callback query
  100.     callback_query(update, props) {
  101.         props.type = 'callbackQuery';
  102.         return this.event('callbackQuery', update, props);
  103.     },
  104.  
  105.     shipping_query(update, props) {
  106.         props.type = 'shippingQuery';
  107.         return this.event('shippingQuery', update, props);
  108.     },
  109.  
  110.     pre_checkout_query(update, props) {
  111.         props.type = 'preShippingQuery';
  112.         return this.event('preShippingQuery', update, props);
  113.     }
  114.  
  115. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement