fix: use usinfobot for username resolving & update README

This commit is contained in:
AlexeyZavar 2025-06-02 15:52:31 +03:00
parent 0fab18e8e8
commit 3be793032f
4 changed files with 49 additions and 27 deletions

View file

@ -30,7 +30,7 @@
### Windows ### Windows
#### Официальный вариант #### Официальная версия
Вы можете скачать готовый бинарный файл со вкладки [Releases](https://github.com/AyuGram/AyuGramDesktop/releases) или из Вы можете скачать готовый бинарный файл со вкладки [Releases](https://github.com/AyuGram/AyuGramDesktop/releases) или из
[Телеграм канала](https://t.me/AyuGramReleases). [Телеграм канала](https://t.me/AyuGramReleases).
@ -55,8 +55,16 @@ scoop install ayugram
### macOS ### macOS
#### Официальная версия
Вы можете скачать подписанный пакет со вкладки [Releases](https://github.com/AyuGram/AyuGramDesktop/releases). Вы можете скачать подписанный пакет со вкладки [Releases](https://github.com/AyuGram/AyuGramDesktop/releases).
#### Homebrew
```bash
brew install --cask ayugram
```
### Arch Linux ### Arch Linux
Вы можете установить `ayugram-desktop` из [AUR](https://aur.archlinux.org/packages?O=0&K=ayugram). Вы можете установить `ayugram-desktop` из [AUR](https://aur.archlinux.org/packages?O=0&K=ayugram).
@ -101,3 +109,8 @@ scoop install ayugram
### Иконки ### Иконки
- [Solar Icon Set](https://www.figma.com/community/file/1166831539721848736) - [Solar Icon Set](https://www.figma.com/community/file/1166831539721848736)
### Боты
- [TelegramDB](https://t.me/tgdatabase) для получения юзернейма по ID (до закрытия бесплатной версии 25 мая 2025)
- [usinfobot](https://t.me/usinfobot) для получения юзернейма по ID

View file

@ -110,3 +110,8 @@ Enjoy using **AyuGram**? Consider sending us a tip!
### Icons ### Icons
- [Solar Icon Set](https://www.figma.com/community/file/1166831539721848736) - [Solar Icon Set](https://www.figma.com/community/file/1166831539721848736)
### Bots
- [TelegramDB](https://t.me/tgdatabase) for username lookup by ID (until closing free inline mode at 25 May 2025)
- [usinfobot](https://t.me/usinfobot) for username lookup by ID

View file

@ -38,6 +38,14 @@
#include "ayu/ayu_state.h" #include "ayu/ayu_state.h"
#include "ayu/data/messages_storage.h" #include "ayu/data/messages_storage.h"
namespace {
constexpr auto usernameResolverBotId = 189165596L;
const auto usernameResolverBotUsername = QString("usinfobot");
const auto usernameResolverEmpty = QString("¯\\_(ツ)_/¯");
}
Main::Session *getSession(ID userId) { Main::Session *getSession(ID userId) {
for (const auto &[index, account] : Core::App().domain().accounts()) { for (const auto &[index, account] : Core::App().domain().accounts()) {
if (const auto session = account->maybeSession()) { if (const auto session = account->maybeSession()) {
@ -526,7 +534,7 @@ void processMessageDelete(not_null<HistoryItem*> item) {
} }
} }
void resolveUser(ID userId, const QString &username, Main::Session *session, const Callback &callback) { void resolveUser(ID userId, const QString &username, Main::Session *session, const UsernameResolverCallback &callback) {
auto normalized = username.trimmed().toLower(); auto normalized = username.trimmed().toLower();
if (normalized.isEmpty()) { if (normalized.isEmpty()) {
callback(QString(), nullptr); callback(QString(), nullptr);
@ -566,19 +574,18 @@ void resolveUser(ID userId, const QString &username, Main::Session *session, con
}).send(); }).send();
} }
void searchUser(long long userId, Main::Session *session, bool searchUserFlag, const Callback &callback) { void searchUser(long long userId, Main::Session *session, bool searchUserFlag, const UsernameResolverCallback &callback) {
if (!session) { if (!session) {
callback(QString(), nullptr); callback(QString(), nullptr);
return; return;
} }
constexpr auto botId = 1696868284; const auto bot = session->data().userLoaded(usernameResolverBotId);
const auto bot = session->data().userLoaded(botId);
if (!bot) { if (!bot) {
if (searchUserFlag) { if (searchUserFlag) {
resolveUser(botId, resolveUser(usernameResolverBotId,
"tgdb_bot", usernameResolverBotUsername,
session, session,
[=](const QString &title, UserData *data) [=](const QString &title, UserData *data)
{ {
@ -649,29 +656,26 @@ void searchUser(long long userId, Main::Session *session, bool searchUserFlag, c
return QString(); return QString();
}); });
if (text.isEmpty()) { if (text.isEmpty() || text.startsWith(usernameResolverEmpty)) {
continue; continue;
} }
ID id = 0; // 🆔 ID id = 0; // 👤
QString title; // 🏷 QString title; // 👦🏻
QString username; // 📧 QString username; // 🌐
for (const auto &line : text.split('\n')) { for (auto &line : text.split('\n')) {
if (line.startsWith("🆔")) { line = line.replace("", "");
id = line.mid(line.indexOf(':') + 1).toLongLong(); if (line.startsWith("👤")) {
} else if (line.startsWith("🏷")) { id = line.mid(line.indexOf(' ') + 1).toLongLong();
title = line.mid(line.indexOf(':') + 1); } else if (line.startsWith("👦🏻")) {
} else if (line.startsWith("📧")) { title = line.mid(line.indexOf(' ') + 1);
username = line.mid(line.indexOf(':') + 1); } else if (line.startsWith("🌐")) {
username = line.mid(line.indexOf(' ') + 1);
} }
} }
if (id == 0) { if (id == 0 || id != userId) {
continue;
}
if (id != userId) {
continue; continue;
} }
@ -702,7 +706,7 @@ void searchUser(long long userId, Main::Session *session, bool searchUserFlag, c
}).handleAllErrors().send(); }).handleAllErrors().send();
} }
void searchById(ID userId, Main::Session *session, const Callback &callback) { void searchById(ID userId, Main::Session *session, const UsernameResolverCallback &callback) {
if (userId == 0 || !session) { if (userId == 0 || !session) {
callback(QString(), nullptr); callback(QString(), nullptr);
return; return;

View file

@ -13,7 +13,7 @@
#include "info/profile/info_profile_badge.h" #include "info/profile/info_profile_badge.h"
#include "main/main_domain.h" #include "main/main_domain.h"
using Callback = Fn<void(const QString &, UserData *)>; using UsernameResolverCallback = Fn<void(const QString &, UserData *)>;
Main::Session *getSession(ID userId); Main::Session *getSession(ID userId);
void dispatchToMainThread(std::function<void()> callback, int delay = 0); void dispatchToMainThread(std::function<void()> callback, int delay = 0);
@ -51,7 +51,7 @@ int getScheduleTime(int64 sumSize);
bool isMessageSavable(not_null<HistoryItem *> item); bool isMessageSavable(not_null<HistoryItem *> item);
void processMessageDelete(not_null<HistoryItem *> item); void processMessageDelete(not_null<HistoryItem *> item);
void searchById(ID userId, Main::Session *session, bool retry, const Callback &callback); void searchById(ID userId, Main::Session *session, bool retry, const UsernameResolverCallback &callback);
void searchById(ID userId, Main::Session *session, const Callback &callback); void searchById(ID userId, Main::Session *session, const UsernameResolverCallback &callback);
ID getUserIdFromPackId(uint64 id); ID getUserIdFromPackId(uint64 id);