2021-09-25 16:49:11 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-10-06 19:44:03 +02:00
|
|
|
from dataclasses import dataclass
|
2021-09-28 17:03:11 +02:00
|
|
|
|
2021-09-25 16:49:11 +02:00
|
|
|
import names
|
2021-10-06 19:44:03 +02:00
|
|
|
from telegram.ext.callbackcontext import CallbackContext
|
|
|
|
from telegram.update import Update
|
2021-09-25 16:49:11 +02:00
|
|
|
|
2021-10-08 15:25:47 +02:00
|
|
|
from entity.group import Group
|
|
|
|
from validator.accessValidator import AccessValidator
|
2021-10-07 19:15:53 +02:00
|
|
|
from validator.groupNameValidator import GroupNameValidator
|
|
|
|
|
2021-09-25 16:49:11 +02:00
|
|
|
|
2021-09-28 17:03:11 +02:00
|
|
|
@dataclass
|
2021-10-08 15:25:47 +02:00
|
|
|
class MessageData:
|
2021-09-28 17:03:11 +02:00
|
|
|
user_id: str
|
|
|
|
chat_id: str
|
2021-10-06 19:44:03 +02:00
|
|
|
group_name: str
|
2021-09-25 16:49:11 +02:00
|
|
|
username: str
|
|
|
|
|
|
|
|
@staticmethod
|
2021-10-06 19:44:03 +02:00
|
|
|
def create_from_arguments(update: Update, context: CallbackContext, include_group: bool = True) -> MessageData:
|
2021-10-08 15:25:47 +02:00
|
|
|
user_id = str(update.effective_user.id)
|
|
|
|
AccessValidator.validate(user_id)
|
|
|
|
|
2021-09-28 17:03:11 +02:00
|
|
|
chat_id = str(update.effective_chat.id)
|
2021-10-06 19:44:03 +02:00
|
|
|
group_name = Group.default_name
|
|
|
|
|
2021-10-05 19:20:04 +02:00
|
|
|
if context.args and context.args[0] and include_group:
|
|
|
|
group_name = str(context.args[0]).lower()
|
2021-09-28 23:14:14 +02:00
|
|
|
|
2021-10-07 19:15:53 +02:00
|
|
|
GroupNameValidator.validate(group_name)
|
2021-09-28 23:14:14 +02:00
|
|
|
|
2021-10-07 19:15:53 +02:00
|
|
|
if group_name is not Group.default_name:
|
|
|
|
chat_id += f'~{group_name}'
|
2021-09-28 21:28:33 +02:00
|
|
|
|
2021-09-25 16:49:11 +02:00
|
|
|
username = update.effective_user.username or update.effective_user.first_name
|
|
|
|
|
|
|
|
if not username:
|
|
|
|
username = names.get_first_name()
|
|
|
|
|
2021-10-06 19:44:03 +02:00
|
|
|
return MessageData(user_id, chat_id, group_name, username)
|