Add customizable IRC nick colors in config (#561)
Co-authored-by: TJ22 <tacojet42@yahoo.com>
This commit is contained in:
parent
56d1c84147
commit
5b01e7639f
@ -107,6 +107,7 @@ First you need to create a Discord bot user, which you can do by following the i
|
||||
"webhookAvatarURL": "https://robohash.org/{$nickname}" // Default avatar to use for webhook messages
|
||||
},
|
||||
"ircNickColor": false, // Gives usernames a color in IRC for better readability (on by default)
|
||||
"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
|
||||
"parallelPingFix": true, // Prevents users of both IRC and Discord from being mentioned in IRC when they speak in Discord (off by default)
|
||||
// Makes the bot hide the username prefix for messages that start
|
||||
// with one of these characters (commands):
|
||||
|
@ -11,7 +11,7 @@ const USERNAME_MIN_LENGTH = 2;
|
||||
const USERNAME_MAX_LENGTH = 32;
|
||||
|
||||
const REQUIRED_FIELDS = ['server', 'nickname', 'channelMapping', 'discordToken'];
|
||||
const NICK_COLORS = ['light_blue', 'dark_blue', 'light_red', 'dark_red', 'light_green',
|
||||
const DEFAULT_NICK_COLORS = ['light_blue', 'dark_blue', 'light_red', 'dark_red', 'light_green',
|
||||
'dark_green', 'magenta', 'light_magenta', 'orange', 'yellow', 'cyan', 'light_cyan'];
|
||||
const patternMatch = /{\$(.+?)}/g;
|
||||
|
||||
@ -37,6 +37,7 @@ class Bot {
|
||||
this.discordToken = options.discordToken;
|
||||
this.commandCharacters = options.commandCharacters || [];
|
||||
this.ircNickColor = options.ircNickColor !== false; // default to true
|
||||
this.ircNickColors = options.ircNickColors || DEFAULT_NICK_COLORS;
|
||||
this.parallelPingFix = options.parallelPingFix === true; // default: false
|
||||
this.channels = _.values(options.channelMapping);
|
||||
this.ircStatusNotices = options.ircStatusNotices;
|
||||
@ -344,8 +345,8 @@ class Bot {
|
||||
}
|
||||
|
||||
if (this.ircNickColor) {
|
||||
const colorIndex = (nickname.charCodeAt(0) + nickname.length) % NICK_COLORS.length;
|
||||
displayUsername = irc.colors.wrap(NICK_COLORS[colorIndex], displayUsername);
|
||||
const colorIndex = (nickname.charCodeAt(0) + nickname.length) % this.ircNickColors.length;
|
||||
displayUsername = irc.colors.wrap(this.ircNickColors[colorIndex], displayUsername);
|
||||
}
|
||||
|
||||
const patternMap = {
|
||||
|
@ -172,6 +172,28 @@ describe('Bot', function () {
|
||||
ClientStub.prototype.say.should.have.been.calledWith('#irc', expected);
|
||||
});
|
||||
|
||||
it('should only use message color defined in config', function () {
|
||||
const text = 'testmessage';
|
||||
const newConfig = { ...config, ircNickColors: ['orange'] };
|
||||
this.setCustomBot(newConfig);
|
||||
const message = {
|
||||
content: text,
|
||||
mentions: { users: [] },
|
||||
channel: {
|
||||
name: 'discord'
|
||||
},
|
||||
author: {
|
||||
username: 'otherauthor',
|
||||
id: 'not bot id'
|
||||
},
|
||||
guild: this.guild
|
||||
};
|
||||
|
||||
this.bot.sendToIRC(message);
|
||||
const expected = `<\u000307${message.author.username}\u000f> ${text}`;
|
||||
ClientStub.prototype.say.should.have.been.calledWith('#irc', expected);
|
||||
});
|
||||
|
||||
it('should send correct messages to irc', function () {
|
||||
const text = 'testmessage';
|
||||
const message = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user