Skip to content

Instantly share code, notes, and snippets.

@SilencerWeb
Created June 22, 2019 12:01
Show Gist options
  • Select an option

  • Save SilencerWeb/63b85e92b1a32e1f9e7a00d2bb1512e9 to your computer and use it in GitHub Desktop.

Select an option

Save SilencerWeb/63b85e92b1a32e1f9e7a00d2bb1512e9 to your computer and use it in GitHub Desktop.
const { Post } = require('../models');
const { generatePostKeyboard } = require('../keyboards');
const { bot } = require('../bot');
const { CHANNELS_INFO, ACTION_NAMES, IS_PRODUCTION, DEVELOPMENT_GROUP_ID } = require('../constants');
const setUpRemovePostCaptionAction = () => {
bot.action(ACTION_NAMES.remove_post_caption.regexp, (context) => {
const id = context.match[1];
const callbackQueryId = context.update.callback_query.id;
Post.findByIdAndUpdate(id, { isCaptionVisible: false }, async (error) => {
if (error) {
console.log(`Error on changing post's "isCaptionVisible" with ID ${id} to "false"`);
console.log(`Error message: ${error.message}`);
bot.telegram.answerCbQuery(callbackQueryId, `Couldn't remove caption. Error: ${error.message}`);
} else {
const post = await Post.findById(id);
const channelInfo = CHANNELS_INFO[post.channel];
const moderationGroupId = IS_PRODUCTION ? channelInfo.moderationGroupId : DEVELOPMENT_GROUP_ID;
const moderationGroupMessageId = post.moderationGroupMessageId;
bot.telegram.editMessageCaption(moderationGroupId, moderationGroupMessageId, '', '');
bot.telegram.editMessageReplyMarkup(moderationGroupId, moderationGroupMessageId, '', generatePostKeyboard(id, false));
bot.telegram.answerCbQuery(callbackQueryId, 'Caption was successfully removed');
}
});
});
};
module.exports = { setUpRemovePostCaptionAction };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment