From fddcc902e7f513b9ff55589bd0665658826e8746 Mon Sep 17 00:00:00 2001 From: "Michael D. Reiley" Date: Fri, 1 Oct 2021 10:35:07 -0800 Subject: [PATCH] Add unemojify option to textify emojis, fixes #192 --- README.md | 1 + lib/bot.js | 6 ++++++ package-lock.json | 10 +++++++++- package.json | 3 ++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b15a1970..31a169ae 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ First you need to create a Discord bot user, which you can do by following the i "sasl": true, // false by default "username": "test", // nodeirc by default "password": "p455w0rd" // empty by default + "unemojify": true // Textify emojis from messages send to Discord, false by default }, "format": { // Optional custom formatting options // Patterns, represented by {$patternName}, are replaced when sending messages diff --git a/lib/bot.js b/lib/bot.js index b05ef160..fe6027d9 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import irc from 'irc-upd'; import discord from 'discord.js'; +import { unemojify } from 'node-emoji'; import logger from './logger'; import { ConfigurationError } from './errors'; import { validateChannelMapping } from './validators'; @@ -46,6 +47,7 @@ class Bot { this.ircStatusNotices = options.ircStatusNotices; this.announceSelfJoin = options.announceSelfJoin; this.webhookOptions = options.webhooks; + this.unemojifyMessages = options.unemojifyMessages === true; // default: false // Nicks to ignore this.ignoreUsers = options.ignoreUsers || {}; @@ -361,6 +363,10 @@ class Bot { ircChannel }; + if (this.unemojifyMessages) { + text = unemojify(text); + } + if (this.isCommandMessage(text)) { patternMap.side = 'Discord'; logger.debug('Sending command message to IRC', ircChannel, text); diff --git a/package-lock.json b/package-lock.json index f4e992f6..9391e2ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "discord-irc", - "version": "2.9.0", + "version": "2.9.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -4516,6 +4516,14 @@ "path-to-regexp": "^1.7.0" } }, + "node-emoji": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz", + "integrity": "sha512-wo2DpQkQp7Sjm2A0cq+sN7EHKO6Sl0ctXeBdFZrL9T9+UywORbufTcTZxom8YqpLQt/FqNMUkOpkZrJVYSKD3A==", + "requires": { + "lodash": "^4.17.21" + } + }, "node-fetch": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", diff --git a/package.json b/package.json index 729eaf3b..00eab580 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-irc", - "version": "2.9.0", + "version": "2.9.1", "description": "Connects IRC and Discord channels by sending messages back and forth.", "keywords": [ "discord", @@ -42,6 +42,7 @@ "irc-formatting": "1.0.0-rc3", "irc-upd": "0.11.0", "lodash": "^4.17.21", + "node-emoji": "^1.11.0", "simple-markdown": "^0.7.3", "strip-json-comments": "^3.1.1", "winston": "^3.3.3"