telegram_bots/aggregator/signals.py

18 lines
518 B
Python
Raw Normal View History

2021-03-11 20:43:54 +00:00
from pyrogram.errors import RPCError
2019-01-30 20:52:05 +00:00
from .client import get_client
from .models import Chat, AggregationSource
def aggregation_source_deleted(sender, instance: AggregationSource, **kwargs):
if not AggregationSource.objects.filter(chat_id=instance.chat_id):
Chat.objects.filter(chat_id=instance.chat_id).delete()
def chat_deleted(sender, instance: Chat, **kwargs):
with get_client() as client:
try:
client.leave_chat(instance.chat_id)
2021-03-11 20:43:54 +00:00
except RPCError:
2019-01-30 20:52:05 +00:00
pass