Skip to content

Commit

Permalink
fix: emojis in the username
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Feb 19, 2024
1 parent 33f09b7 commit 81a1949
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/discord/handlers/MessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ class MessageHandler {
return;
}

const username = message.member.displayName ?? message.author.username;
if (username === undefined || username.length === 0) {
return;
}

const formattedUsername = this.formatEmojis(username);

const messageData = {
member: message.member.user,
channel: message.channel.id,
username: message.member.displayName.replaceAll(" ", ""),
username: formattedUsername.replaceAll(" ", ""),
message: content,
replyingTo: await this.fetchReply(message),
discord: message,
Expand Down Expand Up @@ -136,12 +143,7 @@ class MessageHandler {
const IPAddressPattern = /(?:\d{1,3}\s*\s\s*){3}\d{1,3}/g;
output = output.replaceAll(IPAddressPattern, "[IP Address Removed]");

// ? demojify() function has a bug. It throws an error when it encounters channel with emoji in its name. Example: #💬・guild-chat
try {
return demojify(output);
} catch (e) {
return output;
}
return this.formatEmojis(output);
}

shouldBroadcastMessage(message) {
Expand All @@ -156,6 +158,15 @@ class MessageHandler {

return isValid && validChannelIds.includes(message.channel.id);
}

formatEmojis(content) {
// ? demojify() function has a bug. It throws an error when it encounters channel with emoji in its name. Example: #💬・guild-chat
try {
return demojify(content);
} catch (e) {
return content;
}
}
}

module.exports = MessageHandler;
1 change: 1 addition & 0 deletions src/minecraft/MinecraftManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class MinecraftManager extends CommunicationBridge {

if (config.discord.other.filterMessages) {
message = filter.clean(message);
username = filter.clean(username);
}

message = replaceVariables(config.minecraft.bot.messageFormat, { username, message });
Expand Down

0 comments on commit 81a1949

Please sign in to comment.