2021-09-25 16:49:11 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-09-28 17:03:11 +02:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
2021-09-25 16:49:11 +02:00
|
|
|
import names
|
|
|
|
from telegram.update import Update
|
|
|
|
|
|
|
|
|
2021-09-28 17:03:11 +02:00
|
|
|
@dataclass
|
2021-09-25 16:49:11 +02:00
|
|
|
class UpdateData():
|
2021-09-28 17:03:11 +02:00
|
|
|
user_id: str
|
|
|
|
chat_id: str
|
2021-09-25 16:49:11 +02:00
|
|
|
username: str
|
|
|
|
|
|
|
|
@staticmethod
|
2021-09-28 17:03:11 +02:00
|
|
|
def create_from_update(update: Update) -> UpdateData:
|
|
|
|
user_id = str(update.effective_user.id)
|
|
|
|
chat_id = str(update.effective_chat.id)
|
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-09-28 17:03:11 +02:00
|
|
|
return UpdateData(user_id, chat_id, username)
|