mirror of
https://github.com/Eyre-S/Coeur-Morny-Cono.git
synced 2024-11-23 03:27:39 +08:00
获取用户数据实验性的支持了获取用户所在dc (cdn) #6
This commit is contained in:
parent
79e61e28a2
commit
82c9faea1e
@ -1,6 +1,6 @@
|
|||||||
## Core
|
## Core
|
||||||
|
|
||||||
VERSION = 0.6.0.2
|
VERSION = 0.7.0.0
|
||||||
|
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|
||||||
|
@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny;
|
|||||||
* the final field that will be updated by gradle automatically.
|
* the final field that will be updated by gradle automatically.
|
||||||
*/
|
*/
|
||||||
public class GradleProjectConfigures {
|
public class GradleProjectConfigures {
|
||||||
public static final String VERSION = "0.6.0.2";
|
public static final String VERSION = "0.7.0.0";
|
||||||
public static final long COMPILE_TIMESTAMP = 1647237887029L;
|
public static final long COMPILE_TIMESTAMP = 1647369713069L;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,40 @@
|
|||||||
package cc.sukazyo.cono.morny.util;
|
package cc.sukazyo.cono.morny.util;
|
||||||
|
|
||||||
import com.pengrad.telegrambot.model.User;
|
import com.pengrad.telegrambot.model.User;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
import static cc.sukazyo.untitled.util.telegram.formatting.MsgEscape.escapeHtml;
|
||||||
public class TelegramUserInformation {
|
public class TelegramUserInformation {
|
||||||
|
|
||||||
|
public static final String DC_QUERY_SOURCE_SITE = "https://t.me/";
|
||||||
|
public static final Pattern DC_QUERY_PROCESSOR_REGEX = Pattern.compile("(cdn[1-9]).tele(sco.pe|gram-cdn.org)");
|
||||||
|
|
||||||
|
private static final OkHttpClient httpClient = new OkHttpClient();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static String getDataCenterFromUsername (String username) {
|
||||||
|
final Request request = new Request.Builder().url(DC_QUERY_SOURCE_SITE + username).build();
|
||||||
|
try (Response response = httpClient.newCall(request).execute()) {
|
||||||
|
final ResponseBody body = response.body();
|
||||||
|
if (body == null) return "empty upstream response";
|
||||||
|
final Matcher matcher = DC_QUERY_PROCESSOR_REGEX.matcher(body.string());
|
||||||
|
if (matcher.find()) {
|
||||||
|
return matcher.group(1);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static String informationOutputHTML (User user) {
|
public static String informationOutputHTML (User user) {
|
||||||
|
|
||||||
final StringBuilder userInformation = new StringBuilder();
|
final StringBuilder userInformation = new StringBuilder();
|
||||||
@ -15,7 +45,7 @@ public class TelegramUserInformation {
|
|||||||
user.id()
|
user.id()
|
||||||
));
|
));
|
||||||
if (user.username() == null) {
|
if (user.username() == null) {
|
||||||
userInformation.append("\nusername : <u>null</u>");
|
userInformation.append("\nusername : <u>null</u>\ndatacenter : <u>null</u>");
|
||||||
} else {
|
} else {
|
||||||
userInformation.append(String.format(
|
userInformation.append(String.format(
|
||||||
"""
|
"""
|
||||||
@ -24,6 +54,10 @@ public class TelegramUserInformation {
|
|||||||
- <code>%s</code>""",
|
- <code>%s</code>""",
|
||||||
escapeHtml(user.username())
|
escapeHtml(user.username())
|
||||||
));
|
));
|
||||||
|
// 依赖 username 的 datacenter 查询
|
||||||
|
final String dataCenter = getDataCenterFromUsername(user.username());
|
||||||
|
if (dataCenter == null) { userInformation.append("\ndatacenter : <u>null</u>"); }
|
||||||
|
else { userInformation.append(String.format("\ndatacenter : <code>%s</code>", escapeHtml(dataCenter))); }
|
||||||
}
|
}
|
||||||
if (user.firstName() == null) {
|
if (user.firstName() == null) {
|
||||||
userInformation.append("\nfirstname : <u>null</u>");
|
userInformation.append("\nfirstname : <u>null</u>");
|
||||||
|
Loading…
Reference in New Issue
Block a user