Banned users env, access validator, removed silent command, code quality improvements

This commit is contained in:
miloszowi
2021-10-08 15:25:47 +02:00
parent d05d0c0904
commit 431b004284
28 changed files with 268 additions and 261 deletions

View File

@@ -1,19 +1,18 @@
from __future__ import annotations
import re
from dataclasses import dataclass
import names
from entity.group import Group
from exception.invalidArgumentException import InvalidArgumentException
from telegram.ext.callbackcontext import CallbackContext
from telegram.update import Update
from entity.group import Group
from validator.accessValidator import AccessValidator
from validator.groupNameValidator import GroupNameValidator
@dataclass
class MessageData():
class MessageData:
user_id: str
chat_id: str
group_name: str
@@ -21,6 +20,9 @@ class MessageData():
@staticmethod
def create_from_arguments(update: Update, context: CallbackContext, include_group: bool = True) -> MessageData:
user_id = str(update.effective_user.id)
AccessValidator.validate(user_id)
chat_id = str(update.effective_chat.id)
group_name = Group.default_name
@@ -31,9 +33,7 @@ class MessageData():
if group_name is not Group.default_name:
chat_id += f'~{group_name}'
user_id = str(update.effective_user.id)
username = update.effective_user.username or update.effective_user.first_name
if not username:

View File

@@ -0,0 +1,29 @@
from telegram import Update
from telegram.utils.helpers import mention_markdown
from bot.message.messageData import MessageData
from logger import Logger
class Replier:
@staticmethod
def interpolate(content: str, message_data: MessageData):
return content.format(
mention_markdown(message_data.user_id, message_data.username),
message_data.group_name
)
@staticmethod
def markdown(update: Update, message: str) -> None:
try:
update.effective_message.reply_markdown_v2(message)
except Exception as err:
Logger.error(str(err))
@staticmethod
def html(update: Update, html: str) -> None:
try:
update.effective_message.reply_html(html)
except Exception as err:
Logger.error(str(err))