Use default nick set in config for fallback

This commit is contained in:
Pavel Djundik 2018-04-03 17:49:22 +03:00
parent c1406adcb2
commit 2bea5f67b9
5 changed files with 15 additions and 3 deletions

View file

@ -31,6 +31,7 @@ const Helper = {
getGitCommit,
ip2hex,
mergeConfig,
getDefaultNick,
password: {
hash: passwordHash,
@ -191,6 +192,14 @@ function passwordCompare(password, expected) {
return bcrypt.compare(password, expected);
}
function getDefaultNick() {
if (!this.config.defaults.nick) {
return "thelounge";
}
return this.config.defaults.nick.replace(/%/g, () => Math.floor(Math.random() * 10));
}
function mergeConfig(oldConfig, newConfig) {
return _.mergeWith(oldConfig, newConfig, (objValue, srcValue, key) => {
// Do not override config variables if the type is incorrect (e.g. object changed into a string)

View file

@ -63,7 +63,7 @@ function Network(attr) {
}
Network.prototype.validate = function(client) {
this.setNick(String(this.nick || "thelounge").replace(" ", "_"));
this.setNick(String(this.nick || Helper.getDefaultNick()).replace(" ", "_"));
if (!this.username) {
this.username = this.nick.replace(/[^a-zA-Z0-9]/g, "");

View file

@ -1,6 +1,7 @@
"use strict";
const Msg = require("../../models/msg");
const Helper = require("../../helper");
module.exports = function(irc, network) {
const client = this;
@ -59,7 +60,7 @@ module.exports = function(irc, network) {
lobby.pushMessage(client, msg, true);
if (irc.connection.registered === false) {
irc.changeNick("thelounge" + Math.floor(Math.random() * 100));
irc.changeNick(Helper.getDefaultNick());
}
client.emit("nick", {

View file

@ -599,7 +599,7 @@ function getClientConfiguration(network) {
config.gitCommit = Helper.getGitCommit();
config.themes = themes.getAll();
config.defaultTheme = Helper.config.theme;
config.defaults.nick = config.defaults.nick.replace(/%/g, () => Math.floor(Math.random() * 10));
config.defaults.nick = Helper.getDefaultNick();
}
return config;

View file

@ -51,6 +51,8 @@ describe("Network", function() {
});
it("validate should set correct defaults", function() {
Helper.config.defaults.nick = "";
const network = new Network({
host: "localhost",
});