Commit db49d9e2 authored by nanahira's avatar nanahira

update bot self info

parent f1584890
...@@ -19,7 +19,9 @@ app.plugin(TargetPlugin, { ...@@ -19,7 +19,9 @@ app.plugin(TargetPlugin, {
}); });
app.on('bot-status-updated', (bot) => app.on('bot-status-updated', (bot) =>
console.log(`Bot ${bot.selfId} status updated: ${bot.status}`), console.log(
`Bot ${bot.sid} ${bot.username} ${bot.avatar?.length} status updated: ${bot.status}`,
),
); );
app.on('message', (session) => app.on('message', (session) =>
console.log(`Got message from ${session.channelId}: ${session.content}`), console.log(`Got message from ${session.channelId}: ${session.content}`),
......
...@@ -10,10 +10,10 @@ import { ...@@ -10,10 +10,10 @@ import {
UsePlugin, UsePlugin,
} from 'koishi-thirdeye'; } from 'koishi-thirdeye';
import { Bot, Fragment, Logger, Schema, segment, SendOptions } from 'koishi'; import { Bot, Fragment, Logger, Schema, segment, SendOptions } from 'koishi';
import { WechatyBuilder } from 'wechaty'; import { WechatyBuilder, WechatyOptions } from 'wechaty';
import { WechatyEvents, WechatyInstance } from './def'; import { WechatyEvents, WechatyInstance } from './def';
import { WechatyAdapter } from './adapter'; import { WechatyAdapter } from './adapter';
import { adaptContact, adaptMessage, adaptRoom } from './utils'; import { adaptContact, adaptMessage, adaptRoom, fileBoxToUrl } from './utils';
import { WechatyMessenger } from './message'; import { WechatyMessenger } from './message';
declare module 'koishi' { declare module 'koishi' {
...@@ -48,7 +48,9 @@ export class WechatyBotConfig { ...@@ -48,7 +48,9 @@ export class WechatyBotConfig {
@Reusable() @Reusable()
@PluginSchema(WechatyBotConfig) @PluginSchema(WechatyBotConfig)
@DefinePlugin() @DefinePlugin()
export default class WechatyBot extends Bot<Partial<WechatyBotConfig>> { export default class WechatyBot extends Bot<
Partial<WechatyBotConfig & WechatyOptions>
> {
internal: WechatyInstance; internal: WechatyInstance;
@InjectLogger() @InjectLogger()
...@@ -56,17 +58,15 @@ export default class WechatyBot extends Bot<Partial<WechatyBotConfig>> { ...@@ -56,17 +58,15 @@ export default class WechatyBot extends Bot<Partial<WechatyBotConfig>> {
@UsePlugin() @UsePlugin()
loadAdapter() { loadAdapter() {
this.internal = WechatyBuilder.build({ this.internal = WechatyBuilder.build(this.config as any);
name: this.config.name,
puppetOptions: this.config.puppetOptions,
puppet: this.config.puppet as any,
});
return PluginDef(WechatyAdapter, this); return PluginDef(WechatyAdapter, this);
} }
async initialize() { async initialize() {
this.internal.on('login', (user) => { this.internal.on('login', async (user) => {
this.selfId = user.id; this.selfId = user.id;
this.username = user.name();
this.avatar = await fileBoxToUrl(await user.avatar());
this.online(); this.online();
}); });
this.internal.on('logout', () => { this.internal.on('logout', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment