@hieuzest/koishi-plugin-mahjongpub 0.1.4 → 0.1.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.d.ts +2 -0
- package/lib/index.js +55 -5
- package/lib/locales/zh-CN.json +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -8,11 +8,13 @@ declare module 'koishi' {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export declare class MahjongPub {
|
|
11
|
+
private ctx;
|
|
11
12
|
constructor(ctx: Context, config: MahjongPub.Config);
|
|
12
13
|
}
|
|
13
14
|
export declare namespace MahjongPub {
|
|
14
15
|
const inject: {
|
|
15
16
|
required: string[];
|
|
17
|
+
optional: string[];
|
|
16
18
|
};
|
|
17
19
|
interface Config {
|
|
18
20
|
informNotbind: boolean;
|
package/lib/index.js
CHANGED
|
@@ -10,7 +10,9 @@ function parsePlatform(target) {
|
|
|
10
10
|
return [platform, id];
|
|
11
11
|
}
|
|
12
12
|
class MahjongPub {
|
|
13
|
+
ctx;
|
|
13
14
|
constructor(ctx, config) {
|
|
15
|
+
this.ctx = ctx;
|
|
14
16
|
ctx.i18n.define('zh-CN', require('./locales/zh-CN'));
|
|
15
17
|
ctx.model.extend('user', {
|
|
16
18
|
'mahjongpub/bind-team': 'string',
|
|
@@ -52,7 +54,7 @@ class MahjongPub {
|
|
|
52
54
|
.channelFields(['mahjongpub/bind-team'])
|
|
53
55
|
.action(async ({ session, options }) => {
|
|
54
56
|
const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
|
|
55
|
-
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'];
|
|
57
|
+
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
|
|
56
58
|
if (!pw)
|
|
57
59
|
return config.informNotbind ? session.text('.notbind') : '';
|
|
58
60
|
if (session.isDirect)
|
|
@@ -77,7 +79,7 @@ class MahjongPub {
|
|
|
77
79
|
.channelFields(['mahjongpub/bind-team'])
|
|
78
80
|
.action(async ({ session, options }) => {
|
|
79
81
|
const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
|
|
80
|
-
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'];
|
|
82
|
+
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
|
|
81
83
|
if (!pw)
|
|
82
84
|
return config.informNotbind ? session.text('.notbind') : '';
|
|
83
85
|
const team = new api_1.Team(ctx, pw, config);
|
|
@@ -90,6 +92,53 @@ class MahjongPub {
|
|
|
90
92
|
return session.text('.failed');
|
|
91
93
|
}
|
|
92
94
|
});
|
|
95
|
+
ctx.command('mahjongpub.team.desc [desc:rawtext]')
|
|
96
|
+
.alias('!简介', '!简介')
|
|
97
|
+
.option('channel', '-c <channel:channel>')
|
|
98
|
+
.userFields(['mahjongpub/bind-team'])
|
|
99
|
+
.channelFields(['mahjongpub/bind-team'])
|
|
100
|
+
.action(async ({ session, options }, desc) => {
|
|
101
|
+
const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
|
|
102
|
+
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
|
|
103
|
+
if (!pw)
|
|
104
|
+
return config.informNotbind ? session.text('.notbind') : '';
|
|
105
|
+
const team = new api_1.Team(ctx, pw, config);
|
|
106
|
+
try {
|
|
107
|
+
await team.read();
|
|
108
|
+
if (!desc)
|
|
109
|
+
return session.text('.output', team);
|
|
110
|
+
team.description = desc;
|
|
111
|
+
return await team.write();
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
ctx.logger.warn(e);
|
|
115
|
+
return session.text('.failed');
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
ctx.command('mahjongpub.team.logo [img:img]')
|
|
119
|
+
.alias('!头像', '!头像')
|
|
120
|
+
.option('channel', '-c <channel:channel>')
|
|
121
|
+
.userFields(['mahjongpub/bind-team'])
|
|
122
|
+
.channelFields(['mahjongpub/bind-team'])
|
|
123
|
+
.action(async ({ session, options }, img) => {
|
|
124
|
+
const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
|
|
125
|
+
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
|
|
126
|
+
if (!pw)
|
|
127
|
+
return config.informNotbind ? session.text('.notbind') : '';
|
|
128
|
+
const team = new api_1.Team(ctx, pw, config);
|
|
129
|
+
try {
|
|
130
|
+
await team.read();
|
|
131
|
+
if (!img)
|
|
132
|
+
return koishi_1.h.image(team.img);
|
|
133
|
+
const url = await ctx.assets.upload('https://koishi.chat/logo.png', `${session.id}-${session.timestamp}.png`);
|
|
134
|
+
team.img = url;
|
|
135
|
+
return await team.write();
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
ctx.logger.warn(e);
|
|
139
|
+
return session.text('.failed');
|
|
140
|
+
}
|
|
141
|
+
});
|
|
93
142
|
ctx.command('mahjongpub.team.add <...users:string>')
|
|
94
143
|
.alias('!添加', '!添加')
|
|
95
144
|
.option('channel', '-c <channel:channel>')
|
|
@@ -97,7 +146,7 @@ class MahjongPub {
|
|
|
97
146
|
.channelFields(['mahjongpub/bind-team'])
|
|
98
147
|
.action(async ({ session, options }, ...users) => {
|
|
99
148
|
const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
|
|
100
|
-
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'];
|
|
149
|
+
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
|
|
101
150
|
if (!pw)
|
|
102
151
|
return config.informNotbind ? session.text('.notbind') : '';
|
|
103
152
|
const team = new api_1.Team(ctx, pw, config);
|
|
@@ -119,7 +168,7 @@ class MahjongPub {
|
|
|
119
168
|
.channelFields(['mahjongpub/bind-team'])
|
|
120
169
|
.action(async ({ session, options }, ...indices) => {
|
|
121
170
|
const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
|
|
122
|
-
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'];
|
|
171
|
+
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
|
|
123
172
|
if (!pw)
|
|
124
173
|
return config.informNotbind ? session.text('.notbind') : '';
|
|
125
174
|
const team = new api_1.Team(ctx, pw, config);
|
|
@@ -141,7 +190,7 @@ class MahjongPub {
|
|
|
141
190
|
.channelFields(['mahjongpub/bind-team'])
|
|
142
191
|
.action(async ({ session, options }, ...indices) => {
|
|
143
192
|
const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
|
|
144
|
-
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'];
|
|
193
|
+
: session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
|
|
145
194
|
if (!pw)
|
|
146
195
|
return config.informNotbind ? session.text('.notbind') : '';
|
|
147
196
|
if (indices.length % 2 !== 0)
|
|
@@ -167,6 +216,7 @@ exports.MahjongPub = MahjongPub;
|
|
|
167
216
|
(function (MahjongPub) {
|
|
168
217
|
MahjongPub.inject = {
|
|
169
218
|
required: ['database'],
|
|
219
|
+
optional: ['assets'],
|
|
170
220
|
};
|
|
171
221
|
MahjongPub.Config = koishi_1.Schema.object({
|
|
172
222
|
informNotbind: koishi_1.Schema.boolean().default(false),
|
package/lib/locales/zh-CN.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commands":{"mahjongpub.team.bind":{"description":"绑定队伍","messages":{"failed":"绑定失败","success":"成功: [{cid}:{tid}] {name}"}},"mahjongpub.team.unbind":{"description":"解除绑定","messages":{"notbind":"未绑定","success":"成功"}},"mahjongpub.team.password":{"description":"查看密码","messages":{"notbind":"未绑定","output":"密码: {0}"}},"mahjongpub.team.stats":{"description":"查看队伍信息","messages":{"notbind":"未绑定","failed":"失败","output":"- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n"}},"mahjongpub.team.add":{"description":"添加队员","messages":{"notbind":"未绑定","failed":"失败","success":"成功"}},"mahjongpub.team.remove":{"description":"删除队员","messages":{"notbind":"未绑定","failed":"失败","success":"成功"}},"mahjongpub.team.swap":{"description":"交换队员","messages":{"notbind":"未绑定","failed":"失败","success":"成功"}}}}
|
|
1
|
+
{"commands":{"mahjongpub.team.bind":{"description":"绑定队伍","messages":{"failed":"绑定失败","success":"成功: [{cid}:{tid}] {name}"}},"mahjongpub.team.unbind":{"description":"解除绑定","messages":{"notbind":"未绑定","success":"成功"}},"mahjongpub.team.password":{"description":"查看密码","messages":{"notbind":"未绑定","output":"密码: {0}"}},"mahjongpub.team.stats":{"description":"查看队伍信息","messages":{"notbind":"未绑定","failed":"失败","output":"- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n"}},"mahjongpub.team.desc":{"description":"队伍简介","messages":{"notbind":"未绑定","failed":"失败","output":"- [{cid}:{tid}] {name}\n{description}\n"}},"mahjongpub.team.logo":{"description":"队伍头像","messages":{"notbind":"未绑定","failed":"失败"}},"mahjongpub.team.add":{"description":"添加队员","messages":{"notbind":"未绑定","failed":"失败","success":"成功"}},"mahjongpub.team.remove":{"description":"删除队员","messages":{"notbind":"未绑定","failed":"失败","success":"成功"}},"mahjongpub.team.swap":{"description":"交换队员","messages":{"notbind":"未绑定","failed":"失败","success":"成功"}}}}
|