Skip to content

Commit 5b01e76

Browse files
KWeaver87TJ22
and
TJ22
authored
Add customizable IRC nick colors in config (#561)
Co-authored-by: TJ22 <tacojet42@yahoo.com>
1 parent 56d1c84 commit 5b01e76

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ First you need to create a Discord bot user, which you can do by following the i
107107
"webhookAvatarURL": "https://robohash.org/{$nickname}" // Default avatar to use for webhook messages
108108
},
109109
"ircNickColor": false, // Gives usernames a color in IRC for better readability (on by default)
110+
"ircNickColors": ['light_blue', 'dark_blue', 'light_red', 'dark_red', 'light_green', 'dark_green', 'magenta', 'light_magenta', 'orange', 'yellow', 'cyan', 'light_cyan'], // Which irc-upd colors to use
110111
"parallelPingFix": true, // Prevents users of both IRC and Discord from being mentioned in IRC when they speak in Discord (off by default)
111112
// Makes the bot hide the username prefix for messages that start
112113
// with one of these characters (commands):

lib/bot.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const USERNAME_MIN_LENGTH = 2;
1111
const USERNAME_MAX_LENGTH = 32;
1212

1313
const REQUIRED_FIELDS = ['server', 'nickname', 'channelMapping', 'discordToken'];
14-
const NICK_COLORS = ['light_blue', 'dark_blue', 'light_red', 'dark_red', 'light_green',
14+
const DEFAULT_NICK_COLORS = ['light_blue', 'dark_blue', 'light_red', 'dark_red', 'light_green',
1515
'dark_green', 'magenta', 'light_magenta', 'orange', 'yellow', 'cyan', 'light_cyan'];
1616
const patternMatch = /{\$(.+?)}/g;
1717

@@ -37,6 +37,7 @@ class Bot {
3737
this.discordToken = options.discordToken;
3838
this.commandCharacters = options.commandCharacters || [];
3939
this.ircNickColor = options.ircNickColor !== false; // default to true
40+
this.ircNickColors = options.ircNickColors || DEFAULT_NICK_COLORS;
4041
this.parallelPingFix = options.parallelPingFix === true; // default: false
4142
this.channels = _.values(options.channelMapping);
4243
this.ircStatusNotices = options.ircStatusNotices;
@@ -344,8 +345,8 @@ class Bot {
344345
}
345346

346347
if (this.ircNickColor) {
347-
const colorIndex = (nickname.charCodeAt(0) + nickname.length) % NICK_COLORS.length;
348-
displayUsername = irc.colors.wrap(NICK_COLORS[colorIndex], displayUsername);
348+
const colorIndex = (nickname.charCodeAt(0) + nickname.length) % this.ircNickColors.length;
349+
displayUsername = irc.colors.wrap(this.ircNickColors[colorIndex], displayUsername);
349350
}
350351

351352
const patternMap = {

test/bot.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,28 @@ describe('Bot', function () {
172172
ClientStub.prototype.say.should.have.been.calledWith('#irc', expected);
173173
});
174174

175+
it('should only use message color defined in config', function () {
176+
const text = 'testmessage';
177+
const newConfig = { ...config, ircNickColors: ['orange'] };
178+
this.setCustomBot(newConfig);
179+
const message = {
180+
content: text,
181+
mentions: { users: [] },
182+
channel: {
183+
name: 'discord'
184+
},
185+
author: {
186+
username: 'otherauthor',
187+
id: 'not bot id'
188+
},
189+
guild: this.guild
190+
};
191+
192+
this.bot.sendToIRC(message);
193+
const expected = `<\u000307${message.author.username}\u000f> ${text}`;
194+
ClientStub.prototype.say.should.have.been.calledWith('#irc', expected);
195+
});
196+
175197
it('should send correct messages to irc', function () {
176198
const text = 'testmessage';
177199
const message = {

0 commit comments

Comments
 (0)