@hieuzest/koishi-plugin-mahjongpub 0.1.3 → 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 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',
@@ -20,6 +22,7 @@ class MahjongPub {
20
22
  });
21
23
  ctx.command('mahjongpub.team.bind <pw:string>')
22
24
  .alias('!绑定', '!绑定')
25
+ .option('user', '-u <user:user>')
23
26
  .option('channel', '-c <channel:channel>')
24
27
  .userFields(['mahjongpub/bind-team'])
25
28
  .channelFields(['mahjongpub/bind-team'])
@@ -34,7 +37,9 @@ class MahjongPub {
34
37
  ctx.logger.warn(e);
35
38
  return session.text('.failed');
36
39
  }
37
- if (options.channel)
40
+ if (options.user)
41
+ ctx.database.setUser(...parsePlatform(options.user), { 'mahjongpub/bind-team': pw });
42
+ else if (options.channel)
38
43
  ctx.database.setChannel(...parsePlatform(options.channel), { 'mahjongpub/bind-team': pw });
39
44
  else if (session.isDirect)
40
45
  session.user['mahjongpub/bind-team'] = pw;
@@ -49,7 +54,7 @@ class MahjongPub {
49
54
  .channelFields(['mahjongpub/bind-team'])
50
55
  .action(async ({ session, options }) => {
51
56
  const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
52
- : 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'];
53
58
  if (!pw)
54
59
  return config.informNotbind ? session.text('.notbind') : '';
55
60
  if (session.isDirect)
@@ -74,7 +79,9 @@ class MahjongPub {
74
79
  .channelFields(['mahjongpub/bind-team'])
75
80
  .action(async ({ session, options }) => {
76
81
  const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
77
- : 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'];
83
+ if (!pw)
84
+ return config.informNotbind ? session.text('.notbind') : '';
78
85
  const team = new api_1.Team(ctx, pw, config);
79
86
  try {
80
87
  await team.read();
@@ -85,6 +92,53 @@ class MahjongPub {
85
92
  return session.text('.failed');
86
93
  }
87
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
+ });
88
142
  ctx.command('mahjongpub.team.add <...users:string>')
89
143
  .alias('!添加', '!添加')
90
144
  .option('channel', '-c <channel:channel>')
@@ -92,7 +146,7 @@ class MahjongPub {
92
146
  .channelFields(['mahjongpub/bind-team'])
93
147
  .action(async ({ session, options }, ...users) => {
94
148
  const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
95
- : 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'];
96
150
  if (!pw)
97
151
  return config.informNotbind ? session.text('.notbind') : '';
98
152
  const team = new api_1.Team(ctx, pw, config);
@@ -114,7 +168,7 @@ class MahjongPub {
114
168
  .channelFields(['mahjongpub/bind-team'])
115
169
  .action(async ({ session, options }, ...indices) => {
116
170
  const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
117
- : 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'];
118
172
  if (!pw)
119
173
  return config.informNotbind ? session.text('.notbind') : '';
120
174
  const team = new api_1.Team(ctx, pw, config);
@@ -136,7 +190,7 @@ class MahjongPub {
136
190
  .channelFields(['mahjongpub/bind-team'])
137
191
  .action(async ({ session, options }, ...indices) => {
138
192
  const pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
139
- : 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'];
140
194
  if (!pw)
141
195
  return config.informNotbind ? session.text('.notbind') : '';
142
196
  if (indices.length % 2 !== 0)
@@ -162,6 +216,7 @@ exports.MahjongPub = MahjongPub;
162
216
  (function (MahjongPub) {
163
217
  MahjongPub.inject = {
164
218
  required: ['database'],
219
+ optional: ['assets'],
165
220
  };
166
221
  MahjongPub.Config = koishi_1.Schema.object({
167
222
  informNotbind: koishi_1.Schema.boolean().default(false),
@@ -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":"成功"}}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hieuzest/koishi-plugin-mahjongpub",
3
3
  "description": "Mahjong.pub API",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [