Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
msg = bot.formatter.send_or_edit(recipient, text, to_edit=mid)
else:
msg = util.send_md_message(bot, recipient, text)
# Post actions
buttons = [
InlineKeyboardButton(captions.PIN,
callback_data=util.callback_for_action('pin_message', {'mid': msg.message_id})),
InlineKeyboardButton('Add "Thank You" counter',
callback_data=util.callback_for_action('add_thank_you',
{'cid': recipient, 'mid': msg.message_id})),
]
reply_markup = InlineKeyboardMarkup(util.build_menu(buttons, 1))
mid = util.mid_from_update(update)
action_taken = "edited" if mode == 'editing' else "broadcasted"
bot.formatter.send_or_edit(uid, mdformat.success("Message {}.".format(action_taken)), mid, reply_markup=reply_markup)
)
]
]
reply_markup = InlineKeyboardMarkup(buttons)
text = "{} thinks that you have the means to inspect this bot submission:\n▶️ {}".format(
user.markdown_short, bot_in_question
)
try:
util.send_md_message(
bot,
moderator.chat_id,
text,
reply_markup=reply_markup,
disable_web_page_preview=True,
)
answer_text = mdformat.success(
"I will ask {} to have a look at this submission.".format(
moderator.plaintext
)
)
except Exception as e:
answer_text = mdformat.failure(f"Could not contact {moderator.plaintext}: {e}")
if update.callback_query:
update.callback_query.answer(text=answer_text)
Statistic.of(
update,
"share",
"submission {} with {}".format(bot_in_question.username, moderator.plaintext),
)
with db.atomic():
user_submissions = Bot.select().where(
(Bot.approved == False)
& (Bot.submitted_by == user)
# TODO: does this need to include `Bot.deleted == True`?
)
for b in user_submissions:
b.delete_instance()
users_suggestions = Suggestion.select().where(
(Suggestion.executed == False) & (Suggestion.user == user)
)
for s in users_suggestions:
s.delete_instance()
update.message.reply_text(
mdformat.success(
"User {} banned, all bot submissions and suggestions removed.".format(
user
)
),
parse_mode="markdown",
)
Statistic.of(update, "ban", user.markdown_short)
else:
update.message.reply_text(
mdformat.success("User {} unbanned.".format(user)), parse_mode="markdown"
)
Statistic.of(update, "unban", user.markdown_short)
user.save()
def send_success(self, chat_id, text: str, add_punctuation=True, reply_markup=None, **kwargs):
if add_punctuation:
if text[-1] != '.':
text += '.'
if not reply_markup:
reply_markup = ReplyKeyboardRemove()
return self.bot.sendMessage(
chat_id,
success(text),
reply_markup=reply_markup,
**self._set_defaults(kwargs))