This repository has been archived on 2024-10-15. You can view files and clone it, but cannot push or open issues or pull requests.
PyrogramBotBase/classes/callbacks.py

29 lines
771 B
Python
Raw Normal View History

2023-08-17 16:01:35 +03:00
from dataclasses import dataclass
from pyrogram.types import CallbackQuery
@dataclass
class CallbackLanguage:
language: str
@classmethod
def from_callback(cls, callback: CallbackQuery):
2023-08-18 00:04:38 +03:00
"""Parse callback query and extract language data from it.
### Args:
* callback (`CallbackQuery`): Callback query got from user interaction.
### Raises:
* `ValueError`: Raised when callback provided is not a language one.
### Returns:
* `CallbackLanguage`: Parsed callback query.
"""
2023-08-17 16:01:35 +03:00
action, language = str(callback.data).split(":")
2023-08-18 00:04:38 +03:00
2023-08-17 16:01:35 +03:00
if action.lower() != "language":
raise ValueError("Callback provided is not a language callback")
2023-08-18 00:04:38 +03:00
2023-08-17 16:01:35 +03:00
return cls(language)