diff --git a/adapters/discord/src/ws.ts b/adapters/discord/src/ws.ts index 2c909f26..6302574d 100644 --- a/adapters/discord/src/ws.ts +++ b/adapters/discord/src/ws.ts @@ -79,10 +79,8 @@ export class WsClient extends Adapter.WsClient { if (parsed.t === 'READY') { this._sessionId = parsed.d.session_id this._resumeUrl = parsed.d.resume_gateway_url - const self: any = decodeUser(parsed.d.user) - self.selfId = self.userId - delete self.userId - Object.assign(this.bot, self) + const user = decodeUser(parsed.d.user) + Object.assign(this.bot, user) logger.debug('session_id ' + this._sessionId) return this.bot.online() } diff --git a/adapters/lark/src/utils.ts b/adapters/lark/src/utils.ts index acef0ec7..53f6e695 100644 --- a/adapters/lark/src/utils.ts +++ b/adapters/lark/src/utils.ts @@ -74,7 +74,6 @@ export function adaptMessage(bot: FeishuBot, data: Events['im.message.receive_v1 export function adaptSession(bot: FeishuBot, body: AllEvents): Session { const session = bot.session() - session.selfId = bot.selfId const internal = Object.create(bot.internal) Object.assign(internal, body) defineProperty(session, 'feishu', internal) diff --git a/adapters/line/src/bot.ts b/adapters/line/src/bot.ts index a712d424..1bbd13e7 100644 --- a/adapters/line/src/bot.ts +++ b/adapters/line/src/bot.ts @@ -33,10 +33,8 @@ export class LineBot extends Bot { } async initialize(callback: (bot: this) => Promise) { - const { userId, pictureUrl, displayName } = await this.internal.getBotInfo() - this.selfId = userId - this.username = displayName - if (pictureUrl) this.avatar = pictureUrl + const user = await this.getSelf() + Object.assign(this, user) await callback(this) this.online() } diff --git a/adapters/onebot/src/bot/index.ts b/adapters/onebot/src/bot/index.ts index 7ff7edd1..ec330c5b 100644 --- a/adapters/onebot/src/bot/index.ts +++ b/adapters/onebot/src/bot/index.ts @@ -15,7 +15,6 @@ export class OneBotBot extends Ba constructor(ctx: Context, config: T) { super(ctx, config) - this.selfId = config.selfId this.internal = new OneBot.Internal() this.avatar = `http://q.qlogo.cn/headimg_dl?dst_uin=${config.selfId}&spec=640` diff --git a/adapters/onebot/src/bot/qqguild.ts b/adapters/onebot/src/bot/qqguild.ts index 242392bf..5249d624 100644 --- a/adapters/onebot/src/bot/qqguild.ts +++ b/adapters/onebot/src/bot/qqguild.ts @@ -11,7 +11,7 @@ export namespace QQGuildBot { } export class QQGuildBot extends BaseBot { - parent: OneBotBot + declare parent: OneBotBot hidden = true constructor(ctx: Context, config: QQGuildBot.Config) { diff --git a/adapters/telegram/src/bot.ts b/adapters/telegram/src/bot.ts index 8454d5f9..d8261417 100644 --- a/adapters/telegram/src/bot.ts +++ b/adapters/telegram/src/bot.ts @@ -65,11 +65,8 @@ export class TelegramBot exte } async initialize(callback: (bot: this) => Promise) { - const { username, userId, avatar, nickname } = await this.getLoginInfo() - this.username = username - this.avatar = avatar - this.selfId = userId - this.nickname = nickname + const user = await this.getLoginInfo() + Object.assign(this, user) await callback(this) logger.debug('connected to %c', 'telegram:' + this.selfId) this.online() diff --git a/packages/core/src/bot.ts b/packages/core/src/bot.ts index 45e4f96e..ee478105 100644 --- a/packages/core/src/bot.ts +++ b/packages/core/src/bot.ts @@ -8,6 +8,7 @@ import WebSocket from 'ws' export interface Bot extends Universal.Methods, Universal.User { socket?: WebSocket + internal: any } export abstract class Bot { @@ -19,7 +20,6 @@ export abstract class Bot { public hidden = false public platform: string public selfId: string - public internal = null public adapter?: Adapter public error?: Error @@ -45,6 +45,14 @@ export abstract class Bot { }) } + get userId() { + return this.selfId + } + + set userId(value) { + this.selfId = value + } + get status() { return this._status } diff --git a/tsconfig.base.json b/tsconfig.base.json index b19ef7cf..136e9005 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es2019", + "target": "es2022", "module": "commonjs", "declaration": true, "emitDeclarationOnly": true,