koishi-plugin-noah 2.4.1 → 2.4.4

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.
@@ -0,0 +1,26 @@
1
+ import { Context, Logger } from 'koishi';
2
+ import { SDVXScore } from '../../../games/sdvx/types';
3
+ import { GameService } from '../../../types';
4
+ import { SDVXConfig } from '../../../types/config';
5
+ export declare class SDVXService implements GameService {
6
+ private static instance;
7
+ logger: Logger;
8
+ private constructor();
9
+ static getInstance(logger: Logger): SDVXService;
10
+ /**
11
+ * 获取 refid
12
+ */
13
+ getRefid(ctx: Context, url: string, model: string, cardId: string): Promise<string>;
14
+ /**
15
+ * 获取用户名
16
+ */
17
+ getUserName(ctx: Context, url: string, cardId: string, model?: string): Promise<string>;
18
+ /**
19
+ * 获取所有分数
20
+ */
21
+ getAllScore(ctx: Context, url: string, cardId: string, config: SDVXConfig, model?: string): Promise<SDVXScore[]>;
22
+ /**
23
+ * 难度字符串映射
24
+ */
25
+ private getDifficultyString;
26
+ }
@@ -0,0 +1,44 @@
1
+ import { Context, Logger } from 'koishi';
2
+ import { SDVXScore } from '../../../games/sdvx/types';
3
+ import { SDVXService as ISDVXService } from '../../../types';
4
+ import { SDVXConfig } from '../../../types/config';
5
+ export declare class SDVXService implements ISDVXService {
6
+ private static instance;
7
+ logger: Logger;
8
+ private constructor();
9
+ static getInstance(logger: Logger): SDVXService;
10
+ /**
11
+ * Get the difficulty string based on the difficulty type number
12
+ * @param diffType Difficulty type
13
+ * @returns The difficulty string (novice, advanced, exhaust, infinite, maximum)
14
+ */
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>;
24
+ /**
25
+ * 验证猫网 PIN 码
26
+ * @param ctx - Koishi 上下文对象
27
+ * @param url - 猫网基础 URL
28
+ * @param cardId - 卡号
29
+ * @param pin - 四位数字 PIN
30
+ * @returns 验证是否通过
31
+ */
32
+ verifyPin(ctx: Context, url: string, cardId: string, pin: string): Promise<boolean>;
33
+ uploadScore(ctx: Context, url: string, cardId: string, scorePayload: {
34
+ music_id: string;
35
+ difficulties: Record<string, {
36
+ score: number;
37
+ mark: string;
38
+ grade: string;
39
+ }>;
40
+ }[]): Promise<boolean>;
41
+ getAllScore(ctx: Context, url: string, cardId: string, config: SDVXConfig): Promise<SDVXScore[]>;
42
+ getScore(ctx: Context, url: string, cardId: string, musicId: number, config: SDVXConfig): Promise<SDVXScore>;
43
+ getRecentScores(ctx: Context, url: string, cardId: string, config: SDVXConfig, count?: number): Promise<SDVXScore[]>;
44
+ }
@@ -0,0 +1,25 @@
1
+ import { Context, Logger } from 'koishi';
2
+ import { SDVXScore } from '../../../games/sdvx/types';
3
+ import { SDVXService as ISDVXService } from '../../../types';
4
+ import { SDVXConfig } from '../../../types/config';
5
+ export declare class SDVXService implements ISDVXService {
6
+ private static instance;
7
+ logger: Logger;
8
+ private constructor();
9
+ static getInstance(logger: Logger): SDVXService;
10
+ /**
11
+ * 映射 mark 到 SDVXClearType
12
+ */
13
+ private mapClearType;
14
+ /**
15
+ * Get the user name/ID from the server response
16
+ * @param ctx Context object
17
+ * @param url Base Official Support URL for the API
18
+ * @param player_id Player ID of the player (SV-xxxx-xxxx format)
19
+ * @returns The player name
20
+ */
21
+ getUserName(ctx: Context, url: string, player_id: string): Promise<string>;
22
+ getAllScore(ctx: Context, url: string, player_id: string, config: SDVXConfig): Promise<SDVXScore[]>;
23
+ getScore(ctx: Context, url: string, player_id: string, musicId: number, config: SDVXConfig): Promise<SDVXScore>;
24
+ getRecentScores(ctx: Context, url: string, player_id: string, config: SDVXConfig, count?: number): Promise<SDVXScore[]>;
25
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 根据难度类型和 infVer 获取难度缩写名称
3
+ * @param diffStr - 难度字符串 (novice, advanced, exhaust, infinite, maximum)
4
+ * @param infVer - infVer (2-6)
5
+ * @returns 难度缩写名称 (例如: "NOV", "ADV", "INF", "GRV" 等)
6
+ */
7
+ export declare function getDiffName(diffStr: string, infVer: string | number): string;
8
+ /**
9
+ * 根据难度类型和 infVer 获取完整难度名称
10
+ * @param diffStr - 难度字符串 (novice, advanced, exhaust, infinite, maximum)
11
+ * @param infVer - infVer (2-6)
12
+ * @returns 完整难度名称 (例如: "NOVICE", "ADVANCED", "INFINITE" 等)
13
+ */
14
+ export declare function getDiffFullName(diffStr: string, infVer: string | number): string;
15
+ /**
16
+ * 根据难度缩写名称获取难度字符串和 infVer
17
+ * @param diffAbbr - 难度缩写名称 (例如: "NOV", "ADV", "EXH", "INF", "GRV", "HVN", "VVD", "XCD", "MXM")
18
+ * @returns 包含难度字符串和 infVer 的对象,如果是非 infinite 难度则 infVer 为 null
19
+ */
20
+ export declare function getDiffStringFromAbbr(diffAbbr: string): {
21
+ diffStr: string;
22
+ infVer: number | null;
23
+ } | null;
@@ -0,0 +1,8 @@
1
+ import { SDVXClearType } from '../../games/sdvx/types';
2
+ export { getGradeByScore as getSDVXGrade } from '../../games/sdvx/constants';
3
+ /**
4
+ * 根据通关类型编号获取SDVX通关类型名称
5
+ * @param clearType - 通关类型编号
6
+ * @returns SDVX通关类型
7
+ */
8
+ export declare function getSDVXClearType(clearType: number): SDVXClearType;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 将 XML 字符串转换为 JSON
3
+ * @param xml - XML 格式的字符串
4
+ * @returns 解析后的 JSON 对象
5
+ * @throws 解析 XML 失败时抛出异常
6
+ */
7
+ export declare const xmlToJson: (xml: string) => Promise<any>;
8
+ /**
9
+ * 将 JSON 对象转换为 XML 字符串
10
+ * @param json - 要转换的 JavaScript 对象
11
+ * @returns XML 格式的字符串
12
+ */
13
+ export declare const jsonToXml: (json: any) => string;
@@ -1,4 +1,4 @@
1
- import { MessageReply, PromptReply } from '../fun/poke/types';
1
+ import { MessageReply } from '../fun/poke/types';
2
2
  import { SDVXConfig } from '../games/sdvx/types/config';
3
3
  export { SDVXConfig };
4
4
  /**
@@ -38,12 +38,6 @@ export interface CoreConfig extends BaseConfig {
38
38
  adminUsers?: string[];
39
39
  /** 群名片列表 */
40
40
  guildNameCards?: string[];
41
- /** Token 有效期(秒),默认 1800 */
42
- tokenTtl?: number;
43
- /** 前端面板 URL */
44
- frontendUrl?: string;
45
- /** CORS 允许的来源,默认 * */
46
- corsOrigin?: string;
47
41
  }
