add delete function for channel heler
This commit is contained in:
parent
14e4adab4f
commit
627dd1c128
@ -9,7 +9,7 @@ import requests
|
||||
from PIL import Image
|
||||
from django.db import models
|
||||
from telegram import Update, Bot
|
||||
from telegram.ext import Dispatcher, CallbackContext, MessageHandler, Filters
|
||||
from telegram.ext import Dispatcher, CallbackContext, MessageHandler, Filters, CommandHandler
|
||||
from jsonrpc import Dispatcher as RPCDispatcher
|
||||
from djconfig import config
|
||||
|
||||
@ -71,7 +71,7 @@ class ChannelHelperBotModuleConfig(TelegramBotModuleConfig):
|
||||
|
||||
m = update.effective_message
|
||||
bot = ctx.bot
|
||||
i = QueuedItem(config=self)
|
||||
i = QueuedItem(config=self, message_id=m.message_id)
|
||||
if hasattr(m, 'audio') and m.audio:
|
||||
a = m.audio
|
||||
i.type = 'audio'
|
||||
@ -121,8 +121,19 @@ class ChannelHelperBotModuleConfig(TelegramBotModuleConfig):
|
||||
else:
|
||||
i.send(bot)
|
||||
|
||||
def handle_delete(self, update: Update, ctx: CallbackContext):
|
||||
if update.effective_message.chat_id != self.chat_id:
|
||||
return
|
||||
reply_to_id = update.effective_message.reply_to_message.message_id
|
||||
try:
|
||||
msg = QueuedItem.objects.get(message_id=reply_to_id)
|
||||
msg.delete()
|
||||
except QueuedItem.DoesNotExist:
|
||||
update.effective_message.reply_text('Deleted')
|
||||
|
||||
def build_dispatcher(self, dispatcher: Dispatcher):
|
||||
dispatcher.add_handler(MessageHandler(Filters.private, self.handle_message))
|
||||
dispatcher.add_handler(CommandHandler(['delete', 'del', 'remove', 'rem'], self.handle_delete, Filters.reply))
|
||||
return dispatcher
|
||||
|
||||
|
||||
@ -130,6 +141,7 @@ class QueuedItem(models.Model):
|
||||
config = models.ForeignKey(ChannelHelperBotModuleConfig, on_delete=models.CASCADE, related_name='queued_items')
|
||||
type = models.CharField(max_length=12)
|
||||
args = models.TextField()
|
||||
message_id = models.PositiveBigIntegerField(default=None, db_index=True)
|
||||
|
||||
def send(self, bot: Bot):
|
||||
getattr(bot, 'send_' + self.type)(self.config.chat_id, *json.loads(self.args))
|
||||
|
Loading…
Reference in New Issue
Block a user