koishi-plugin-toram 0.2.3 → 0.2.5
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.js +27 -34
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -37,75 +37,68 @@ async function apply(ctx, config) {
|
|
|
37
37
|
let x;
|
|
38
38
|
let text;
|
|
39
39
|
let 等级差倍率 = [11, 11, 11, 11, 11, 10, 9, 7, 3];
|
|
40
|
+
let 时间戳增加对应 = {
|
|
41
|
+
'上午': 12 * 60 * 60 * 1000,
|
|
42
|
+
'下午': 18 * 60 * 60 * 1000,
|
|
43
|
+
};
|
|
40
44
|
ctx.command('组队 <截止时间> <求组内容>').action(async ({ session }, ...args) => {
|
|
45
|
+
const { userId, guildId } = session;
|
|
41
46
|
const 当前时间date = new Date();
|
|
42
47
|
await ctx.database.remove('toram_team', { until_Unix: { $lte: 当前时间date.getTime() } });
|
|
43
48
|
let 截止时间 = args[0], 组队内容 = args[1];
|
|
44
|
-
|
|
45
|
-
if (截止时间 == undefined || 组队内容 == undefined || /^\d+月\d+日(前)?$/.test(截止时间) == false) {
|
|
49
|
+
if (截止时间 == undefined || 组队内容 == undefined) {
|
|
46
50
|
return '如果你要发布组队信息,请输入\n"组队 时间/截止时间 求组内容"\n\n示例:\n"组队 5月1日前 210升级"表示截止至5月1日结束前希望组队进行210升级;\n"组队 5月2日 190托环"表示5月2日当天希望组队进行190托环';
|
|
47
51
|
}
|
|
48
|
-
|
|
52
|
+
if (/^\d+月\d+日(前|上午|下午|晚)?$/.test(截止时间) == false) {
|
|
53
|
+
return '"时间/截止时间"的格式应为"xx月xx日",也可在日期后加入以下后缀:前/上午/下午/晚';
|
|
54
|
+
}
|
|
55
|
+
const 组队对象 = await ctx.database.get('toram_team', `${guildId}${userId}`);
|
|
49
56
|
if (组队对象.length != 0) {
|
|
50
57
|
return '每个人同一时间只能发布一个组队哦~';
|
|
51
58
|
}
|
|
52
59
|
const 截止时间拆分 = 截止时间.split('月');
|
|
53
60
|
const 截止时间_月 = Number(截止时间拆分[0]);
|
|
54
|
-
const 截止时间_日 = Number(截止时间拆分[1].replace(
|
|
55
|
-
const 当前时间_
|
|
56
|
-
const 当前时间_月
|
|
57
|
-
const 当前时间_日 = 当前时间date.getDate();
|
|
58
|
-
if (截止时间_月 < 当前时间_月 || (截止时间_月 == 当前时间_月 && 截止时间_日 < 当前时间_日)) {
|
|
59
|
-
截止时间_年 = 当前时间_年 + 1;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
截止时间_年 = 当前时间_年;
|
|
63
|
-
}
|
|
64
|
-
;
|
|
61
|
+
const 截止时间_日 = Number(截止时间拆分[1].replace(/日(前|上午|下午|晚)?$/, ''));
|
|
62
|
+
const [当前时间_年, 当前时间_月, 当前时间_日] = 当前时间date.toLocaleDateString().split('-');
|
|
63
|
+
const 截止时间_年 = 截止时间_月 < Number(当前时间_月) + 1 || (截止时间_月 === Number(当前时间_月) + 1 && 截止时间_日 < Number(当前时间_日)) ? Number(当前时间_年) + 1 : Number(当前时间_年);
|
|
65
64
|
const 截止时间字符串 = `${截止时间_年}-${截止时间_月}-${截止时间_日}`;
|
|
66
65
|
const 截止时间date = new Date(截止时间字符串);
|
|
67
|
-
const 检测时间_
|
|
68
|
-
const
|
|
69
|
-
const 检测时间_日 = 截止时间date.getDate();
|
|
70
|
-
const 检测时间字符串 = `${检测时间_年}-${检测时间_月}-${检测时间_日}`;
|
|
66
|
+
const [检测时间_年, 检测时间_月, 检测时间_日] = 截止时间date.toLocaleDateString().split('-');
|
|
67
|
+
const 检测时间字符串 = `${检测时间_年}-${Number(检测时间_月) + 1}-${检测时间_日}`;
|
|
71
68
|
if (isNaN(截止时间date.getTime()) || 检测时间字符串 != 截止时间字符串) {
|
|
72
69
|
return '你确定是这个日期吗?';
|
|
73
70
|
}
|
|
74
71
|
;
|
|
75
72
|
截止时间date.setDate(截止时间date.getDate() + 1);
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
let 截止时间戳 = 截止时间date.getTime();
|
|
74
|
+
const 截止时间后缀 = 截止时间.split("日")[1];
|
|
75
|
+
const 截止时间戳增加 = Number(时间戳增加对应[截止时间后缀]) || 24 * 60 * 60 * 1000;
|
|
76
|
+
截止时间戳 += 截止时间戳增加;
|
|
77
|
+
const 今日时间date = new Date(Number(当前时间_年), Number(当前时间_月), Number(当前时间_日));
|
|
78
|
+
const 最大时间戳 = 今日时间date.getTime() + (config.组队_未来天数 + 1) * 24 * 60 * 60 * 1000;
|
|
79
|
+
if (截止时间戳 > 最大时间戳 || 截止时间戳 < 当前时间date.getTime()) {
|
|
78
80
|
return '只支持输入未来' + config.组队_未来天数 + '天的时间哦~';
|
|
79
81
|
}
|
|
80
82
|
;
|
|
81
|
-
const { nickname } = await session.onebot.getGroupMemberInfo(
|
|
82
|
-
await ctx.database.upsert('toram_team', [{ id: `${
|
|
83
|
+
const { nickname } = await session.onebot.getGroupMemberInfo(guildId, userId, true);
|
|
84
|
+
await ctx.database.upsert('toram_team', [{ id: `${guildId}${userId}`, form: guildId, member_id: userId, member_name: nickname, until_Unix: 截止时间戳, until_string: 截止时间, content: 组队内容 }]);
|
|
83
85
|
return '成功发布求组信息到组队大厅!';
|
|
84
86
|
});
|
|
85
87
|
ctx.command('组队大厅 [页码]').action(async ({ session }, 输入页码) => {
|
|
86
88
|
{
|
|
87
|
-
let 起始索引 = 0;
|
|
88
|
-
let 结束索引 = 0;
|
|
89
|
-
let 页码 = 0;
|
|
90
89
|
const 当前时间date = new Date();
|
|
91
90
|
await ctx.database.remove('toram_team', { until_Unix: { $lte: 当前时间date.getTime() } });
|
|
92
91
|
const 本群组队 = await ctx.database.get('toram_team', { form: session.guildId });
|
|
93
92
|
const 本群组队数 = 本群组队.length;
|
|
94
93
|
const 总页数 = Math.max(Math.ceil(本群组队数 / 10), 1);
|
|
95
|
-
|
|
96
|
-
页码 = 1;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
页码 = 输入页码;
|
|
100
|
-
}
|
|
101
|
-
;
|
|
94
|
+
const 页码 = 输入页码 == undefined || Number.isInteger(Number(输入页码)) == false || 输入页码 <= 0 || isNaN(Number(输入页码)) || 输入页码 > 总页数 ? 1 : 输入页码;
|
|
102
95
|
text = '组队大厅 第' + 页码 + '/' + 总页数 + '页\n\n';
|
|
103
96
|
if (本群组队数 == 0) {
|
|
104
97
|
text += '【还没有人发布组队信息呢】';
|
|
105
98
|
}
|
|
106
99
|
else {
|
|
107
|
-
起始索引 = (页码 - 1) * 10;
|
|
108
|
-
结束索引 = Math.min(页码 * 10, 本群组队数);
|
|
100
|
+
const 起始索引 = (页码 - 1) * 10;
|
|
101
|
+
const 结束索引 = Math.min(页码 * 10, 本群组队数);
|
|
109
102
|
const 目标页数据 = 本群组队.slice(起始索引, 结束索引);
|
|
110
103
|
const 目标页信息结果 = 目标页数据.map((team) => {
|
|
111
104
|
return `${team?.member_name} ${team?.until_string} ${team?.content}`;
|