Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
fix emoji reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorunome committed Mar 2, 2021
1 parent 46d4a71 commit 0f87dd6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
44 changes: 26 additions & 18 deletions src/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,19 +309,13 @@ export class App {
client.on("reactionAdded", async (reaction: Slack.Reaction) => {
log.verbose("Received new reaction");
const params = await this.getSendParams(puppetId, reaction.message);
const e = Emoji.get(reaction.reaction);
if (!e) {
return;
}
const e = this.slackToEmoji(`:${reaction.reaction}:`);
await this.puppet.sendReaction(params, reaction.message.ts, e);
});
client.on("reactionRemoved", async (reaction: Slack.Reaction) => {
log.verbose("Received reaction remove");
const params = await this.getSendParams(puppetId, reaction.message);
const e = Emoji.get(reaction.reaction);
if (!e) {
return;
}
const e = this.slackToEmoji(`:${reaction.reaction}:`);
await this.puppet.removeReaction(params, reaction.message.ts, e);
});
p.client = client;
Expand Down Expand Up @@ -667,11 +661,8 @@ export class App {
log.warn(`Room ${room.roomId} not found!`);
return;
}
const e = Emoji.find(reaction);
if (!e) {
return;
}
await chan.sendReaction(eventId, e.key);
const e = this.emojiToSlack(reaction).slice(1, -1);
await chan.sendReaction(eventId, e);
}

public async handleMatrixRemoveReaction(
Expand All @@ -689,11 +680,8 @@ export class App {
log.warn(`Room ${room.roomId} not found!`);
return;
}
const e = Emoji.find(reaction);
if (!e) {
return;
}
await chan.removeReaction(eventId, e.key);
const e = this.emojiToSlack(reaction).slice(1, -1);
await chan.removeReaction(eventId, e);
}

public async handleMatrixImage(
Expand Down Expand Up @@ -1078,4 +1066,24 @@ export class App {
},
};
}

private emojiToSlack(msg: string): string {
return msg.replace(/((?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])[\ufe00-\ufe0f]?)/gi, (s) => {
const e = Emoji.find(s);
if (e) {
return `:${e.key}:`;
}
return "";
});
}

private slackToEmoji(msg: string): string {
return msg.replace(/:([^\s:]+?):/gi, (s) => {
const e = Emoji.get(s);
if (Emoji.find(e + "\ufe0f")) {
return e + "\ufe0f";
}
return e;
});
}
}
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"moduleResolution": "node",
"target": "es2016",
"noImplicitAny": false,
"inlineSourceMap": true,
"outDir": "./build",
"types": ["node"],
"strictNullChecks": true,
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"incremental": true,
"sourceMap": true,
"allowJs": false
},
"compileOnSave": true,
"include": [
Expand Down

0 comments on commit 0f87dd6

Please sign in to comment.