removal of tags

This commit is contained in:
2023-12-27 11:10:58 -05:00
parent 6241b57172
commit 62a412b465

29
bot.py
View File

@@ -6,7 +6,7 @@ from telethon import TelegramClient, events
from telethon.tl.types import InputChannel
from telethon.errors import FloodWaitError
import asyncio, json, time, sys, yaml, os, time
import asyncio, json, time, sys, yaml, os, time, re
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from datetime import (
datetime,
@@ -20,6 +20,14 @@ job_defaults = {
'max_instances': 1
}
# Regexp patterns to remove from group
patterns = [
'https:\/\/t.me\/\w*',
'@[Ww]hite[Aa]ction'
]
combined_patterns = r'|'.join(map(r'(?:{})'.format, patterns))
# Start Scheduler
scheduler = AsyncIOScheduler(job_defaults=job_defaults)
@@ -65,29 +73,38 @@ async def _indexer(client, config):
path = await client.download_media(message.media, file='usermedia/', progress_callback=callback)
if path is not None:
if message.text:
logging.info(f'Sending file to {output_channel}.')
txt = re.sub(combined_patterns, '', message.text)
await client.send_file(
output_channel,
path,
caption=message.text
caption=txt
)
else:
await client.send_file(
output_channel,
path
)
# Remove file after upload
os.remove(path)
else:
if message.text:
elif message.text:
logging.info(f'Sending message to {output_channel}..')
txt = re.sub(combined_patterns, '', message.text)
await client.send_message(
output_channel,
message.text
txt
)
elif message.text:
logging.info(f'Sending message to {output_channel}.')
txt = re.sub(combined_patterns, '', message.text)
await client.send_message(
output_channel,
message.text
txt
)
except FloodWaitError as e:
logging.error(f'Flood wait for {e.seconds} for _indexer.')