Skip to content

Commit

Permalink
feat: supports matrix m.sticker event
Browse files Browse the repository at this point in the history
  • Loading branch information
rikumi committed Jul 30, 2024
1 parent 7772254 commit 20eb0d3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/clients/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ export class MatrixUserBotClient extends EventEmitter implements GenericClient<a
const homeServer = config.matrixHomeServer || 'matrix.org';
const accessToken = config.matrixAccessToken;
this.bot = new MatrixClient('https://' + homeServer, accessToken, storage);
this.bot.on('room.message', async (roomId: string, message: any) => {
const transformedMessage = await this.transformMessage(message, roomId);
if (transformedMessage.userId === this.botInfo?.user_id) return;
this.emit(message.content['m.new_content'] ? 'edit-message' : 'message', transformedMessage);
});
this.bot.on('room.message', this.handleMessage);
this.bot.on('room.event', this.handleMessage);
AutojoinRoomsMixin.setupOnClient(this.bot);
this.fetchBotInfo();

Expand All @@ -49,6 +46,12 @@ export class MatrixUserBotClient extends EventEmitter implements GenericClient<a
this.bot.stop();
}

public handleMessage = async (roomId: string, message: any) => {
const transformedMessage = await this.transformMessage(message, roomId);
if (transformedMessage.userId === this.botInfo?.user_id) return;
this.emit(message.content['m.new_content'] ? 'edit-message' : 'message', transformedMessage);
}

public async sendMessage(message: MessageToSend): Promise<GenericMessage> {
if (message.rawUserDisplayName) {
prependMessageText(message, `${message.rawUserDisplayName}: `);
Expand Down

0 comments on commit 20eb0d3

Please sign in to comment.