def _do_purge(self, bot): for msg in self.messages_issued: if self.id == msg.chat_id: bot.delete_message(chat_id=self.id, message_id=msg.message_id) self.messages_issued.clear() self.q_notifications.clear()
def _callback_announce(self, update, decision): bot = update.bot if decision == "N": update.answer(text="Alright, I won't announce anything. " "Why bother?") else: self._do_announce(update, contest_id=int(decision)) bot.delete_message(chat_id=self.id, message_id=update.message.message_id)
def _callback_purge(self, update, decision): bot = update.bot if decision == "Yes": update.answer(text="(passive-aggressive voice) Fine, I'll delete " "my recent messages.") self._do_purge(bot) else: update.answer(text="Okay, I won't delete nothing.") bot.delete_message(chat_id=self.id, message_id=update.message.message_id)
def order_cancel_handler(update, context): message = utils.get_message(update, context) bot = utils.get_bot(update, context) bot.delete_message( chat_id=message.chat_id, message_id=message.message_id ) message.reply_text('Ваш заказ отменен') utils.send_message_to_admin( context.bot, f"Заказ {context.user_data['order_id']} *отменен*") utils.update_order_status( context.user_data['order_id'], 'cancelled' ) context.user_data.clear() return CHOOSING_CATEGORY
def order_confirm_handler(update, context): message = utils.get_message(update, context) bot = utils.get_bot(update, context) bot.delete_message( chat_id=message.chat_id, message_id=message.message_id ) message.reply_text( config.text['thank_you'], reply_markup=utils.get_start_kb() ) utils.send_message_to_admin( context.bot, f"Заказ {context.user_data['order_id']} *подтвержден*") utils.update_order_status( context.user_data['order_id'], 'confirmed' ) context.user_data.clear() return CHOOSING_CATEGORY
db.add_notice(notice_category, notice_date, crawl_dt, issuer, title, short_link, msg_id) time.sleep(2) if s_p.obsolete(): notice_category = str(cat + '_Pinned') for stuff in s_p.obsolete(): stuff_notice_date = datetime.datetime.strptime( db.get_notice_date(notice_category, stuff), '%Y-%m-%d') tdelta = datetime.datetime.today() - stuff_notice_date if tdelta.days > 180: #등록 뒤 180일을 초과한 시간이 지난 공지만 삭제 또는 열람 불가 처리 #코드 작성 시점에서는 Telegram 메신저 자체의 정책으로 봇 계정은 작성 뒤 48시간 이내의 메시지만 삭제할 수 있음 message_id = str(db.get_msg_id(notice_category, stuff)) try: bot.delete_message(chat_id=channel, message_id=message_id) except: try: bot.edit_message_text( text= '#obsolete\n오래된 공지입니다.\n다시 보려면 학교 누리집을 방문해주십시오.', chat_id=channel, message_id=message_id) db.del_notice(notice_category, stuff) except: pass new_pinned.clear() check_pinned.clear() check_normal = db.get_notices(str(cat + '_Normal'))