Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Matrix -> Discord reactions #877

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,13 @@ export class DiscordBot {

const relatesTo = event.content['m.relates_to'];

let emoji = relatesTo.key
if (emoji.indexOf("👍") >=0 ) {
emoji = "👍"
}
Comment on lines +729 to +732

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading this if statement, I'm assuming that this is related to the skin-tones? If so, you may want to do proper parsing of those, as more than thumbs up is affected. There's also country flags which use a similar concept.


const matrixID = `${relatesTo.event_id};${event.room_id}`
const storeEvent = await this.store.Get(DbEvent, { matrix_id: matrixID });
const storeReaction = await this.store.Get(DbReaction, { matrix_id: matrixID, emoji: relatesTo.key });

if (storeReaction && storeReaction.Result) {
log.verbose(`ignoring duplicate reaction`)
}

if (!storeEvent || !storeEvent.Result) {
log.warn(`Could not react because the event was not in the store.`);
Expand All @@ -747,7 +747,7 @@ export class DiscordBot {
const msg = await chan.messages.fetch(storeEvent.DiscordId);
try {
this.channelLock.set(msg.channel.id);
await msg.react(relatesTo.key);
await msg.react(emoji);
this.channelLock.release(msg.channel.id);
log.info(`Reacted to message`);
} catch (ex) {
Expand All @@ -760,7 +760,7 @@ export class DiscordBot {
dbReaction.DiscordId = storeEvent.DiscordId;
dbReaction.ChannelId = storeEvent.ChannelId;
dbReaction.GuildId = storeEvent.GuildId;
dbReaction.Emoji = relatesTo.key;
dbReaction.Emoji = emoji;
await this.store.Insert(dbReaction);
} catch (ex) {
log.warn(`Failed to store reaction event`)
Expand Down