UNPKG

koishi-plugin-best-jrrp

Version:

支持真随机的今日人品(运势),可自定义消息,还有节日祝福,甚至还有随机图片哦~

164 lines (163 loc) 4.91 kB
import { Context } from 'koishi'; /** * 定义数据库表结构 */ declare module 'koishi' { interface Tables { jrrp: JrrpEntry; } } /** * 人品数据表结构 * @interface JrrpEntry * @property {string} userId 用户ID * @property {string} username 用户名 * @property {string} algorithm 算法 * @property {string} date 日期 * @property {number} score 分数 */ export interface JrrpEntry { userId: string; username: string; algorithm: string; date: string; score: number; } /** * 完整的人品数据 * @interface FortuneData * @property {string} username 用户名 * @property {number} score 分数 * @property {string} algorithm 算法 */ export interface FortuneData { username: string; score: number; algorithm: string; } /** * 简化的统计分析结果接口 * @interface AnalysisResult * @property {number} count 记录数量 * @property {number} mean 平均分 * @property {number} median 中位数 * @property {number} stdDev 标准差 * @property {number} min 最低分 * @property {number} max 最高分 * @property {number[]} recentScores 最近的分数 * @property {string} luckType 运气类型 * @property {Object} distribution 分布统计 * @property {number[]} histogram 直方图数据 * @property {number} entropy 熵指数 * @property {number} balance 平衡度 * @property {number} extremeRate 极值率 * @property {number[]} heatmap 热图数据(10个分段) * @property {string} trendGraph 走势图 */ export interface AnalysisResult { count: number; mean: number; median: number; stdDev: number; min: number; max: number; recentScores?: number[]; luckType?: string; distribution?: { low: number; medium: number; high: number; }; histogram?: number[]; entropy?: number; balance?: number; extremeRate?: number; heatmap?: number[]; trendGraph?: string; } /** * 统计数据比较结果 * @interface StatsComparison * @property {AnalysisResult} userAllTime 用户全部历史统计数据 * @property {AnalysisResult} userRecent 用户近期统计数据 * @property {AnalysisResult} globalRecent 全局近期统计数据 */ export interface StatsComparison { userAllTime: AnalysisResult; userRecent: AnalysisResult; globalRecent: AnalysisResult; } /** * 人品数据存储类 * @class FortuneStore */ export declare class FortuneStore { private ctx; /** * 构造函数,初始化数据库表结构 * @param {Context} ctx Koishi 上下文 */ constructor(ctx: Context); /** * 清理字符串,移除不可见字符和特殊字符,限制长度 * @param {string} input 输入字符串 * @returns {string} 清理后的字符串 */ sanitizeString(input: string): string; /** * 查询用户人品数据 * @param {string} userId 用户ID * @param {string} [date] 可选,指定日期,默认为今天 * @returns {Promise<FortuneData|null>} 查询结果 */ getFortune(userId: string, date?: string): Promise<FortuneData | null>; /** * 保存人品数据 * @param {string} userId 用户ID * @param {FortuneData} fortune 人品数据 * @returns {Promise<boolean>} 是否保存成功 */ save(userId: string, fortune: FortuneData): Promise<boolean>; /** * 获取所有今日人品数据,按分数排序 * @returns {Promise<Array<{userId: string, data: FortuneData}>>} */ getAllTodayFortunes(): Promise<Array<{ userId: string; data: FortuneData; }>>; /** * 清除人品数据 * @param {string} [userId] 可选,指定用户ID * @param {string} [date] 可选,指定日期 * @param {boolean} [dropTable] 可选,是否直接删除数据表 * @returns {Promise<number>} 清除的记录数量 */ clearData(userId?: string, date?: string, dropTable?: boolean): Promise<number>; /** * 获取用户和全局统计数据的比较 * @param {string} userId 用户ID * @returns {Promise<StatsComparison>} 用户和全局统计数据比较结果 */ getStatsComparison(userId: string): Promise<StatsComparison>; /** * 分析人品数据集合 * @param {JrrpEntry[]} records 人品记录集合 * @param {number} [recentLimit] 最近记录的限制数量 * @returns {AnalysisResult} 分析结果 */ analyzeData(records: JrrpEntry[], recentLimit?: number): AnalysisResult; /** * 计算熵指数 * @param {number[]} histogram 直方图数据 * @param {number} count 总记录数 * @returns {number} 熵指数(0-100) */ private calculateEntropy; /** * 生成走势图 * @param {number[]} scores 分数列表 * @returns {string} 走势图字符串 */ private generateTrendGraph; }