koishi-plugin-steam-info-check 1.0.5 → 1.0.6
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 +36 -8
- package/package.json +1 -1
- package/src/index.ts +38 -8
package/dist/index.js
CHANGED
|
@@ -127,8 +127,8 @@ function apply(ctx, config) {
|
|
|
127
127
|
const profile = await ctx.steam.getUserData(steamId);
|
|
128
128
|
const image = await ctx.drawer.drawPlayerStatus(profile, steamId);
|
|
129
129
|
if (typeof image === 'string')
|
|
130
|
-
return
|
|
131
|
-
return
|
|
130
|
+
return image;
|
|
131
|
+
return koishi_1.h.image(image, 'image/png');
|
|
132
132
|
}
|
|
133
133
|
catch (err) {
|
|
134
134
|
exports.logger.error(err);
|
|
@@ -148,15 +148,15 @@ function apply(ctx, config) {
|
|
|
148
148
|
const summaries = await ctx.steam.getPlayerSummaries(steamIds);
|
|
149
149
|
if (summaries.length === 0)
|
|
150
150
|
return session.text('.api_error');
|
|
151
|
-
const channelInfo = await ctx
|
|
152
|
-
const parentAvatar = channelInfo
|
|
153
|
-
? Buffer.from(channelInfo
|
|
151
|
+
const channelInfo = await ensureChannelMeta(ctx, session);
|
|
152
|
+
const parentAvatar = channelInfo.avatar
|
|
153
|
+
? Buffer.from(channelInfo.avatar, 'base64')
|
|
154
154
|
: await ctx.drawer.getDefaultAvatar();
|
|
155
|
-
const parentName = channelInfo
|
|
155
|
+
const parentName = channelInfo.name || session.channelId || 'Unknown';
|
|
156
156
|
const image = await ctx.drawer.drawFriendsStatus(parentAvatar, parentName, summaries, binds);
|
|
157
157
|
if (typeof image === 'string')
|
|
158
|
-
return
|
|
159
|
-
return
|
|
158
|
+
return image;
|
|
159
|
+
return koishi_1.h.image(image, 'image/png');
|
|
160
160
|
}
|
|
161
161
|
catch (err) {
|
|
162
162
|
exports.logger.error(err);
|
|
@@ -236,6 +236,34 @@ function apply(ctx, config) {
|
|
|
236
236
|
}
|
|
237
237
|
// Broadcast Logic
|
|
238
238
|
const statusCache = new Map();
|
|
239
|
+
async function ensureChannelMeta(ctx, session) {
|
|
240
|
+
const channelId = session.channelId;
|
|
241
|
+
const existing = await ctx.database.get('steam_channel', { id: channelId });
|
|
242
|
+
const current = existing[0] || { id: channelId, enable: true, platform: session.platform, assignee: session.selfId };
|
|
243
|
+
let name = current.name;
|
|
244
|
+
if (!name && session.event?.channel?.name) {
|
|
245
|
+
name = session.event.channel.name;
|
|
246
|
+
}
|
|
247
|
+
let avatar = current.avatar;
|
|
248
|
+
if (!avatar) {
|
|
249
|
+
try {
|
|
250
|
+
// For QQ group avatars
|
|
251
|
+
const url = `http://p.qlogo.cn/gh/${channelId}/${channelId}/0`;
|
|
252
|
+
const buffer = await ctx.http.get(url, { responseType: 'arraybuffer' });
|
|
253
|
+
avatar = Buffer.from(buffer).toString('base64');
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// fallback later to default avatar
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const update = { id: channelId, platform: session.platform, assignee: session.selfId };
|
|
260
|
+
if (name)
|
|
261
|
+
update.name = name;
|
|
262
|
+
if (avatar)
|
|
263
|
+
update.avatar = avatar;
|
|
264
|
+
await ctx.database.upsert('steam_channel', [update]);
|
|
265
|
+
return { ...current, ...update };
|
|
266
|
+
}
|
|
239
267
|
async function seedStatusCache(ctx) {
|
|
240
268
|
const binds = await ctx.database.get('steam_bind', {});
|
|
241
269
|
if (!binds.length)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -157,8 +157,8 @@ export function apply(ctx: Context, config: Config) {
|
|
|
157
157
|
|
|
158
158
|
const profile = await ctx.steam.getUserData(steamId)
|
|
159
159
|
const image = await ctx.drawer.drawPlayerStatus(profile, steamId)
|
|
160
|
-
if (typeof image === 'string') return
|
|
161
|
-
return
|
|
160
|
+
if (typeof image === 'string') return image
|
|
161
|
+
return h.image(image, 'image/png')
|
|
162
162
|
} catch (err) {
|
|
163
163
|
logger.error(err)
|
|
164
164
|
return session.text('.error')
|
|
@@ -178,15 +178,15 @@ export function apply(ctx: Context, config: Config) {
|
|
|
178
178
|
|
|
179
179
|
if (summaries.length === 0) return session.text('.api_error')
|
|
180
180
|
|
|
181
|
-
const channelInfo = await ctx
|
|
182
|
-
const parentAvatar = channelInfo
|
|
183
|
-
? Buffer.from(channelInfo
|
|
181
|
+
const channelInfo = await ensureChannelMeta(ctx, session)
|
|
182
|
+
const parentAvatar = channelInfo.avatar
|
|
183
|
+
? Buffer.from(channelInfo.avatar, 'base64')
|
|
184
184
|
: await ctx.drawer.getDefaultAvatar()
|
|
185
|
-
const parentName = channelInfo
|
|
185
|
+
const parentName = channelInfo.name || session.channelId || 'Unknown'
|
|
186
186
|
|
|
187
187
|
const image = await ctx.drawer.drawFriendsStatus(parentAvatar, parentName, summaries, binds)
|
|
188
|
-
if (typeof image === 'string') return
|
|
189
|
-
return
|
|
188
|
+
if (typeof image === 'string') return image
|
|
189
|
+
return h.image(image, 'image/png')
|
|
190
190
|
} catch (err) {
|
|
191
191
|
logger.error(err)
|
|
192
192
|
return session.text('.error')
|
|
@@ -269,6 +269,36 @@ export function apply(ctx: Context, config: Config) {
|
|
|
269
269
|
// Broadcast Logic
|
|
270
270
|
const statusCache = new Map<string, any>()
|
|
271
271
|
|
|
272
|
+
async function ensureChannelMeta(ctx: Context, session: Session) {
|
|
273
|
+
const channelId = session.channelId
|
|
274
|
+
const existing = await ctx.database.get('steam_channel', { id: channelId })
|
|
275
|
+
const current = existing[0] || { id: channelId, enable: true, platform: session.platform, assignee: session.selfId }
|
|
276
|
+
|
|
277
|
+
let name = current.name
|
|
278
|
+
if (!name && session.event?.channel?.name) {
|
|
279
|
+
name = session.event.channel.name
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
let avatar = current.avatar
|
|
283
|
+
if (!avatar) {
|
|
284
|
+
try {
|
|
285
|
+
// For QQ group avatars
|
|
286
|
+
const url = `http://p.qlogo.cn/gh/${channelId}/${channelId}/0`
|
|
287
|
+
const buffer = await ctx.http.get(url, { responseType: 'arraybuffer' })
|
|
288
|
+
avatar = Buffer.from(buffer).toString('base64')
|
|
289
|
+
} catch {
|
|
290
|
+
// fallback later to default avatar
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const update: any = { id: channelId, platform: session.platform, assignee: session.selfId }
|
|
295
|
+
if (name) update.name = name
|
|
296
|
+
if (avatar) update.avatar = avatar
|
|
297
|
+
await ctx.database.upsert('steam_channel', [update])
|
|
298
|
+
|
|
299
|
+
return { ...current, ...update }
|
|
300
|
+
}
|
|
301
|
+
|
|
272
302
|
async function seedStatusCache(ctx: Context) {
|
|
273
303
|
const binds = await ctx.database.get('steam_bind', {})
|
|
274
304
|
if (!binds.length) return
|