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.
Files changed (2) hide show
  1. package/lib/index.js +28 -8
  2. 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 appId = await resolveApp(keyword);
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 `「${game}」未进入 App Store ${config.country.toUpperCase()} ${feedLabels[feedType]} Top ${actualLimit}
190
- ${formatUpdatedAt(updated)}
191
- 口径:Apple 公开榜单,只代表 iOS 排名,不代表全平台流水`;
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 appIds = await Promise.all(names.map(resolveApp));
222
+ const details = await Promise.all(names.map(resolveAppDetail));
209
223
  const results = names.map((game, index) => {
210
- const appId = appIds[index];
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) return `${game}:未进入畅销榜 Top ${actualLimit}`;
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} 名`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-apple-rank",
3
3
  "description": "给二游痴看流水用的,数据来自苹果的rss",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [