koishi-plugin-noah 1.0.1 → 1.0.3

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.
@@ -19,5 +19,5 @@ export declare class UserService {
19
19
  * @param cid Channel ID
20
20
  * @param serverId Server ID
21
21
  */
22
- updateChannelDefaultServer(cid: string, serverId: number): Promise<void>;
22
+ updateChannelDefaultServer(platform: string, cid: string, serverId: number): Promise<void>;
23
23
  }
package/lib/index.js CHANGED
@@ -450,8 +450,8 @@ var UserService = class {
450
450
  * @param cid Channel ID
451
451
  * @param serverId Server ID
452
452
  */
453
- async updateChannelDefaultServer(cid, serverId) {
454
- await this.ctx.database.set("channel", cid, { defaultServerId: serverId });
453
+ async updateChannelDefaultServer(platform, cid, serverId) {
454
+ await this.ctx.database.setChannel(platform, cid, { defaultServerId: serverId });
455
455
  }
456
456
  };
457
457
 
@@ -737,7 +737,6 @@ function hasPermission(...perms) {
737
737
  }
738
738
  __name(hasPermission, "hasPermission");
739
739
  function isPluginAdmin(session, config) {
740
- console.log(config.adminUsers, session.userId);
741
740
  return config.adminUsers?.includes(session.userId) ?? false;
742
741
  }
743
742
  __name(isPluginAdmin, "isPluginAdmin");
@@ -849,7 +848,7 @@ async function showServerMenu(ctx, session, serverService, userService, server2,
849
848
  return session.text("commands.timeout");
850
849
  const selectNum = parseInt(select, 10);
851
850
  if (isNaN(selectNum) || selectNum < 0 || selectNum > 4) {
852
- return await session.text(".invalid-select");
851
+ return session.text(".invalid-select");
853
852
  }
854
853
  if (selectNum === 0) {
855
854
  if (from === "user")
@@ -865,7 +864,7 @@ async function showServerMenu(ctx, session, serverService, userService, server2,
865
864
  } else {
866
865
  if (channelDefaultServerId === server2.id)
867
866
  return session.text(".menu-1-error-duplicate");
868
- await userService.updateChannelDefaultServer(cid, server2.id);
867
+ await userService.updateChannelDefaultServer(session.platform, cid, server2.id);
869
868
  }
870
869
  return session.text(".menu-1-success");
871
870
  }
@@ -894,9 +893,9 @@ async function showServerMenu(ctx, session, serverService, userService, server2,
894
893
  if (channelDefaultServerId === server2.id) {
895
894
  const res = await serverService.getServersByCid(cid);
896
895
  if (res.length === 0) {
897
- await userService.updateChannelDefaultServer(cid, 0);
896
+ await userService.updateChannelDefaultServer(session.platform, cid, 0);
898
897
  } else {
899
- await userService.updateChannelDefaultServer(cid, res[0].id);
898
+ await userService.updateChannelDefaultServer(session.platform, cid, res[0].id);
900
899
  }
901
900
  }
902
901
  }
@@ -926,7 +925,7 @@ async function addServer(ctx, session, serverService, userService, from, uid, us
926
925
  return session.text("commands.timeout");
927
926
  const selectNum = parseInt(select, 10);
928
927
  if (isNaN(selectNum) || selectNum < 1 || selectNum > serverValues.length) {
929
- return await session.text(".invalid-select");
928
+ return session.text(".invalid-select");
930
929
  }
931
930
  const serverType = serverValues[selectNum - 1];
932
931
  await session.send(session.text(".add-url"));
@@ -939,24 +938,25 @@ async function addServer(ctx, session, serverService, userService, from, uid, us
939
938
  return session.text("commands.timeout");
940
939
  if (serverName.includes(" "))
941
940
  return session.text(".add-invalid-name");
942
- const res = from === "user" ? await serverService.createServerForUser({
943
- type: serverType,
944
- name: serverName,
945
- baseUrl: url,
946
- supportedGames: []
947
- }, uid) : await serverService.createServerForChannel({
948
- type: serverType,
949
- name: serverName,
950
- baseUrl: url,
951
- supportedGames: []
952
- }, cid);
953
941
  if (from === "user") {
942
+ const res = await serverService.createServerForUser({
943
+ type: serverType,
944
+ name: serverName,
945
+ baseUrl: url,
946
+ supportedGames: []
947
+ }, uid);
954
948
  if (userDefaultServerId === 0) {
955
949
  await userService.updateUserDefaultServer(uid, res.id);
956
950
  }
957
951
  } else {
952
+ const res = await serverService.createServerForChannel({
953
+ type: serverType,
954
+ name: serverName,
955
+ baseUrl: url,
956
+ supportedGames: []
957
+ }, cid);
958
958
  if (channelDefaultServerId === 0) {
959
- await userService.updateChannelDefaultServer(cid, res.id);
959
+ await userService.updateChannelDefaultServer(session.platform, cid, res.id);
960
960
  }
961
961
  }
962
962
  return session.text(".add-success", { serverName, serverType });
@@ -1291,7 +1291,7 @@ function calculateVolforce(raw_score) {
1291
1291
  const gradeFactor = GRADE_FACTORS[grade];
1292
1292
  const clearFactor = CLEAR_FACTORS[clearType];
1293
1293
  const volforce = level * score * gradeFactor * clearFactor * 2e-6;
1294
- return Math.round(volforce) / 20;
1294
+ return Math.floor(volforce) / 20;
1295
1295
  }
1296
1296
  __name(calculateVolforce, "calculateVolforce");
1297
1297
 
@@ -1357,6 +1357,25 @@ var SDVXService2 = class _SDVXService {
1357
1357
  };
1358
1358
  return diffStrMap[diffType] || "novice";
1359
1359
  }
1360
+ /**
1361
+ * Get the user name/ID from the server response
1362
+ * @param ctx Context object
1363
+ * @param url Base URL for the API
1364
+ * @param cardId Card ID of the player
1365
+ * @returns The player ID (e.g., "ED*")
1366
+ */
1367
+ async getUserName(ctx, url, cardId) {
1368
+ try {
1369
+ const response = await ctx.http.get(`/my?card=${cardId}`, { baseURL: url, responseType: "text" });
1370
+ const match = response.match(/猫网玩家\[([^\]]+)\]/);
1371
+ if (!match || !match[1]) {
1372
+ throw new Error("Failed to extract player ID from response");
1373
+ }
1374
+ return match[1];
1375
+ } catch (error) {
1376
+ throw error;
1377
+ }
1378
+ }
1360
1379
  async getAllScore(ctx, url, cardId, config) {
1361
1380
  try {
1362
1381
  const data = await ctx.http.get(`/sdvx/scores?card=${cardId}`, { baseURL: url, responseType: "json" });
@@ -2077,16 +2096,53 @@ var SDVXDrawer = class extends BaseDrawer {
2077
2096
  subTitle = score.music_data.sub_title_name;
2078
2097
  }
2079
2098
  }
2080
- const wrappedText = this.wrapText(ctx, mainTitle, 413);
2081
- wrappedText.forEach((line, index) => {
2082
- ctx.fillText(line, x + 388, y + 90 + index * 30);
2083
- });
2084
- ctx.fillStyle = "rgba(255, 255, 255, 0.7)";
2085
- const wrappedSubTitle = this.wrapText(ctx, subTitle, 413);
2086
- const startY2 = y + 388 + wrappedText.length * 30;
2087
- wrappedSubTitle.forEach((line, index) => {
2088
- ctx.fillText(line, x + 388, startY2 + index * 28);
2089
- });
2099
+ const totalAvailableWidth = 413;
2100
+ ctx.font = '400 24px "Noto Sans JP"';
2101
+ const mainTitleWidth = ctx.measureText(mainTitle).width;
2102
+ let displayMainTitle = mainTitle;
2103
+ if (subTitle) {
2104
+ const mainTitleMaxWidth = totalAvailableWidth * 0.7;
2105
+ if (mainTitleWidth > mainTitleMaxWidth) {
2106
+ let fitLength = 0;
2107
+ for (let i2 = 1; i2 <= mainTitle.length; i2++) {
2108
+ if (ctx.measureText(mainTitle.substring(0, i2)).width > mainTitleMaxWidth) {
2109
+ fitLength = i2 - 1;
2110
+ break;
2111
+ }
2112
+ }
2113
+ displayMainTitle = mainTitle.substring(0, fitLength);
2114
+ }
2115
+ ctx.fillStyle = "#FFFFFF";
2116
+ ctx.fillText(displayMainTitle, x + 388, y + 90);
2117
+ ctx.fillStyle = "rgba(255, 255, 255, 0.7)";
2118
+ const actualMainTitleWidth = ctx.measureText(displayMainTitle).width;
2119
+ const remainingWidth = totalAvailableWidth - actualMainTitleWidth - 10;
2120
+ let displaySubTitle = subTitle;
2121
+ if (ctx.measureText(subTitle).width > remainingWidth) {
2122
+ let fitLength = 0;
2123
+ for (let i2 = 1; i2 <= subTitle.length; i2++) {
2124
+ if (ctx.measureText(subTitle.substring(0, i2)).width > remainingWidth) {
2125
+ fitLength = i2 - 1;
2126
+ break;
2127
+ }
2128
+ }
2129
+ displaySubTitle = subTitle.substring(0, fitLength);
2130
+ }
2131
+ ctx.fillText(displaySubTitle, x + 388 + actualMainTitleWidth + 10, y + 90);
2132
+ } else {
2133
+ if (mainTitleWidth > totalAvailableWidth) {
2134
+ let fitLength = 0;
2135
+ for (let i2 = 1; i2 <= mainTitle.length; i2++) {
2136
+ if (ctx.measureText(mainTitle.substring(0, i2)).width > totalAvailableWidth) {
2137
+ fitLength = i2 - 1;
2138
+ break;
2139
+ }
2140
+ }
2141
+ displayMainTitle = mainTitle.substring(0, fitLength);
2142
+ }
2143
+ ctx.fillStyle = "#FFFFFF";
2144
+ ctx.fillText(displayMainTitle, x + 388, y + 90);
2145
+ }
2090
2146
  ctx.fillStyle = "#FFFFFF";
2091
2147
  const grade = score.music.score_grade;
2092
2148
  if (gradeImages[grade]) {
@@ -2332,7 +2388,7 @@ function vf(ctx, config) {
2332
2388
  const sdvxDrawer = drawerManager.getDrawer("sdvx");
2333
2389
  const imageBuffer = await sdvxDrawer.generateVFImage({
2334
2390
  scores: scoreList,
2335
- playerName: card2.name || "Unknown Player",
2391
+ playerName: await sdvxService.getUserName(ctx, server2.baseUrl, card2.code),
2336
2392
  config
2337
2393
  }, {
2338
2394
  lossless: options.lossless || false
@@ -13,6 +13,14 @@ export declare class SDVXService implements ISDVXService {
13
13
  * @returns The difficulty string (novice, advanced, exhaust, infinite, maximum)
14
14
  */
15
15
  private getDifficultyString;
16
+ /**
17
+ * Get the user name/ID from the server response
18
+ * @param ctx Context object
19
+ * @param url Base URL for the API
20
+ * @param cardId Card ID of the player
21
+ * @returns The player ID (e.g., "ED*")
22
+ */
23
+ getUserName(ctx: Context, url: string, cardId: string): Promise<string>;
16
24
  getAllScore(ctx: Context, url: string, cardId: string, config: SDVXConfig): Promise<SDVXScore[]>;
17
25
  getScore(ctx: Context, url: string, cardId: string, musicId: number, config: SDVXConfig): Promise<SDVXScore>;
18
26
  getRecentScores(ctx: Context, url: string, cardId: string, count: number, config: SDVXConfig): Promise<SDVXScore[]>;
@@ -46,6 +46,14 @@ export interface SDVXService extends GameService {
46
46
  * @throws Error if the fetch operation fails
47
47
  */
48
48
  getRecentScores(ctx: Context, url: string, cardId: string, count?: number, config?: SDVXConfig): Promise<SDVXScore[]>;
49
+ /**
50
+ * Get the user name/ID from the server response
51
+ * @param ctx Context object
52
+ * @param url Base URL for the API
53
+ * @param cardId Card ID of the player
54
+ * @returns The player ID (e.g., "ED*")
55
+ */
56
+ getUserName(ctx: Context, url: string, cardId: string): Promise<string>;
49
57
  }
50
58
  export interface IServer {
51
59
  name: TServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-noah",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "contributors": [
5
5
  "Logthm <logthm@outlook.com>"
6
6
  ],