mirror of
https://github.com/MuRuLOSE/limoka.git
synced 2026-06-17 23:04:17 +02:00
Added and updated repositories 2026-01-10 01:09:56
This commit is contained in:
@@ -26,15 +26,29 @@
|
||||
# scope: Api AccountData 0.0.1
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
import aiohttp
|
||||
|
||||
from datetime import datetime
|
||||
from .. import loader, utils
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@loader.tds
|
||||
class AccountData(loader.Module):
|
||||
"""Find out the approximate date of registration of the telegram account"""
|
||||
|
||||
def __init__(self):
|
||||
self.config = loader.ModuleConfig(
|
||||
loader.ConfigValue(
|
||||
"api_token",
|
||||
"7518491974:1ea2284eec9dc40a9838cfbcb48a2b36",
|
||||
"API token for datereg.pro",
|
||||
validator=loader.validators.String(),
|
||||
)
|
||||
)
|
||||
|
||||
strings = {
|
||||
"name": "AccountData",
|
||||
"_cls_doc": "Find out the approximate date of registration of the telegram account",
|
||||
@@ -51,7 +65,10 @@ class AccountData(loader.Module):
|
||||
}
|
||||
|
||||
async def get_creation_date(self, user_id: int) -> str:
|
||||
api_token = "7518491974:1ea2284eec9dc40a9838cfbcb48a2b36"
|
||||
api_token = self.config.get("api_token", "")
|
||||
if not api_token:
|
||||
return {"error": "API token not configured"}
|
||||
|
||||
url = "https://api.datereg.pro/api/v1/users/getCreationDateFast"
|
||||
params = {"token": api_token, "user_id": user_id}
|
||||
|
||||
@@ -76,16 +93,22 @@ class AccountData(loader.Module):
|
||||
async def accdata(self, message):
|
||||
if reply := await message.get_reply_message():
|
||||
result = await self.get_creation_date(user_id=reply.sender.id)
|
||||
month, year = map(int, result['creation_date'].split('.'))
|
||||
date_object = datetime(year, month, 1)
|
||||
formatted = date_object.strftime('%B %Y')
|
||||
|
||||
if "error" in result:
|
||||
await utils.answer(message, f"Ошибка: {result['error']}")
|
||||
else:
|
||||
|
||||
if "error" in result or not result.get("creation_date"):
|
||||
error_msg = result.get("error", "Unknown error occurred")
|
||||
await utils.answer(message, f"Ошибка: {error_msg}")
|
||||
return
|
||||
|
||||
try:
|
||||
month, year = map(int, result['creation_date'].split('.'))
|
||||
date_object = datetime(year, month, 1)
|
||||
formatted = date_object.strftime('%B %Y')
|
||||
|
||||
await utils.answer(
|
||||
message,
|
||||
f"{self.strings('date_text').format(data=formatted, accuracy=result['accuracy_percent'])}\n\n{self.strings('date_text_ps')}",
|
||||
)
|
||||
except (ValueError, KeyError) as e:
|
||||
await utils.answer(message, f"Ошибка обработки данных: {str(e)}")
|
||||
else:
|
||||
await utils.answer(message, self.strings("no_reply"))
|
||||
|
||||
Reference in New Issue
Block a user