48
42
  /**
49
43
  * 戳一戳功能配置接口
@@ -55,7 +49,7 @@ export interface PokeConfig extends BaseConfig {
55
49
  /** 是否启用警告功能 */
56
50
  warning?: boolean;
57
51
  /** 提示消息列表 */
58
- prompt?: PromptReply[];
52
+ prompt?: MessageReply[];
59
53
  /** 消息回复列表 */
60
54
  messages?: MessageReply[];
61
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-noah",
3
- "version": "2.4.1",
3
+ "version": "2.4.4",
4
4
  "contributors": [
5
5
  "Logthm <logthm@outlook.com>"
6
6
  ],
@@ -23,10 +23,10 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@koishijs/plugin-server": "^3.2.9",
26
- "adm-zip": "^0.5.17",
27
- "bwip-js": "^4.10.1",
26
+ "adm-zip": "^0.5.18",
27
+ "bwip-js": "^4.11.2",
28
28
  "javascript-barcode-reader": "^0.6.9",
29
- "koishi-plugin-adapter-onebot": "^6.9.3",
29
+ "koishi-plugin-adapter-onebot": "^6.9.4",
30
30
  "sharp": "^0.33.5",
31
31
  "xml2js": "^0.6.2"
32
32
  },
@@ -56,11 +56,11 @@
56
56
  "eslint": "^9.39.4",
