koishi-plugin-steam-info-check 1.0.5 → 1.0.7
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/dist/index.js +49 -9
- package/package.json +1 -1
- package/src/index.ts +49 -9
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.logger = new koishi_1.Logger('steam-info');
|
|
|
37
37
|
function apply(ctx, config) {
|
|
38
38
|
// Localization
|
|
39
39
|
ctx.i18n.define('zh-CN', zh_CN_1.default);
|
|
40
|
+
ctx.i18n.define('zh', zh_CN_1.default);
|
|
40
41
|
// Services
|
|
41
42
|
ctx.plugin(service_1.SteamService, config);
|
|
42
43
|
ctx.plugin(drawer_1.DrawService, config);
|
|
@@ -63,7 +64,7 @@ function apply(ctx, config) {
|
|
|
63
64
|
});
|
|
64
65
|
// Commands and scheduler depend on steam/drawer being ready
|
|
65
66
|
ctx.using(['steam', 'drawer'], (ctx) => {
|
|
66
|
-
ctx.command('steam', 'Steam
|
|
67
|
+
ctx.command('steam', 'Steam 信息');
|
|
67
68
|
ctx.command('steam.bind <steamId:string>', 'Bind Steam ID', { authority: config.commandAuthority.bind })
|
|
68
69
|
.alias('steambind', '绑定steam')
|
|
69
70
|
.action(async ({ session }, steamId) => {
|
|
@@ -127,8 +128,8 @@ function apply(ctx, config) {
|
|
|
127
128
|
const profile = await ctx.steam.getUserData(steamId);
|
|
128
129
|
const image = await ctx.drawer.drawPlayerStatus(profile, steamId);
|
|
129
130
|
if (typeof image === 'string')
|
|
130
|
-
return
|
|
131
|
-
return
|
|
131
|
+
return image;
|
|
132
|
+
return koishi_1.h.image(image, 'image/png');
|
|
132
133
|
}
|
|
133
134
|
catch (err) {
|
|
134
135
|
exports.logger.error(err);
|
|
@@ -148,15 +149,15 @@ function apply(ctx, config) {
|
|
|
148
149
|
const summaries = await ctx.steam.getPlayerSummaries(steamIds);
|
|
149
150
|
if (summaries.length === 0)
|
|
150
151
|
return session.text('.api_error');
|
|
151
|
-
const channelInfo = await ctx
|
|
152
|
-
const parentAvatar = channelInfo
|
|
153
|
-
? Buffer.from(channelInfo
|
|
152
|
+
const channelInfo = await ensureChannelMeta(ctx, session);
|
|
153
|
+
const parentAvatar = channelInfo.avatar
|
|
154
|
+
? Buffer.from(channelInfo.avatar, 'base64')
|
|
154
155
|
: await ctx.drawer.getDefaultAvatar();
|
|
155
|
-
const parentName = channelInfo
|
|
156
|
+
const parentName = channelInfo.name || session.channelId || 'Unknown';
|
|
156
157
|
const image = await ctx.drawer.drawFriendsStatus(parentAvatar, parentName, summaries, binds);
|
|
157
158
|
if (typeof image === 'string')
|
|
158
|
-
return
|
|
159
|
-
return
|
|
159
|
+
return image;
|
|
160
|
+
return koishi_1.h.image(image, 'image/png');
|
|
160
161
|
}
|
|
161
162
|
catch (err) {
|
|
162
163
|
exports.logger.error(err);
|
|
@@ -236,6 +237,45 @@ function apply(ctx, config) {
|
|
|
236
237
|
}
|
|
237
238
|
// Broadcast Logic
|
|
238
239
|
const statusCache = new Map();
|
|
240
|
+
async function ensureChannelMeta(ctx, session) {
|
|
241
|
+
const channelId = session.channelId;
|
|
242
|
+
const existing = await ctx.database.get('steam_channel', { id: channelId });
|
|
243
|
+
const current = existing[0] || { id: channelId, enable: true, platform: session.platform, assignee: session.selfId };
|
|
244
|
+
let name = current.name;
|
|
245
|
+
if (!name && session.event?.channel?.name) {
|
|
246
|
+
name = session.event.channel.name;
|
|
247
|
+
}
|
|
248
|
+
// OneBot 群名补充
|
|
249
|
+
if (!name && session.platform?.includes('onebot') && session.bot?.internal?.getGroupInfo) {
|
|
250
|
+
try {
|
|
251
|
+
const info = await session.bot.internal.getGroupInfo({ group_id: channelId });
|
|
252
|
+
if (info?.group_name)
|
|
253
|
+
name = info.group_name;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
/* ignore */
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
let avatar = current.avatar;
|
|
260
|
+
if (!avatar) {
|
|
261
|
+
try {
|
|
262
|
+
// For QQ group avatars
|
|
263
|
+
const url = `http://p.qlogo.cn/gh/${channelId}/${channelId}/0`;
|
|
264
|
+
const buffer = await ctx.http.get(url, { responseType: 'arraybuffer' });
|
|
265
|
+
avatar = Buffer.from(buffer).toString('base64');
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
// fallback later to default avatar
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const update = { id: channelId, platform: session.platform, assignee: session.selfId };
|
|
272
|
+
if (name)
|
|
273
|
+
update.name = name;
|
|
274
|
+
if (avatar)
|
|
275
|
+
update.avatar = avatar;
|
|
276
|
+
await ctx.database.upsert('steam_channel', [update]);
|
|
277
|
+
return { ...current, ...update };
|
|
278
|
+
}
|
|
239
279
|
async function seedStatusCache(ctx) {
|
|
240
280
|
const binds = await ctx.database.get('steam_bind', {});
|
|
241
281
|
if (!binds.length)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -65,6 +65,7 @@ declare module 'koishi' {
|
|
|
65
65
|
export function apply(ctx: Context, config: Config) {
|
|
66
66
|
// Localization
|
|
67
67
|
ctx.i18n.define('zh-CN', zhCN)
|
|
68
|
+
ctx.i18n.define('zh', zhCN)
|
|
68
69
|
|
|
69
70
|
// Services
|
|
70
71
|
ctx.plugin(SteamService, config)
|
|
@@ -95,7 +96,7 @@ export function apply(ctx: Context, config: Config) {
|
|
|
95
96
|
|
|
96
97
|
// Commands and scheduler depend on steam/drawer being ready
|
|
97
98
|
ctx.using(['steam', 'drawer'], (ctx) => {
|
|
98
|
-
ctx.command('steam', 'Steam
|
|
99
|
+
ctx.command('steam', 'Steam 信息')
|
|
99
100
|
|
|
100
101
|
ctx.command('steam.bind <steamId:string>', 'Bind Steam ID', { authority: config.commandAuthority.bind })
|
|
101
102
|
.alias('steambind', '绑定steam')
|
|
@@ -157,8 +158,8 @@ export function apply(ctx: Context, config: Config) {
|
|
|
157
158
|
|
|
158
159
|
const profile = await ctx.steam.getUserData(steamId)
|
|
159
160
|
const image = await ctx.drawer.drawPlayerStatus(profile, steamId)
|
|
160
|
-
if (typeof image === 'string') return
|
|
161
|
-
return
|
|
161
|
+
if (typeof image === 'string') return image
|
|
162
|
+
return h.image(image, 'image/png')
|
|
162
163
|
} catch (err) {
|
|
163
164
|
logger.error(err)
|
|
164
165
|
return session.text('.error')
|
|
@@ -178,15 +179,15 @@ export function apply(ctx: Context, config: Config) {
|
|
|
178
179
|
|
|
179
180
|
if (summaries.length === 0) return session.text('.api_error')
|
|
180
181
|
|
|
181
|
-
const channelInfo = await ctx
|
|
182
|
-
const parentAvatar = channelInfo
|
|
183
|
-
? Buffer.from(channelInfo
|
|
182
|
+
const channelInfo = await ensureChannelMeta(ctx, session)
|
|
183
|
+
const parentAvatar = channelInfo.avatar
|
|
184
|
+
? Buffer.from(channelInfo.avatar, 'base64')
|
|
184
185
|
: await ctx.drawer.getDefaultAvatar()
|
|
185
|
-
const parentName = channelInfo
|
|
186
|
+
const parentName = channelInfo.name || session.channelId || 'Unknown'
|
|
186
187
|
|
|
187
188
|
const image = await ctx.drawer.drawFriendsStatus(parentAvatar, parentName, summaries, binds)
|
|
188
|
-
if (typeof image === 'string') return
|
|
189
|
-
return
|
|
189
|
+
if (typeof image === 'string') return image
|
|
190
|
+
return h.image(image, 'image/png')
|
|
190
191
|
} catch (err) {
|
|
191
192
|
logger.error(err)
|
|
192
193
|
return session.text('.error')
|
|
@@ -269,6 +270,45 @@ export function apply(ctx: Context, config: Config) {
|
|
|
269
270
|
// Broadcast Logic
|
|
270
271
|
const statusCache = new Map<string, any>()
|
|
271
272
|
|
|
273
|
+
async function ensureChannelMeta(ctx: Context, session: Session) {
|
|
274
|
+
const channelId = session.channelId
|
|
275
|
+
const existing = await ctx.database.get('steam_channel', { id: channelId })
|
|
276
|
+
const current = existing[0] || { id: channelId, enable: true, platform: session.platform, assignee: session.selfId }
|
|
277
|
+
|
|
278
|
+
let name = current.name
|
|
279
|
+
if (!name && session.event?.channel?.name) {
|
|
280
|
+
name = session.event.channel.name
|
|
281
|
+
}
|
|
282
|
+
// OneBot 群名补充
|
|
283
|
+
if (!name && session.platform?.includes('onebot') && session.bot?.internal?.getGroupInfo) {
|
|
284
|
+
try {
|
|
285
|
+
const info = await session.bot.internal.getGroupInfo({ group_id: channelId })
|
|
286
|
+
if (info?.group_name) name = info.group_name
|
|
287
|
+
} catch {
|
|
288
|
+
/* ignore */
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
let avatar = current.avatar
|
|
293
|
+
if (!avatar) {
|
|
294
|
+
try {
|
|
295
|
+
// For QQ group avatars
|
|
296
|
+
const url = `http://p.qlogo.cn/gh/${channelId}/${channelId}/0`
|
|
297
|
+
const buffer = await ctx.http.get(url, { responseType: 'arraybuffer' })
|
|
298
|
+
avatar = Buffer.from(buffer).toString('base64')
|
|
299
|
+
} catch {
|
|
300
|
+
// fallback later to default avatar
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const update: any = { id: channelId, platform: session.platform, assignee: session.selfId }
|
|
305
|
+
if (name) update.name = name
|
|
306
|
+
if (avatar) update.avatar = avatar
|
|
307
|
+
await ctx.database.upsert('steam_channel', [update])
|
|
308
|
+
|
|
309
|
+
return { ...current, ...update }
|
|
310
|
+
}
|
|
311
|
+
|
|
272
312
|
async function seedStatusCache(ctx: Context) {
|
|
273
313
|
const binds = await ctx.database.get('steam_bind', {})
|
|
274
314
|
if (!binds.length) return
|