31 lines
802 B
Python
31 lines
802 B
Python
from dataclasses import dataclass
|
|
|
|
from pyrogram.types import CallbackQuery
|
|
|
|
|
|
@dataclass
|
|
class CallbackLanguage:
|
|
__slots__ = ("language",)
|
|
|
|
language: str
|
|
|
|
@classmethod
|
|
def from_callback(cls, callback: CallbackQuery):
|
|
"""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.
|
|
"""
|
|
action, language = str(callback.data).split(":")
|
|
|
|
if action.lower() != "language":
|
|
raise ValueError("Callback provided is not a language callback")
|
|
|
|
return cls(language)
|