Commit 6ea4e5d1 authored by nanahira's avatar nanahira

fix message history

parent 5523c6c9
......@@ -34,6 +34,12 @@ export class WechatyAdapter extends Adapter.Client<WechatyBot> {
if (!payload) return;
payload.timestamp ??= timestamp;
const session = this.bot.session(payload);
if (
session.type === 'message' &&
Date.now() - this.bot.loginTime < 1000
) {
return;
}
this.bot.dispatch(session);
});
});
......@@ -43,6 +49,7 @@ export class WechatyAdapter extends Adapter.Client<WechatyBot> {
this.adaptEvent('message', async (message) => {
const adaptedMessage = await adaptMessage(this.bot, message);
if (!adaptedMessage) return;
// console.log(`Got message type ${message.type()}`);
return {
...adaptedMessage,
type:
......
......@@ -69,11 +69,14 @@ export default class WechatyBot extends Bot<
return PluginDef(WechatyAdapter, this);
}
loginTime: number;
async initialize() {
this.internal.on('login', async (user) => {
this.selfId = user.id;
this.username = user.name();
this.avatar = await fileBoxToUrl(await user.avatar());
this.loginTime = Date.now();
this.online();
});
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