moved to user' object & fixes
This commit is contained in:
27
bot/bot.py
27
bot/bot.py
@ -5,19 +5,17 @@ from secret import TOKEN
|
||||
import textbook
|
||||
import re
|
||||
from urllib.parse import urlparse, urlunparse
|
||||
from msgprocessor import (
|
||||
TrackerRemovalMsgProcessor,
|
||||
TrackerRemovalProcessorMessage
|
||||
)
|
||||
import random
|
||||
|
||||
HAS_LINK_RE = r'(https?:\/\/[^\s]+|www\.[^\s]+)'
|
||||
from msgprocessor import TrackerRemovalMsgProcessor, TrackerRemovalProcessorMessage
|
||||
|
||||
HAS_LINK_RE = r"(https?:\/\/[^\s]+|www\.[^\s]+)"
|
||||
|
||||
bot = AsyncTeleBot(TOKEN)
|
||||
|
||||
|
||||
def extract_links(text: str):
|
||||
url_pattern = r'(https?://[^\s]+|www\.[^\s]+)'
|
||||
url_pattern = r"(https?://[^\s]+|www\.[^\s]+)"
|
||||
links = re.findall(url_pattern, text)
|
||||
return links
|
||||
|
||||
@ -54,26 +52,25 @@ async def got_message(msg: Message):
|
||||
return
|
||||
if msg.from_user is None:
|
||||
return
|
||||
if msg.from_user.username is None:
|
||||
return
|
||||
|
||||
tracker_removal_result = TrackerRemovalMsgProcessor(
|
||||
TrackerRemovalProcessorMessage(
|
||||
fromUsername=msg.from_user.username,
|
||||
text=msg.text
|
||||
)
|
||||
TrackerRemovalProcessorMessage(fromUser=msg.from_user, text=msg.text)
|
||||
).process()
|
||||
|
||||
if not tracker_removal_result.needsToReply:
|
||||
return
|
||||
|
||||
try:
|
||||
await bot.delete_message(msg.chat.id, msg.id, 5)
|
||||
await bot.delete_message(msg.chat.id, msg.id, timeout=5)
|
||||
except Exception as e:
|
||||
print(e) # todo: логгер
|
||||
await bot.reply_to(
|
||||
message=msg.id,
|
||||
text="Uoghhhh, i am not an admin here? I can't cleanup this tracking(",
|
||||
)
|
||||
print(e, flush=True) # todo: логгер
|
||||
return
|
||||
|
||||
await bot.send_message(msg.chat.id, tracker_removal_result.text)
|
||||
await bot.send_message(msg.chat.id, tracker_removal_result.text, parse_mode="html")
|
||||
|
||||
|
||||
async def main():
|
||||
|
||||
Reference in New Issue
Block a user