koishi-plugin-jrys-plus 1.0.0 → 1.0.1
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 +2 -12
- package/lib/index.js +2 -4
- package/lib/ranks.js +7 -62
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* koishi-plugin-jrys-plus
|
|
3
|
-
* 今日运势签到 +
|
|
3
|
+
* 今日运势签到 + 签到天数排行榜(精简版)
|
|
4
4
|
*
|
|
5
5
|
* 改动:
|
|
6
6
|
* - 移除金币/经验值展示和进度条
|
|
7
7
|
* - 🍀 替换为 ⭐
|
|
8
8
|
* - 日期问候模块移除半透明背景
|
|
9
|
-
* -
|
|
9
|
+
* - 仅保留签到天数排行榜
|
|
10
10
|
*/
|
|
11
11
|
import { Context, Schema } from 'koishi';
|
|
12
12
|
import * as si from './signin';
|
|
@@ -18,12 +18,10 @@ export interface Config {
|
|
|
18
18
|
levelSet: si.LevelInfo[];
|
|
19
19
|
fortuneSet: si.FortuneInfo[];
|
|
20
20
|
event: RollEvent[];
|
|
21
|
-
expCommand: string;
|
|
22
21
|
signCommand: string;
|
|
23
22
|
imageMode: boolean;
|
|
24
23
|
limit: number;
|
|
25
24
|
borderwidth: number;
|
|
26
|
-
next_ExpDisplay: boolean;
|
|
27
25
|
pre_next_LevelDisplay: boolean;
|
|
28
26
|
}
|
|
29
27
|
export declare const Config: Schema<Schemastery.ObjectS<{
|
|
@@ -58,12 +56,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
58
56
|
bad: Schema<string, string>;
|
|
59
57
|
}>[]>;
|
|
60
58
|
}> | Schemastery.ObjectS<{
|
|
61
|
-
expCommand: Schema<string, string>;
|
|
62
59
|
signCommand: Schema<string, string>;
|
|
63
60
|
imageMode: Schema<boolean, boolean>;
|
|
64
61
|
limit: Schema<number, number>;
|
|
65
62
|
borderwidth: Schema<number, number>;
|
|
66
|
-
next_ExpDisplay: Schema<boolean, boolean>;
|
|
67
63
|
pre_next_LevelDisplay: Schema<boolean, boolean>;
|
|
68
64
|
}>, {
|
|
69
65
|
imgUrl: string;
|
|
@@ -85,12 +81,10 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
85
81
|
bad: Schema<string, string>;
|
|
86
82
|
}>[];
|
|
87
83
|
} & {
|
|
88
|
-
expCommand: string;
|
|
89
84
|
signCommand: string;
|
|
90
85
|
imageMode: boolean;
|
|
91
86
|
limit: number;
|
|
92
87
|
borderwidth: number;
|
|
93
|
-
next_ExpDisplay: boolean;
|
|
94
88
|
pre_next_LevelDisplay: boolean;
|
|
95
89
|
}>;
|
|
96
90
|
export declare const inject: {
|
|
@@ -133,12 +127,10 @@ declare const _default: {
|
|
|
133
127
|
bad: Schema<string, string>;
|
|
134
128
|
}>[]>;
|
|
135
129
|
}> | Schemastery.ObjectS<{
|
|
136
|
-
expCommand: Schema<string, string>;
|
|
137
130
|
signCommand: Schema<string, string>;
|
|
138
131
|
imageMode: Schema<boolean, boolean>;
|
|
139
132
|
limit: Schema<number, number>;
|
|
140
133
|
borderwidth: Schema<number, number>;
|
|
141
|
-
next_ExpDisplay: Schema<boolean, boolean>;
|
|
142
134
|
pre_next_LevelDisplay: Schema<boolean, boolean>;
|
|
143
135
|
}>, {
|
|
144
136
|
imgUrl: string;
|
|
@@ -160,12 +152,10 @@ declare const _default: {
|
|
|
160
152
|
bad: Schema<string, string>;
|
|
161
153
|
}>[];
|
|
162
154
|
} & {
|
|
163
|
-
expCommand: string;
|
|
164
155
|
signCommand: string;
|
|
165
156
|
imageMode: boolean;
|
|
166
157
|
limit: number;
|
|
167
158
|
borderwidth: number;
|
|
168
|
-
next_ExpDisplay: boolean;
|
|
169
159
|
pre_next_LevelDisplay: boolean;
|
|
170
160
|
}>;
|
|
171
161
|
};
|
package/lib/index.js
CHANGED
|
@@ -40,13 +40,13 @@ 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
45
|
* 改动:
|
|
46
46
|
* - 移除金币/经验值展示和进度条
|
|
47
47
|
* - 🍀 替换为 ⭐
|
|
48
48
|
* - 日期问候模块移除半透明背景
|
|
49
|
-
* -
|
|
49
|
+
* - 仅保留签到天数排行榜
|
|
50
50
|
*/
|
|
51
51
|
const koishi_1 = require("koishi");
|
|
52
52
|
const url_1 = require("url");
|
|
@@ -88,12 +88,10 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
88
88
|
.description('自定义黄历事件'),
|
|
89
89
|
}).description('签到/运势设置'),
|
|
90
90
|
koishi_1.Schema.object({
|
|
91
|
-
expCommand: koishi_1.Schema.string().description('经验排行榜命令').default('jrysranks'),
|
|
92
91
|
signCommand: koishi_1.Schema.string().description('签到天数排行榜命令').default('jrysranksign'),
|
|
93
92
|
imageMode: koishi_1.Schema.boolean().description('排行榜是否使用图片模式(需要 puppeteer)').default(true),
|
|
94
93
|
limit: koishi_1.Schema.number().description('排行榜显示的最大条目数').min(1).max(100).default(10),
|
|
95
94
|
borderwidth: koishi_1.Schema.number().description('文本模式边框宽度').default(14),
|
|
96
|
-
next_ExpDisplay: koishi_1.Schema.boolean().description('排行榜中显示升级所需经验').default(true),
|
|
97
95
|
pre_next_LevelDisplay: koishi_1.Schema.boolean().description('排行榜中显示前后等级信息').default(true),
|
|
98
96
|
}).description('排行榜设置'),
|
|
99
97
|
]);
|
package/lib/ranks.js
CHANGED
|
@@ -30,46 +30,6 @@ function getLevelInfo(exp, levels) {
|
|
|
30
30
|
return sorted.find(l => exp >= l.levelExp) || sorted[sorted.length - 1];
|
|
31
31
|
}
|
|
32
32
|
/* ── 文本渲染 ── */
|
|
33
|
-
function renderExpText(users, levelConfig, config) {
|
|
34
|
-
const divider = '┏' + '—'.repeat(config.borderwidth) + '┓';
|
|
35
|
-
const midDivider = '┣' + '—'.repeat(config.borderwidth) + '┫';
|
|
36
|
-
const endDivider = '┗' + '—'.repeat(config.borderwidth) + '┛';
|
|
37
|
-
const header = [divider, `┃ 🏆 经验排行榜 TOP.${config.limit} `, midDivider].join('\n');
|
|
38
|
-
const rankings = users.map((user, index) => {
|
|
39
|
-
const medal = index < 3 ? ['👑', '⭐', '✧'][index] : '•';
|
|
40
|
-
const expStr = user.exp.toLocaleString();
|
|
41
|
-
let lines = [`┃ ${medal} ${index + 1}. ${user.displayName}`];
|
|
42
|
-
if (config.next_ExpDisplay) {
|
|
43
|
-
const sorted = [...levelConfig].sort((a, b) => a.levelExp - b.levelExp);
|
|
44
|
-
const cur = getLevelInfo(user.exp, levelConfig);
|
|
45
|
-
const idx = sorted.findIndex(l => l.levelExp === cur.levelExp);
|
|
46
|
-
const next = sorted[idx + 1];
|
|
47
|
-
lines.push(next ? `┃ ⚡${expStr} exp (下一级:${next.levelExp} exp)` : `┃ ⚡${expStr} (Max)`);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
lines.push(`┃ ⚡${expStr} exp`);
|
|
51
|
-
}
|
|
52
|
-
if (config.pre_next_LevelDisplay && levelConfig.length) {
|
|
53
|
-
const sorted = [...levelConfig].sort((a, b) => a.levelExp - b.levelExp);
|
|
54
|
-
const cur = getLevelInfo(user.exp, levelConfig);
|
|
55
|
-
const idx = sorted.findIndex(l => l.levelExp === cur.levelExp);
|
|
56
|
-
const prev = sorted[idx - 1]?.levelName;
|
|
57
|
-
const next = sorted[idx + 1]?.levelName;
|
|
58
|
-
let line = '┃ ✨';
|
|
59
|
-
if (prev)
|
|
60
|
-
line += `${prev} → `;
|
|
61
|
-
line += `「${cur.levelName}」`;
|
|
62
|
-
if (next)
|
|
63
|
-
line += ` → ${next}`;
|
|
64
|
-
lines.push(line);
|
|
65
|
-
}
|
|
66
|
-
else if (levelConfig.length) {
|
|
67
|
-
lines.push(`┃ ✨${getLevelInfo(user.exp, levelConfig).levelName}`);
|
|
68
|
-
}
|
|
69
|
-
return lines.join('\n');
|
|
70
|
-
}).join('\n\n');
|
|
71
|
-
return [header, rankings, endDivider].join('\n');
|
|
72
|
-
}
|
|
73
33
|
function renderSignText(users, levelConfig, config) {
|
|
74
34
|
const divider = '┏' + '—'.repeat(config.borderwidth) + '┓';
|
|
75
35
|
const midDivider = '┣' + '—'.repeat(config.borderwidth) + '┫';
|
|
@@ -97,13 +57,13 @@ function renderSignText(users, levelConfig, config) {
|
|
|
97
57
|
return [header, rankings, endDivider].join('\n');
|
|
98
58
|
}
|
|
99
59
|
/* ── 图片渲染 ── */
|
|
100
|
-
async function renderRankImage(ctx,
|
|
60
|
+
async function renderRankImage(ctx, users, totalUsers, limit, getLevelConfig) {
|
|
101
61
|
try {
|
|
102
62
|
const path = await resolveTemplatePath();
|
|
103
63
|
let template = await fs_1.promises.readFile(path, 'utf-8');
|
|
104
64
|
const levelConfig = getLevelConfig();
|
|
105
65
|
const data = {
|
|
106
|
-
type,
|
|
66
|
+
type: 'sign',
|
|
107
67
|
limit,
|
|
108
68
|
channelName: '当前频道',
|
|
109
69
|
totalUsers,
|
|
@@ -124,7 +84,7 @@ async function renderRankImage(ctx, type, users, totalUsers, limit, getLevelConf
|
|
|
124
84
|
return {
|
|
125
85
|
displayName: user.displayName,
|
|
126
86
|
originalId: user.name,
|
|
127
|
-
value:
|
|
87
|
+
value: user.signCount,
|
|
128
88
|
levelName: cur.levelName,
|
|
129
89
|
levelColor: cur.levelColor,
|
|
130
90
|
currentLevelExp: cur.levelExp,
|
|
@@ -158,8 +118,8 @@ function registerRanks(ctx, config, getLevelConfig) {
|
|
|
158
118
|
function canUseImage() {
|
|
159
119
|
return config.imageMode && !!ctx.puppeteer;
|
|
160
120
|
}
|
|
161
|
-
async function getRankedUsers(
|
|
162
|
-
const all = await ctx.database.get('jrys', {}, { sort: {
|
|
121
|
+
async function getRankedUsers() {
|
|
122
|
+
const all = await ctx.database.get('jrys', {}, { sort: { signCount: 'desc' } });
|
|
163
123
|
if (!all.length)
|
|
164
124
|
return null;
|
|
165
125
|
const users = all.slice(0, config.limit).map(u => ({
|
|
@@ -168,31 +128,16 @@ function registerRanks(ctx, config, getLevelConfig) {
|
|
|
168
128
|
}));
|
|
169
129
|
return users;
|
|
170
130
|
}
|
|
171
|
-
ctx.command(config.expCommand || 'jrysranks')
|
|
172
|
-
.action(async ({ session }) => {
|
|
173
|
-
const users = await getRankedUsers(session, 'exp');
|
|
174
|
-
if (users === null)
|
|
175
|
-
return '暂无数据';
|
|
176
|
-
if (!users.length)
|
|
177
|
-
return '当前频道暂无数据';
|
|
178
|
-
if (canUseImage()) {
|
|
179
|
-
const total = (await ctx.database.get('jrys', {})).length;
|
|
180
|
-
const img = await renderRankImage(ctx, 'exp', users, total, config.limit, getLevelConfig);
|
|
181
|
-
if (img)
|
|
182
|
-
return img;
|
|
183
|
-
}
|
|
184
|
-
return renderExpText(users, getLevelConfig(), config);
|
|
185
|
-
});
|
|
186
131
|
ctx.command(config.signCommand || 'jrysranksign')
|
|
187
132
|
.action(async ({ session }) => {
|
|
188
|
-
const users = await getRankedUsers(
|
|
133
|
+
const users = await getRankedUsers();
|
|
189
134
|
if (users === null)
|
|
190
135
|
return '暂无数据';
|
|
191
136
|
if (!users.length)
|
|
192
137
|
return '当前频道暂无数据';
|
|
193
138
|
if (canUseImage()) {
|
|
194
139
|
const total = (await ctx.database.get('jrys', {})).length;
|
|
195
|
-
const img = await renderRankImage(ctx,
|
|
140
|
+
const img = await renderRankImage(ctx, users, total, config.limit, getLevelConfig);
|
|
196
141
|
if (img)
|
|
197
142
|
return img;
|
|
198
143
|
}
|