57
57
  "eslint-config-prettier": "^10.1.8",
58
58
  "eslint-import-resolver-typescript": "^3.10.1",
59
- "eslint-plugin-prettier": "^5.5.5",
59
+ "eslint-plugin-prettier": "^5.5.6",
60
60
  "husky": "^9.1.7",
61
61
  "koishi": "^4.18.11",
62
62
  "lint-staged": "^16.4.0",
63
- "prettier": "^3.8.3",
63
+ "prettier": "^3.9.4",
64
64
  "yml-register": "^1.2.5"
65
65
  },
66
66
  "scripts": {
@@ -81,4 +81,4 @@
81
81
  "prettier --write"
82
82
  ]
83
83
  }
84
- }
84
+ }
@@ -1,18 +0,0 @@
1
- export interface TokenPayload {
2
- uid: number;
3
- iat: number;
4
- exp: number;
5
- }
6
- export interface ApiContext {
7
- secret: string;
8
- tokenTtl: number;
9
- frontendUrl: string;
10
- corsOrigin: string;
11
- }
12
- export declare function resolveApiContext(config: {
13
- tokenTtl?: number;
14
- frontendUrl?: string;
15
- corsOrigin?: string;
16
- }): ApiContext;
17
- export declare function createToken(uid: number, secret: string, ttlSeconds?: number): string;
18
- export declare function verifyToken(token: string, secret: string): TokenPayload | null;
@@ -1,3 +0,0 @@
1
- import { Context } from 'koishi';
2
- import { ApiContext } from './auth';
3
- export declare function registerApiRoutes(ctx: Context, apiCtx: ApiContext): void;
@@ -1,3 +0,0 @@
1
- import { Context } from 'koishi';
2
- import { ApiContext } from '../api/auth';
3
- export declare function settings(ctx: Context, apiCtx: ApiContext): void;
@@ -1,13 +0,0 @@
1
- import { Session } from 'koishi';
2
- import { CardService } from '../services/card-service';
3
- import { ServerService } from '../services/server-service';
4
- import { Card, Server } from '../types';
5
- export type SelectResult<T> = {
6
- ok: true;
7
- value: T;
8
- } | {
9
- ok: false;
10
- message: string;
11
- };
12
- export declare function selectCard(session: Session, cardService: CardService, uid: number): Promise<SelectResult<Card>>;
13
- export declare function selectServer(session: Session, serverService: ServerService, uid: number, channelId: string | null): Promise<SelectResult<Server>>;
@@ -1,6 +0,0 @@
1
- import { Context } from 'koishi';
2
- /**
3
- * 注册 poke 命令:主动戳一戳目标用户
4
- * @param ctx - koishi 上下文
5
- */
6
- export declare function registerPokeCommand(ctx: Context): void;
@@ -1,6 +0,0 @@
1
- import { Context } from 'koishi';
2
- /**
3
- * 注册 stamp 命令:手动发送随机贴纸
4
- * @param ctx - koishi 上下文
5
- */
6
- export declare function registerStampCommand(ctx: Context): void;
@@ -1,10 +0,0 @@
1
- /** 支持的图片扩展名 */
2
- export declare const IMAGE_EXTENSIONS: readonly [".png", ".jpg", ".jpeg", ".gif", ".webp"];
3
- /** 扩展名到 MIME 类型的映射 */
4
- export declare const MIME_MAP: Record<string, string>;
5
- /** MIME 类型兜底值 */
6
- export declare const DEFAULT_MIME = "image/png";
7
- /** tip 缺省语言(用户无匹配偏好时使用) */
8
- export declare const DEFAULT_LOCALE = "zh-CN";
9
- /** 被戳时 text 类型随机抽取的提示池(按语言区分) */
10
- export declare const TIP_POOL: Record<string, string[]>;
@@ -1,9 +0,0 @@
1
- import { Context } from 'koishi';
2
- import { PokeConfig } from '../../../types/config';
3
- /**
4
- * 注册被戳事件处理:命中冷却发警告,否则按权重分发文本/贴纸
5
- * @param ctx - koishi 上下文
6
- * @param config - 戳一戳配置
7
- * @param cache - 用户 -> 上次触发时间戳的冷却缓存
8
- */
9
- export declare function registerPokeNotice(ctx: Context, config: PokeConfig, cache: Map<string, number>): void;
@@ -1,18 +0,0 @@
1
- /**
2
- * 判断文件是否为图片
3
- * @param filename - 文件名
4
- * @returns 是否为支持的图片格式
5
- */
6
- export declare function isImageFile(filename: string): boolean;
7
- /**
8
- * 根据文件名获取 MIME 类型
9
- * @param filename - 文件名
10
- * @returns MIME 类型,未匹配时返回兜底值
11
- */
12
- export declare function getMimeType(filename: string): string;
13
- /**
14
- * 查找贴纸图片对应的语音文件
15
- * @param imagePath - 贴纸图片完整路径(如 .../stamp_0384_01.png)
16
- * @returns 匹配的音频文件路径(如 .../xxx-1.mp3),未找到返回 null
17
- */
18
- export declare function findMatchingAudio(imagePath: string): string | null;
@@ -1,14 +0,0 @@
1
- /**
2
- * 按权重随机选取一项
3
- * @param items - 带 weight 字段的数组
4
- * @returns 命中的元素,空数组时返回 undefined
5
- */
6
- export declare function randomMessage<T extends {
7
- weight: number;
8
- }>(items: T[]): T | undefined;
9
- /**
10
- * 从数组中等概率随机取一项
11
- * @param items - 任意数组
12
- * @returns 随机元素,空数组时返回 undefined
13
- */
14
- export declare function pickRandom<T>(items: T[]): T | undefined;
@@ -1,14 +0,0 @@
1
- import { Context, h, Session } from 'koishi';
2
- /**
3
- * 随机发送一个 noah 贴纸(文件夹形式,可附带语音)
4
- * @param ctx - koishi 上下文
5
- * @param session - 当前会话
6
- * @param voiceOnly - 是否仅选取带语音的贴纸
7
- */
8
- export declare function sendRandomNoahStamp(ctx: Context, session: Session, voiceOnly?: boolean): Promise<void>;
9
- /**
10
- * 随机选取一个 chat 贴纸(直接图片形式)
11
- * @param ctx - koishi 上下文
12
- * @returns 图片消息元素,失败时返回错误文本
13
- */
14
- export declare function getRandomChatStamp(ctx: Context): h | string;
@@ -1,10 +0,0 @@
1
- import { Session } from 'koishi';
2
- /**
3
- * 根据用户偏好语言随机选取一条 tip
4
- *
5
- * 按用户的 locales(偏好语言顺序)依次匹配 TIP_POOL,
6
- * 命中首个有内容的语言;都不匹配时回退到默认语言。
7
- * @param session - 当前会话
8
- * @returns 随机 tip 文本,无可用 tip 时返回 undefined
9
- */
10
- export declare function pickTip(session: Session): Promise<string | undefined>;