Add country support for Apple app commands

Refactored Apple app-related commands and data structures to include country information, allowing users to specify a country when adding or querying Apple apps. Updated method signatures, command help texts, and output formatting to reflect this change. This improves accuracy for apps that require country-specific data.
This commit is contained in:
2025-11-07 14:21:04 +07:00
parent 7857f29a58
commit 59b03b6f9a
8 changed files with 31 additions and 40 deletions
@@ -19,7 +19,7 @@ public class AddAppleAppCommand extends BaseStoreScraperBotCommand {
AddAppleAppCommand() {
super(
"addapple",
"<id/appId>. Thêm Apple app vào danh sách theo dõi của nhóm. id: <i>iTunes 'trackId'</i>, appId: <i>iTunes 'bundleId'</i>");
"<id/appId> [country]. Thêm Apple app vào danh sách theo dõi của nhóm. id: <i>iTunes 'trackId'</i>, appId: <i>iTunes 'bundleId'</i>. Một số app cần country để hoạt động đúng, country mặc định là 'vn'");
}
@Override
@@ -39,6 +39,7 @@ public class AddAppleAppCommand extends BaseStoreScraperBotCommand {
var appId = arguments[0];
long id = -1;
var country = arguments.length == 2 ? arguments[1] : "vn";
AppleAppResponse response = null;
try {
try {
@@ -47,9 +48,9 @@ public class AddAppleAppCommand extends BaseStoreScraperBotCommand {
// Input không phải id, bỏ qua
}
if (id != -1) {
response = AppStoreScraper.app(new AppleAppRequest(id));
response = AppStoreScraper.app(new AppleAppRequest(id, country));
} else {
response = AppStoreScraper.app(new AppleAppRequest(appId));
response = AppStoreScraper.app(new AppleAppRequest(appId, country));
}
} catch (Exception e) {
log.error("request app error for appId: '{}', id: '{}'", appId, id, e);
@@ -69,9 +70,11 @@ public class AddAppleAppCommand extends BaseStoreScraperBotCommand {
return;
}
group.getAppleApps().add(new AppleAppInfo(appId));
group.getAppleApps().add(new AppleAppInfo(appId, country));
GroupRepository.INSTANCE.save(groupId, group);
StoreScrapeBotTelegramClient.INSTANCE.sendMessage(
chat.getId(), "Apple app <code>%s</code> added successfully".formatted(appId));
chat.getId(),
"Apple app <code>%s</code>, country <b>%s</b> added successfully"
.formatted(appId, country));
}
}
@@ -61,6 +61,8 @@ public class AddGoogleAppCommand extends BaseStoreScraperBotCommand {
group.getGoogleApps().add(new GoogleAppInfo(appId, country));
GroupRepository.INSTANCE.save(groupId, group);
StoreScrapeBotTelegramClient.INSTANCE.sendMessage(
chat.getId(), "Google app <code>%s</code> added successfully".formatted(appId));
chat.getId(),
"Google app <code>%s</code>, country <b>%s</b> added successfully"
.formatted(appId, country));
}
}
@@ -46,7 +46,7 @@ public class CheckAppCommand extends BaseStoreScraperBotCommand {
sb.append("\n");
for (var app : group.getAppleApps()) {
var appId = app.appId();
var updated = AppStoreScraper.getAppUpdated(appId);
var updated = AppStoreScraper.getAppUpdated(appId, app.country());
long days = ChronoUnit.DAYS.between(updated, now);
boolean passed = days <= Constant.NUM_DAYS_WARNING_NOT_UPDATED;
sb.append(
@@ -42,8 +42,9 @@ public class CheckAppScoreCommand extends BaseStoreScraperBotCommand {
sb.append("\n");
for (var app : group.getAppleApps()) {
var appId = app.appId();
double score = AppStoreScraper.getAppScore(appId);
long ratings = AppStoreScraper.getAppRatings(appId);
var country = app.country();
double score = AppStoreScraper.getAppScore(appId, country);
long ratings = AppStoreScraper.getAppRatings(appId, country);
sb.append("%-20s | %-10s | %-10s\n".formatted(appId, score, ratings));
}
sb.append("</code>\n");
@@ -35,13 +35,13 @@ public class ListAppCommand extends BaseStoreScraperBotCommand {
var sb = new StringBuilder();
sb.append("<b>Apple Apps:</b>\n");
sb.append("<code>\n");
sb.append("%-2s | %-20s\n".formatted("#", "AppId"));
sb.append("%-2s | %-20s | %-7s\n".formatted("#", "AppId", "Country"));
sb.append("-".repeat(25));
sb.append("\n");
int i = 0;
for (var app : group.getAppleApps()) {
i++;
sb.append("%-2d | %-20s\n".formatted(i,app.appId()));
sb.append("%-2s | %-20s | %-7s\n".formatted(i, app.appId(), app.country()));
}
sb.append("</code>\n");
sb.append("\n");