koishi-plugin-apple-rank 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +28 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -156,13 +156,24 @@ function apply(ctx, config) {
|
|
|
156
156
|
return results.find((result) => result.primaryGenreName === "Games")?.trackId.toString() || results[0]?.trackId.toString();
|
|
157
157
|
}
|
|
158
158
|
__name(resolveApp, "resolveApp");
|
|
159
|
+
async function resolveAppDetail(keyword) {
|
|
160
|
+
const presetId = config.aliases[keyword] || (/^\d+$/.test(keyword) ? keyword : void 0);
|
|
161
|
+
const results = await searchApp(keyword);
|
|
162
|
+
if (presetId) {
|
|
163
|
+
return results.find((result) => result.trackId.toString() === presetId) || results.find((result) => result.primaryGenreName === "Games") || results[0];
|
|
164
|
+
}
|
|
165
|
+
return results.find((result) => result.primaryGenreName === "Games") || results[0];
|
|
166
|
+
}
|
|
167
|
+
__name(resolveAppDetail, "resolveAppDetail");
|
|
159
168
|
async function findRank(keyword, feedType = "topgrossingapplications") {
|
|
160
|
-
const
|
|
169
|
+
const detail = await resolveAppDetail(keyword);
|
|
170
|
+
const appId = detail?.trackId.toString() || config.aliases[keyword] || (/^\d+$/.test(keyword) ? keyword : void 0);
|
|
161
171
|
if (!appId) return { appId: void 0, item: void 0 };
|
|
162
172
|
const feed = await fetchRanks(feedType);
|
|
163
173
|
return {
|
|
164
174
|
appId,
|
|
165
175
|
item: feed.ranks.find((item) => item.appId === appId),
|
|
176
|
+
detail,
|
|
166
177
|
updated: feed.updated,
|
|
167
178
|
actualLimit: feed.actualLimit
|
|
168
179
|
};
|
|
@@ -183,12 +194,15 @@ function apply(ctx, config) {
|
|
|
183
194
|
if (!game) return "请输入游戏名,例如:ios排名 王者荣耀";
|
|
184
195
|
const feedType = parseFeedType(options.type);
|
|
185
196
|
if (!feedType) return "榜单类型可用:畅销 / 免费 / 付费";
|
|
186
|
-
const { appId, item, updated, actualLimit } = await findRank(game, feedType);
|
|
197
|
+
const { appId, item, detail, updated, actualLimit } = await findRank(game, feedType);
|
|
187
198
|
if (!appId) return `没找到「${game}」对应的 App Store 应用`;
|
|
188
199
|
if (!item) {
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
|
|
200
|
+
return [
|
|
201
|
+
detail?.artworkUrl100 ? import_koishi.h.image(detail.artworkUrl100) : "",
|
|
202
|
+
`「${detail?.trackName || game}」未进入 App Store ${config.country.toUpperCase()} ${feedLabels[feedType]} Top ${actualLimit}`,
|
|
203
|
+
formatUpdatedAt(updated),
|
|
204
|
+
"口径:Apple 公开榜单,只代表 iOS 排名,不代表全平台流水"
|
|
205
|
+
].filter(Boolean).join("\n");
|
|
192
206
|
}
|
|
193
207
|
return [
|
|
194
208
|
item.icon ? import_koishi.h.image(item.icon) : "",
|
|
@@ -205,12 +219,18 @@ ${formatUpdatedAt(updated)}
|
|
|
205
219
|
if (names.length < 2) return "请输入至少两个游戏名,例如:ios对比 王者荣耀 原神";
|
|
206
220
|
const feed = await fetchRanks();
|
|
207
221
|
const actualLimit = feed.actualLimit || feed.ranks.length;
|
|
208
|
-
const
|
|
222
|
+
const details = await Promise.all(names.map(resolveAppDetail));
|
|
209
223
|
const results = names.map((game, index) => {
|
|
210
|
-
const
|
|
224
|
+
const detail = details[index];
|
|
225
|
+
const appId = detail?.trackId.toString() || config.aliases[game] || (/^\d+$/.test(game) ? game : void 0);
|
|
211
226
|
if (!appId) return `${game}:未找到应用`;
|
|
212
227
|
const item = feed.ranks.find((item2) => item2.appId === appId);
|
|
213
|
-
if (!item)
|
|
228
|
+
if (!item) {
|
|
229
|
+
return [
|
|
230
|
+
detail?.artworkUrl100 ? import_koishi.h.image(detail.artworkUrl100) : "",
|
|
231
|
+
`${detail?.trackName || game}:未进入畅销榜 Top ${actualLimit}`
|
|
232
|
+
].filter(Boolean).join("\n");
|
|
233
|
+
}
|
|
214
234
|
return [
|
|
215
235
|
item.icon ? import_koishi.h.image(item.icon) : "",
|
|
216
236
|
`${item.name}:第 ${item.rank} 名`
|