koishi-plugin-jrys-plus 1.0.2 → 1.0.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.
- package/lib/index.d.ts +4 -70
- package/lib/index.js +7 -26
- package/lib/ranks.d.ts +1 -2
- package/lib/ranks.js +11 -47
- package/lib/roll.d.ts +2 -2
- package/lib/roll.js +11 -1
- package/lib/signin.d.ts +0 -8
- package/lib/signin.js +0 -34
- package/lib/templates/fortune.html +36 -23
- package/lib/templates/rank-card.html +5 -60
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,51 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* koishi-plugin-jrys-plus
|
|
3
|
-
* 今日运势签到 +
|
|
3
|
+
* 今日运势签到 + 签到天数排行榜
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
8
|
-
* - 日期问候模块移除半透明背景
|
|
9
|
-
* - 仅保留签到天数排行榜
|
|
5
|
+
* - 彩色星星替代运势文字
|
|
6
|
+
* - 无经验/等级系统
|
|
7
|
+
* - 仅签到天数排行榜
|
|
10
8
|
*/
|
|
11
9
|
import { Context, Schema } from 'koishi';
|
|
12
|
-
import * as si from './signin';
|
|
13
10
|
import { RollEvent } from './event';
|
|
14
11
|
export declare const name = "jrys-plus";
|
|
15
12
|
export interface Config {
|
|
16
13
|
imgUrl: string;
|
|
17
14
|
signExp: [number, number];
|
|
18
|
-
levelSet: si.LevelInfo[];
|
|
19
|
-
fortuneSet: si.FortuneInfo[];
|
|
20
15
|
event: RollEvent[];
|
|
21
16
|
signCommand: string;
|
|
22
17
|
imageMode: boolean;
|
|
23
18
|
limit: number;
|
|
24
19
|
borderwidth: number;
|
|
25
|
-
pre_next_LevelDisplay: boolean;
|
|
26
20
|
}
|
|
27
21
|
export declare const Config: Schema<Schemastery.ObjectS<{
|
|
28
22
|
imgUrl: Schema<string, string>;
|
|
29
23
|
signExp: Schema<[number?, number?, ...any[]], [number?, number?, ...any[]]>;
|
|
30
24
|
}> | Schemastery.ObjectS<{
|
|
31
|
-
levelSet: Schema<Schemastery.ObjectS<{
|
|
32
|
-
level: Schema<number, number>;
|
|
33
|
-
levelExp: Schema<number, number>;
|
|
34
|
-
levelName: Schema<string, string>;
|
|
35
|
-
levelColor: Schema<string, string>;
|
|
36
|
-
}>[], Schemastery.ObjectT<{
|
|
37
|
-
level: Schema<number, number>;
|
|
38
|
-
levelExp: Schema<number, number>;
|
|
39
|
-
levelName: Schema<string, string>;
|
|
40
|
-
levelColor: Schema<string, string>;
|
|
41
|
-
}>[]>;
|
|
42
|
-
fortuneSet: Schema<Schemastery.ObjectS<{
|
|
43
|
-
luck: Schema<number, number>;
|
|
44
|
-
desc: Schema<string, string>;
|
|
45
|
-
}>[], Schemastery.ObjectT<{
|
|
46
|
-
luck: Schema<number, number>;
|
|
47
|
-
desc: Schema<string, string>;
|
|
48
|
-
}>[]>;
|
|
49
25
|
event: Schema<Schemastery.ObjectS<{
|
|
50
26
|
name: Schema<string, string>;
|
|
51
27
|
good: Schema<string, string>;
|
|
@@ -60,21 +36,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
60
36
|
imageMode: Schema<boolean, boolean>;
|
|
61
37
|
limit: Schema<number, number>;
|
|
62
38
|
borderwidth: Schema<number, number>;
|
|
63
|
-
pre_next_LevelDisplay: Schema<boolean, boolean>;
|
|
64
39
|
}>, {
|
|
65
40
|
imgUrl: string;
|
|
66
41
|
signExp: [number?, number?, ...any[]];
|
|
67
42
|
} & import("cosmokit").Dict & {
|
|
68
|
-
levelSet: Schemastery.ObjectT<{
|
|
69
|
-
level: Schema<number, number>;
|
|
70
|
-
levelExp: Schema<number, number>;
|
|
71
|
-
levelName: Schema<string, string>;
|
|
72
|
-
levelColor: Schema<string, string>;
|
|
73
|
-
}>[];
|
|
74
|
-
fortuneSet: Schemastery.ObjectT<{
|
|
75
|
-
luck: Schema<number, number>;
|
|
76
|
-
desc: Schema<string, string>;
|
|
77
|
-
}>[];
|
|
78
43
|
event: Schemastery.ObjectT<{
|
|
79
44
|
name: Schema<string, string>;
|
|
80
45
|
good: Schema<string, string>;
|
|
@@ -85,7 +50,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
85
50
|
imageMode: boolean;
|
|
86
51
|
limit: number;
|
|
87
52
|
borderwidth: number;
|
|
88
|
-
pre_next_LevelDisplay: boolean;
|
|
89
53
|
}>;
|
|
90
54
|
export declare const inject: {
|
|
91
55
|
required: string[];
|
|
@@ -99,24 +63,6 @@ declare const _default: {
|
|
|
99
63
|
imgUrl: Schema<string, string>;
|
|
100
64
|
signExp: Schema<[number?, number?, ...any[]], [number?, number?, ...any[]]>;
|
|
101
65
|
}> | Schemastery.ObjectS<{
|
|
102
|
-
levelSet: Schema<Schemastery.ObjectS<{
|
|
103
|
-
level: Schema<number, number>;
|
|
104
|
-
levelExp: Schema<number, number>;
|
|
105
|
-
levelName: Schema<string, string>;
|
|
106
|
-
levelColor: Schema<string, string>;
|
|
107
|
-
}>[], Schemastery.ObjectT<{
|
|
108
|
-
level: Schema<number, number>;
|
|
109
|
-
levelExp: Schema<number, number>;
|
|
110
|
-
levelName: Schema<string, string>;
|
|
111
|
-
levelColor: Schema<string, string>;
|
|
112
|
-
}>[]>;
|
|
113
|
-
fortuneSet: Schema<Schemastery.ObjectS<{
|
|
114
|
-
luck: Schema<number, number>;
|
|
115
|
-
desc: Schema<string, string>;
|
|
116
|
-
}>[], Schemastery.ObjectT<{
|
|
117
|
-
luck: Schema<number, number>;
|
|
118
|
-
desc: Schema<string, string>;
|
|
119
|
-
}>[]>;
|
|
120
66
|
event: Schema<Schemastery.ObjectS<{
|
|
121
67
|
name: Schema<string, string>;
|
|
122
68
|
good: Schema<string, string>;
|
|
@@ -131,21 +77,10 @@ declare const _default: {
|
|
|
131
77
|
imageMode: Schema<boolean, boolean>;
|
|
132
78
|
limit: Schema<number, number>;
|
|
133
79
|
borderwidth: Schema<number, number>;
|
|
134
|
-
pre_next_LevelDisplay: Schema<boolean, boolean>;
|
|
135
80
|
}>, {
|
|
136
81
|
imgUrl: string;
|
|
137
82
|
signExp: [number?, number?, ...any[]];
|
|
138
83
|
} & import("cosmokit").Dict & {
|
|
139
|
-
levelSet: Schemastery.ObjectT<{
|
|
140
|
-
level: Schema<number, number>;
|
|
141
|
-
levelExp: Schema<number, number>;
|
|
142
|
-
levelName: Schema<string, string>;
|
|
143
|
-
levelColor: Schema<string, string>;
|
|
144
|
-
}>[];
|
|
145
|
-
fortuneSet: Schemastery.ObjectT<{
|
|
146
|
-
luck: Schema<number, number>;
|
|
147
|
-
desc: Schema<string, string>;
|
|
148
|
-
}>[];
|
|
149
84
|
event: Schemastery.ObjectT<{
|
|
150
85
|
name: Schema<string, string>;
|
|
151
86
|
good: Schema<string, string>;
|
|
@@ -156,7 +91,6 @@ declare const _default: {
|
|
|
156
91
|
imageMode: boolean;
|
|
157
92
|
limit: number;
|
|
158
93
|
borderwidth: number;
|
|
159
|
-
pre_next_LevelDisplay: boolean;
|
|
160
94
|
}>;
|
|
161
95
|
};
|
|
162
96
|
export default _default;
|
package/lib/index.js
CHANGED
|
@@ -40,13 +40,11 @@ exports.inject = exports.Config = exports.name = void 0;
|
|
|
40
40
|
exports.apply = apply;
|
|
41
41
|
/**
|
|
42
42
|
* koishi-plugin-jrys-plus
|
|
43
|
-
* 今日运势签到 +
|
|
43
|
+
* 今日运势签到 + 签到天数排行榜
|
|
44
44
|
*
|
|
45
|
-
*
|
|
46
|
-
* -
|
|
47
|
-
* -
|
|
48
|
-
* - 日期问候模块移除半透明背景
|
|
49
|
-
* - 仅保留签到天数排行榜
|
|
45
|
+
* - 彩色星星替代运势文字
|
|
46
|
+
* - 无经验/等级系统
|
|
47
|
+
* - 仅签到天数排行榜
|
|
50
48
|
*/
|
|
51
49
|
const koishi_1 = require("koishi");
|
|
52
50
|
const url_1 = require("url");
|
|
@@ -64,22 +62,10 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
64
62
|
.description('随机横图api或者本地图片目录路径。填 URL 则直接用;填本地路径则随机取目录内图片。')
|
|
65
63
|
.required(),
|
|
66
64
|
signExp: koishi_1.Schema.tuple([Number, Number])
|
|
67
|
-
.description('
|
|
65
|
+
.description('签到获得经验范围(仅用于后端累计,不在卡片展示)')
|
|
68
66
|
.default([1, 100]),
|
|
69
67
|
}).description('基础设置'),
|
|
70
68
|
koishi_1.Schema.object({
|
|
71
|
-
levelSet: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
72
|
-
level: koishi_1.Schema.number().description('等级'),
|
|
73
|
-
levelExp: koishi_1.Schema.number().description('等级最低经验'),
|
|
74
|
-
levelName: koishi_1.Schema.string().description('等级名称'),
|
|
75
|
-
levelColor: koishi_1.Schema.string().role('color').description('等级颜色'),
|
|
76
|
-
})).role('table').default(si.defaultLevelInfo)
|
|
77
|
-
.description('经验等级设置(升序,最低等级经验必须为0)'),
|
|
78
|
-
fortuneSet: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
79
|
-
luck: koishi_1.Schema.number().description('每级最低运势'),
|
|
80
|
-
desc: koishi_1.Schema.string().description('运势描述'),
|
|
81
|
-
})).role('table').default(si.defaultFortuneInfo)
|
|
82
|
-
.description('运势值描述(升序,最低一级必须为0,描述最长14个中文字符)'),
|
|
83
69
|
event: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
84
70
|
name: koishi_1.Schema.string().description('事件名称'),
|
|
85
71
|
good: koishi_1.Schema.string().description('好的结局'),
|
|
@@ -92,7 +78,6 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
92
78
|
imageMode: koishi_1.Schema.boolean().description('排行榜是否使用图片模式(需要 puppeteer)').default(true),
|
|
93
79
|
limit: koishi_1.Schema.number().description('排行榜显示的最大条目数').min(1).max(100).default(10),
|
|
94
80
|
borderwidth: koishi_1.Schema.number().description('文本模式边框宽度').default(14),
|
|
95
|
-
pre_next_LevelDisplay: koishi_1.Schema.boolean().description('排行榜中显示前后等级信息').default(true),
|
|
96
81
|
}).description('排行榜设置'),
|
|
97
82
|
]);
|
|
98
83
|
exports.inject = {
|
|
@@ -135,7 +120,7 @@ function apply(ctx, config) {
|
|
|
135
120
|
// 合并事件
|
|
136
121
|
const eventJson = [...event_1.defaultEventJson, ...config.event];
|
|
137
122
|
// 注册排行榜
|
|
138
|
-
(0, ranks_1.registerRanks)(ctx, db, config
|
|
123
|
+
(0, ranks_1.registerRanks)(ctx, db, config);
|
|
139
124
|
/* ── 运势签到命令 ── */
|
|
140
125
|
ctx.command('jrys', '今日运势')
|
|
141
126
|
.userFields(['id', 'name'])
|
|
@@ -149,11 +134,9 @@ function apply(ctx, config) {
|
|
|
149
134
|
return '今天已经签到过了哦~';
|
|
150
135
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
151
136
|
const day = date.getDate().toString().padStart(2, '0');
|
|
152
|
-
const luckInfo = signin.getFortuneInfo(luck);
|
|
153
137
|
const [gd1, gd2, bd1, bd2] = await jrys.getRandomObjects(eventJson, session.user.id);
|
|
154
138
|
const hitokoto = await fetchHitokoto();
|
|
155
139
|
const greeting = signin.getGreeting(date.getHours());
|
|
156
|
-
const levelinfo = signin.getLevelInfo(sign.allExp);
|
|
157
140
|
// 背景图
|
|
158
141
|
let bgUrl;
|
|
159
142
|
if (/^https?:\/\//i.test(config.imgUrl)) {
|
|
@@ -178,10 +161,8 @@ function apply(ctx, config) {
|
|
|
178
161
|
.replace('{{DAY}}', day)
|
|
179
162
|
.replace('{{HITOKOTO}}', hitokoto)
|
|
180
163
|
.replace('{{NAME}}', name)
|
|
181
|
-
.replace('{{LEVEL_NAME}}', levelinfo.levelInfo.levelName)
|
|
182
|
-
.replace('{{LEVEL_COLOR}}', levelinfo.levelInfo.levelColor)
|
|
183
164
|
.replace('{{LUCK}}', String(luck))
|
|
184
|
-
.replace('{{
|
|
165
|
+
.replace('{{UID}}', String(session.user.id))
|
|
185
166
|
.replace('{{GOODDO}}', gooddo)
|
|
186
167
|
.replace('{{BADDO}}', baddo);
|
|
187
168
|
const outPath = path_1.default.resolve(__dirname, 'templates', '_fortune_render.html');
|
package/lib/ranks.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { Context, Database } from 'koishi';
|
|
2
|
-
|
|
3
|
-
export declare function registerRanks(ctx: Context, db: Database<any>, config: any, getLevelConfig: () => LevelInfo[]): void;
|
|
2
|
+
export declare function registerRanks(ctx: Context, db: Database<any>, config: any): void;
|
package/lib/ranks.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerRanks = registerRanks;
|
|
4
4
|
const koishi_1 = require("koishi");
|
|
5
|
-
const signin_1 = require("./signin");
|
|
6
5
|
const fs_1 = require("fs");
|
|
7
6
|
const path_1 = require("path");
|
|
8
7
|
/* ── 模板路径候选 ── */
|
|
@@ -23,68 +22,34 @@ async function resolveTemplatePath() {
|
|
|
23
22
|
throw new Error('未找到 rank-card.html 模板文件');
|
|
24
23
|
}
|
|
25
24
|
/* ── 文本渲染 ── */
|
|
26
|
-
function renderSignText(users,
|
|
25
|
+
function renderSignText(users, config) {
|
|
27
26
|
const divider = '┏' + '—'.repeat(config.borderwidth) + '┓';
|
|
28
27
|
const midDivider = '┣' + '—'.repeat(config.borderwidth) + '┫';
|
|
29
28
|
const endDivider = '┗' + '—'.repeat(config.borderwidth) + '┛';
|
|
30
29
|
const header = [divider, `┃ 🏆 签到排行榜 TOP.${config.limit} `, midDivider].join('\n');
|
|
31
30
|
const rankings = users.map((user, index) => {
|
|
32
31
|
const medal = index < 3 ? ['👑', '⭐', '✧'][index] : '•';
|
|
33
|
-
|
|
34
|
-
if (config.pre_next_LevelDisplay && levelConfig.length) {
|
|
35
|
-
const sorted = [...levelConfig].sort((a, b) => a.levelExp - b.levelExp);
|
|
36
|
-
const cur = (0, signin_1.getLevelInfo)(user.exp, levelConfig);
|
|
37
|
-
const idx = sorted.findIndex(l => l.levelExp === cur.levelExp);
|
|
38
|
-
const prev = sorted[idx - 1]?.levelName;
|
|
39
|
-
const next = sorted[idx + 1]?.levelName;
|
|
40
|
-
let line = '┃ ✨';
|
|
41
|
-
if (prev)
|
|
42
|
-
line += `${prev} → `;
|
|
43
|
-
line += `「${cur.levelName}」`;
|
|
44
|
-
if (next)
|
|
45
|
-
line += ` → ${next}`;
|
|
46
|
-
lines.push(line);
|
|
47
|
-
}
|
|
32
|
+
const lines = [`┃ ${medal} ${index + 1}. ${user.displayName}`, `┃ 📅${user.signCount.toLocaleString()} 天`];
|
|
48
33
|
return lines.join('\n');
|
|
49
34
|
}).join('\n\n');
|
|
50
35
|
return [header, rankings, endDivider].join('\n');
|
|
51
36
|
}
|
|
52
37
|
/* ── 图片渲染 ── */
|
|
53
|
-
async function renderRankImage(ctx, users, totalUsers, limit
|
|
38
|
+
async function renderRankImage(ctx, users, totalUsers, limit) {
|
|
54
39
|
try {
|
|
55
40
|
const path = await resolveTemplatePath();
|
|
56
41
|
let template = await fs_1.promises.readFile(path, 'utf-8');
|
|
57
|
-
const levelConfig = getLevelConfig();
|
|
58
42
|
const data = {
|
|
59
43
|
type: 'sign',
|
|
60
44
|
limit,
|
|
61
45
|
channelName: '当前频道',
|
|
62
46
|
totalUsers,
|
|
63
47
|
updateTime: new Date().toLocaleString('zh-CN'),
|
|
64
|
-
users: users.map(user => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const nextObj = sorted[idx + 1];
|
|
70
|
-
const nextName = nextObj?.levelName;
|
|
71
|
-
let levelProgression = '';
|
|
72
|
-
if (prev)
|
|
73
|
-
levelProgression += `${prev} → `;
|
|
74
|
-
levelProgression += `「${cur.levelName}」`;
|
|
75
|
-
if (nextName)
|
|
76
|
-
levelProgression += ` → ${nextName}`;
|
|
77
|
-
return {
|
|
78
|
-
displayName: user.displayName,
|
|
79
|
-
originalId: user.name,
|
|
80
|
-
value: user.signCount,
|
|
81
|
-
levelName: cur.levelName,
|
|
82
|
-
levelColor: cur.levelColor,
|
|
83
|
-
currentLevelExp: cur.levelExp,
|
|
84
|
-
nextLevelExp: nextObj?.levelExp ?? null,
|
|
85
|
-
levelProgression,
|
|
86
|
-
};
|
|
87
|
-
}),
|
|
48
|
+
users: users.map(user => ({
|
|
49
|
+
displayName: user.displayName,
|
|
50
|
+
originalId: user.name,
|
|
51
|
+
value: user.signCount,
|
|
52
|
+
})),
|
|
88
53
|
};
|
|
89
54
|
template = template.replace('{{DATA}}', JSON.stringify(data));
|
|
90
55
|
const page = await ctx.puppeteer.page();
|
|
@@ -106,8 +71,7 @@ async function renderRankImage(ctx, users, totalUsers, limit, getLevelConfig) {
|
|
|
106
71
|
}
|
|
107
72
|
}
|
|
108
73
|
/* ── 注册排行命令 ── */
|
|
109
|
-
function registerRanks(ctx, db, config
|
|
110
|
-
const logger = ctx.logger('jrys-plus');
|
|
74
|
+
function registerRanks(ctx, db, config) {
|
|
111
75
|
function canUseImage() {
|
|
112
76
|
return config.imageMode && !!ctx.puppeteer;
|
|
113
77
|
}
|
|
@@ -130,10 +94,10 @@ function registerRanks(ctx, db, config, getLevelConfig) {
|
|
|
130
94
|
return '当前频道暂无数据';
|
|
131
95
|
if (canUseImage()) {
|
|
132
96
|
const total = (await db.get('jrys', {})).length;
|
|
133
|
-
const img = await renderRankImage(ctx, users, total, config.limit
|
|
97
|
+
const img = await renderRankImage(ctx, users, total, config.limit);
|
|
134
98
|
if (img)
|
|
135
99
|
return img;
|
|
136
100
|
}
|
|
137
|
-
return renderSignText(users,
|
|
101
|
+
return renderSignText(users, config);
|
|
138
102
|
});
|
|
139
103
|
}
|
package/lib/roll.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare class Jrys {
|
|
|
2
2
|
constructor();
|
|
3
3
|
seededRandom(seed: number): number;
|
|
4
4
|
/** 同一天同一用户运势值固定(0~maxRange) */
|
|
5
|
-
getFortune(uid: number, maxRange?: number): Promise<number>;
|
|
5
|
+
getFortune(uid: number | string, maxRange?: number): Promise<number>;
|
|
6
6
|
/** 抽 4 个不重复的黄历事件 */
|
|
7
|
-
getRandomObjects(jsonObject: Array<any>, uid: number): Promise<Array<any>>;
|
|
7
|
+
getRandomObjects(jsonObject: Array<any>, uid: number | string): Promise<Array<any>>;
|
|
8
8
|
}
|
package/lib/roll.js
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
// 每日运势值、随机黄历事件
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Jrys = void 0;
|
|
5
|
+
/** 将任意字符串/数字转为稳定的正整数 hash */
|
|
6
|
+
function hashUID(uid) {
|
|
7
|
+
const str = String(uid);
|
|
8
|
+
let hash = 5381;
|
|
9
|
+
for (let i = 0; i < str.length; i++) {
|
|
10
|
+
hash = ((hash << 5) + hash) ^ str.charCodeAt(i);
|
|
11
|
+
hash = hash >>> 0; // 转为无符号 32 位
|
|
12
|
+
}
|
|
13
|
+
return hash;
|
|
14
|
+
}
|
|
5
15
|
class Jrys {
|
|
6
16
|
constructor() { }
|
|
7
17
|
seededRandom(seed) {
|
|
@@ -11,7 +21,7 @@ class Jrys {
|
|
|
11
21
|
/** 同一天同一用户运势值固定(0~maxRange) */
|
|
12
22
|
async getFortune(uid, maxRange = 100) {
|
|
13
23
|
const etime = new Date().setHours(0, 0, 0, 0);
|
|
14
|
-
const todaySeed = (
|
|
24
|
+
const todaySeed = (hashUID(uid) ^ etime) % 1000000001;
|
|
15
25
|
return Math.floor(this.seededRandom(todaySeed) * maxRange);
|
|
16
26
|
}
|
|
17
27
|
/** 抽 4 个不重复的黄历事件 */
|
package/lib/signin.d.ts
CHANGED
|
@@ -35,10 +35,7 @@ export declare const defaultFortuneInfo: FortuneInfo[];
|
|
|
35
35
|
export declare function initDatabase(ctx: Context): void;
|
|
36
36
|
export interface SigninConfig {
|
|
37
37
|
signExp: [number, number];
|
|
38
|
-
levelSet: LevelInfo[];
|
|
39
|
-
fortuneSet: FortuneInfo[];
|
|
40
38
|
}
|
|
41
|
-
export declare function getLevelInfo(exp: number, levels: LevelInfo[]): LevelInfo;
|
|
42
39
|
export declare class Signin {
|
|
43
40
|
private db;
|
|
44
41
|
private cfg;
|
|
@@ -55,10 +52,5 @@ export declare class Signin {
|
|
|
55
52
|
signTime: Date;
|
|
56
53
|
count: any;
|
|
57
54
|
}>;
|
|
58
|
-
getLevelInfo(exp: number): {
|
|
59
|
-
levelInfo: LevelInfo;
|
|
60
|
-
nextExp: string | number;
|
|
61
|
-
};
|
|
62
|
-
getFortuneInfo(luck: number): string;
|
|
63
55
|
getGreeting(hour: number): string;
|
|
64
56
|
}
|
package/lib/signin.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Signin = exports.defaultFortuneInfo = exports.defaultLevelInfo = void 0;
|
|
4
4
|
exports.initDatabase = initDatabase;
|
|
5
|
-
exports.getLevelInfo = getLevelInfo;
|
|
6
5
|
const timeGreetings = [
|
|
7
6
|
{ range: [0, 5], message: '晚安' },
|
|
8
7
|
{ range: [5, 9], message: '早上好' },
|
|
@@ -60,12 +59,6 @@ function initDatabase(ctx) {
|
|
|
60
59
|
signCount: 'unsigned',
|
|
61
60
|
});
|
|
62
61
|
}
|
|
63
|
-
function getLevelInfo(exp, levels) {
|
|
64
|
-
if (!levels?.length)
|
|
65
|
-
return { level: 0, levelExp: 0, levelName: '无等级', levelColor: '#666666' };
|
|
66
|
-
const sorted = [...levels].sort((a, b) => b.levelExp - a.levelExp);
|
|
67
|
-
return sorted.find(l => exp >= l.levelExp) || sorted[sorted.length - 1];
|
|
68
|
-
}
|
|
69
62
|
class Signin {
|
|
70
63
|
constructor(db, cfg) {
|
|
71
64
|
this.db = db;
|
|
@@ -102,33 +95,6 @@ class Signin {
|
|
|
102
95
|
});
|
|
103
96
|
return { status: 0, allExp: accExp, signTime: date, count: accCount };
|
|
104
97
|
}
|
|
105
|
-
getLevelInfo(exp) {
|
|
106
|
-
let index = 0;
|
|
107
|
-
for (let i = 0; i < this.cfg.levelSet.length; i++) {
|
|
108
|
-
if (exp >= this.cfg.levelSet[i].levelExp)
|
|
109
|
-
index++;
|
|
110
|
-
else
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
let nExp;
|
|
114
|
-
if (index >= this.cfg.levelSet.length)
|
|
115
|
-
nExp = '???';
|
|
116
|
-
else
|
|
117
|
-
nExp = this.cfg.levelSet[index].levelExp;
|
|
118
|
-
index--;
|
|
119
|
-
return { levelInfo: this.cfg.levelSet[index], nextExp: nExp };
|
|
120
|
-
}
|
|
121
|
-
getFortuneInfo(luck) {
|
|
122
|
-
let index = 0;
|
|
123
|
-
for (let i = 0; i < this.cfg.fortuneSet.length; i++) {
|
|
124
|
-
if (luck >= this.cfg.fortuneSet[i].luck)
|
|
125
|
-
index++;
|
|
126
|
-
else
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
index--;
|
|
130
|
-
return this.cfg.fortuneSet[index].desc;
|
|
131
|
-
}
|
|
132
98
|
getGreeting(hour) {
|
|
133
99
|
const g = timeGreetings.find(t => hour >= t.range[0] && hour < t.range[1]);
|
|
134
100
|
return g ? g.message : '你好';
|
|
@@ -64,25 +64,23 @@
|
|
|
64
64
|
}
|
|
65
65
|
.signin {
|
|
66
66
|
color: #838383;
|
|
67
|
-
margin: 0 0
|
|
67
|
+
margin: 0 0 24px 0;
|
|
68
68
|
font-size: 20px;
|
|
69
69
|
font-weight: 500;
|
|
70
|
+
text-align: center;
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
+
|
|
73
|
+
/* ── 彩色星星 ── */
|
|
74
|
+
.stars {
|
|
72
75
|
display: flex;
|
|
76
|
+
flex-wrap: wrap;
|
|
73
77
|
justify-content: center;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
margin-bottom: 10px;
|
|
78
|
+
gap: 8px;
|
|
79
|
+
margin: 10px 0 20px 0;
|
|
77
80
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
display: flex;
|
|
82
|
-
flex-direction: row;
|
|
83
|
-
justify-content: space-between;
|
|
84
|
-
align-items: center;
|
|
85
|
-
margin: 10px 5px 0 0;
|
|
81
|
+
.stars span {
|
|
82
|
+
font-size: 36px;
|
|
83
|
+
line-height: 1;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
/* ── 宜/忌 ── */
|
|
@@ -140,16 +138,7 @@
|
|
|
140
138
|
<div class="content">
|
|
141
139
|
<div class="signin"><strong>{{NAME}}</strong> 签到成功!</div>
|
|
142
140
|
|
|
143
|
-
<div class="
|
|
144
|
-
<span style="color: {{LEVEL_COLOR}};">{{LEVEL_NAME}}</span>
|
|
145
|
-
</div>
|
|
146
|
-
|
|
147
|
-
<div class="fortune">
|
|
148
|
-
<span style="font-size: 36px; font-weight: bold;">
|
|
149
|
-
<span style="font-size: 28px;">⭐</span>{{LUCK}}
|
|
150
|
-
</span>
|
|
151
|
-
<span style="font-size: 28px; color: #838383;">🌠{{LUCK_INFO}}</span>
|
|
152
|
-
</div>
|
|
141
|
+
<div class="stars" id="stars-area"></div>
|
|
153
142
|
|
|
154
143
|
<hr>
|
|
155
144
|
|
|
@@ -166,5 +155,29 @@
|
|
|
166
155
|
|
|
167
156
|
<div class="credit">随机生成 请勿迷信 | JRYS+</div>
|
|
168
157
|
</div>
|
|
158
|
+
|
|
159
|
+
<script>
|
|
160
|
+
(function() {
|
|
161
|
+
var luck = {{LUCK}};
|
|
162
|
+
// 运势 0~100 映射为 1~10 颗星
|
|
163
|
+
var starCount = Math.max(1, Math.ceil(luck / 10));
|
|
164
|
+
// 十种彩色
|
|
165
|
+
var colors = [
|
|
166
|
+
'#ff4757', '#ff6b81', '#ffa502', '#eccc68',
|
|
167
|
+
'#2ed573', '#1e90ff', '#5352ed', '#9b59b6',
|
|
168
|
+
'#ff6348', '#00d2d3'
|
|
169
|
+
];
|
|
170
|
+
// 用运势值 + 星星序号做种子,保证同一天同一用户颜色固定
|
|
171
|
+
var baseSeed = luck * 31 + {{UID}};
|
|
172
|
+
var area = document.getElementById('stars-area');
|
|
173
|
+
for (var i = 0; i < starCount; i++) {
|
|
174
|
+
var span = document.createElement('span');
|
|
175
|
+
span.textContent = '⭐';
|
|
176
|
+
var ci = (baseSeed + i * 7) % colors.length;
|
|
177
|
+
span.style.color = colors[ci];
|
|
178
|
+
area.appendChild(span);
|
|
179
|
+
}
|
|
180
|
+
})();
|
|
181
|
+
</script>
|
|
169
182
|
</body>
|
|
170
183
|
</html>
|
|
@@ -89,11 +89,10 @@
|
|
|
89
89
|
<script type="application/json" id="data-source">{{DATA}}</script>
|
|
90
90
|
<script>
|
|
91
91
|
const DATA = JSON.parse(document.getElementById("data-source").textContent);
|
|
92
|
-
const isExp = DATA.type === "exp";
|
|
93
92
|
const headerIcon = document.getElementById("header-icon");
|
|
94
|
-
headerIcon.className = "header-icon
|
|
95
|
-
headerIcon.textContent =
|
|
96
|
-
document.getElementById("header-title").textContent =
|
|
93
|
+
headerIcon.className = "header-icon sign";
|
|
94
|
+
headerIcon.textContent = "📅";
|
|
95
|
+
document.getElementById("header-title").textContent = "累计签到排行榜 TOP " + DATA.limit;
|
|
97
96
|
document.getElementById("header-sub").textContent = DATA.channelName || "当前频道";
|
|
98
97
|
const rankList = document.getElementById("rank-list");
|
|
99
98
|
DATA.users.forEach(function(user, i) {
|
|
@@ -109,62 +108,8 @@
|
|
|
109
108
|
userDiv.className = "rank-user";
|
|
110
109
|
var nameDiv = document.createElement("div");
|
|
111
110
|
nameDiv.className = "rank-name";
|
|
112
|
-
|
|
113
|
-
if (user.nickname && user.username && user.displayName === user.nickname) {
|
|
114
|
-
nameText += " (" + user.username + ")";
|
|
115
|
-
} else if (user.username && user.displayName !== user.originalId) {
|
|
116
|
-
nameText += " (" + user.originalId + ")";
|
|
117
|
-
}
|
|
118
|
-
nameDiv.textContent = nameText;
|
|
111
|
+
nameDiv.textContent = user.displayName;
|
|
119
112
|
userDiv.appendChild(nameDiv);
|
|
120
|
-
if (user.levelName) {
|
|
121
|
-
var subDiv = document.createElement("div");
|
|
122
|
-
subDiv.className = "rank-sub";
|
|
123
|
-
var color = user.levelColor || "var(--accent-color)";
|
|
124
|
-
if (user.levelProgression) {
|
|
125
|
-
var marker = "「" + user.levelName + "」";
|
|
126
|
-
var parts = user.levelProgression.split(marker);
|
|
127
|
-
if (parts.length === 2) {
|
|
128
|
-
subDiv.appendChild(document.createTextNode(parts[0]));
|
|
129
|
-
var span = document.createElement("span");
|
|
130
|
-
span.textContent = marker;
|
|
131
|
-
span.style.color = color;
|
|
132
|
-
span.style.fontWeight = "700";
|
|
133
|
-
subDiv.appendChild(span);
|
|
134
|
-
subDiv.appendChild(document.createTextNode(parts[1]));
|
|
135
|
-
} else {
|
|
136
|
-
subDiv.textContent = user.levelProgression;
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
var span2 = document.createElement("span");
|
|
140
|
-
span2.textContent = "「" + user.levelName + "」";
|
|
141
|
-
span2.style.color = color;
|
|
142
|
-
span2.style.fontWeight = "700";
|
|
143
|
-
subDiv.appendChild(span2);
|
|
144
|
-
}
|
|
145
|
-
userDiv.appendChild(subDiv);
|
|
146
|
-
}
|
|
147
|
-
if (isExp && user.nextLevelExp !== null && user.nextLevelExp !== undefined) {
|
|
148
|
-
var progressDiv = document.createElement("div");
|
|
149
|
-
progressDiv.className = "rank-progress";
|
|
150
|
-
var bar = document.createElement("div");
|
|
151
|
-
bar.className = "progress-bar";
|
|
152
|
-
var fill = document.createElement("div");
|
|
153
|
-
fill.className = "progress-fill";
|
|
154
|
-
var currentExp = user.value;
|
|
155
|
-
var baseLevelExp = user.currentLevelExp || 0;
|
|
156
|
-
var nextExp = user.nextLevelExp;
|
|
157
|
-
var progress = nextExp > baseLevelExp ? Math.min(((currentExp - baseLevelExp) / (nextExp - baseLevelExp)) * 100, 100) : 100;
|
|
158
|
-
fill.style.width = progress.toFixed(1) + "%";
|
|
159
|
-
fill.style.background = user.levelColor || "var(--accent-color)";
|
|
160
|
-
bar.appendChild(fill);
|
|
161
|
-
progressDiv.appendChild(bar);
|
|
162
|
-
var pText = document.createElement("div");
|
|
163
|
-
pText.className = "progress-text";
|
|
164
|
-
pText.textContent = progress >= 100 ? "MAX" : currentExp + "/" + nextExp;
|
|
165
|
-
progressDiv.appendChild(pText);
|
|
166
|
-
userDiv.appendChild(progressDiv);
|
|
167
|
-
}
|
|
168
113
|
item.appendChild(userDiv);
|
|
169
114
|
var valueDiv = document.createElement("div");
|
|
170
115
|
valueDiv.className = "rank-value";
|
|
@@ -174,7 +119,7 @@
|
|
|
174
119
|
valueDiv.appendChild(mainVal);
|
|
175
120
|
var labelVal = document.createElement("div");
|
|
176
121
|
labelVal.className = "rank-value-label";
|
|
177
|
-
labelVal.textContent =
|
|
122
|
+
labelVal.textContent = "天";
|
|
178
123
|
valueDiv.appendChild(labelVal);
|
|
179
124
|
item.appendChild(valueDiv);
|
|
180
125
|
rankList.appendChild(item);
|