Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const updateFunctions = {
- // Message
- message(update, props) {
- // Any event status: ['*', '/*']
- let anyEventFlags = [false, false];
- let promise = Promise.resolve();
- let mod = this.modRun('message', {message: update, props});
- update = mod.message;
- props = mod.props;
- promise = promise.then(() => mod.promise);
- for (let type of MESSAGE_TYPES) {
- // Check for Telegram API documented types
- if (!(type in update)) continue;
- // Shortcut
- if (SHORTCUTS[type]) type = SHORTCUTS[type];
- // Set message type
- props.type = type;
- // Run message type mod
- mod = this.modRun(type, {message: update, props});
- update = mod.message;
- props = mod.props;
- promise = promise.then(() => mod.promise);
- const eventList = [type];
- if (!anyEventFlags[0]) {
- eventList.push('*');
- anyEventFlags[0] = true;
- }
- promise = promise.then(() => {
- return this.event(eventList, update, props);
- });
- ################################################################################
- // Check for command
- if (type === 'command') {
- const match = REGEXP_COMMAND.exec(update.text);
- if (!match) continue;
- // Command found
- props.type = 'text';
- const eventList = ['*' + match[1]];
- if (!anyEventFlags[1]) {
- eventList.push(['/*']);
- anyEventFlags[1] = true;
- }
- promise = promise.then(() => {
- return this.event(eventList, update, props);
- });
- }
- ################################################################################
- break;
- }
- return promise;
- },
- // Channel post
- channel_post(update, props) {
- return updateFunctions.message.call(this, update, props);
- },
- // Edited hannel post
- edited_channel_post(update, props) {
- return updateFunctions.message.call(this, update, props);
- },
- // Edited message
- edited_message(update, props) {
- return updateFunctions.message.call(this, update, props);
- },
- // Inline query
- inline_query(update, props) {
- props.type = 'inlineQuery';
- return this.event('inlineQuery', update, props);
- },
- // Inline choice
- chosen_inline_result(update, props) {
- props.type = 'chosenInlineResult';
- return this.event([props.type, 'inlineChoice'], update, props);
- },
- // Callback query
- callback_query(update, props) {
- props.type = 'callbackQuery';
- return this.event('callbackQuery', update, props);
- },
- shipping_query(update, props) {
- props.type = 'shippingQuery';
- return this.event('shippingQuery', update, props);
- },
- pre_checkout_query(update, props) {
- props.type = 'preShippingQuery';
- return this.event('preShippingQuery', update, props);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement