Use default nick set in config for fallback
This commit is contained in:
parent
c1406adcb2
commit
2bea5f67b9
@ -31,6 +31,7 @@ const Helper = {
|
|||||||
getGitCommit,
|
getGitCommit,
|
||||||
ip2hex,
|
ip2hex,
|
||||||
mergeConfig,
|
mergeConfig,
|
||||||
|
getDefaultNick,
|
||||||
|
|
||||||
password: {
|
password: {
|
||||||
hash: passwordHash,
|
hash: passwordHash,
|
||||||
@ -191,6 +192,14 @@ function passwordCompare(password, expected) {
|
|||||||
return bcrypt.compare(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) {
|
function mergeConfig(oldConfig, newConfig) {
|
||||||
return _.mergeWith(oldConfig, newConfig, (objValue, srcValue, key) => {
|
return _.mergeWith(oldConfig, newConfig, (objValue, srcValue, key) => {
|
||||||
// Do not override config variables if the type is incorrect (e.g. object changed into a string)
|
// Do not override config variables if the type is incorrect (e.g. object changed into a string)
|
||||||
|
@ -63,7 +63,7 @@ function Network(attr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Network.prototype.validate = function(client) {
|
Network.prototype.validate = function(client) {
|
||||||
this.setNick(String(this.nick || "thelounge").replace(" ", "_"));
|
this.setNick(String(this.nick || Helper.getDefaultNick()).replace(" ", "_"));
|
||||||
|
|
||||||
if (!this.username) {
|
if (!this.username) {
|
||||||
this.username = this.nick.replace(/[^a-zA-Z0-9]/g, "");
|
this.username = this.nick.replace(/[^a-zA-Z0-9]/g, "");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const Msg = require("../../models/msg");
|
const Msg = require("../../models/msg");
|
||||||
|
const Helper = require("../../helper");
|
||||||
|
|
||||||
module.exports = function(irc, network) {
|
module.exports = function(irc, network) {
|
||||||
const client = this;
|
const client = this;
|
||||||
@ -59,7 +60,7 @@ module.exports = function(irc, network) {
|
|||||||
lobby.pushMessage(client, msg, true);
|
lobby.pushMessage(client, msg, true);
|
||||||
|
|
||||||
if (irc.connection.registered === false) {
|
if (irc.connection.registered === false) {
|
||||||
irc.changeNick("thelounge" + Math.floor(Math.random() * 100));
|
irc.changeNick(Helper.getDefaultNick());
|
||||||
}
|
}
|
||||||
|
|
||||||
client.emit("nick", {
|
client.emit("nick", {
|
||||||
|
@ -599,7 +599,7 @@ function getClientConfiguration(network) {
|
|||||||
config.gitCommit = Helper.getGitCommit();
|
config.gitCommit = Helper.getGitCommit();
|
||||||
config.themes = themes.getAll();
|
config.themes = themes.getAll();
|
||||||
config.defaultTheme = Helper.config.theme;
|
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;
|
return config;
|
||||||
|
@ -51,6 +51,8 @@ describe("Network", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("validate should set correct defaults", function() {
|
it("validate should set correct defaults", function() {
|
||||||
|
Helper.config.defaults.nick = "";
|
||||||
|
|
||||||
const network = new Network({
|
const network = new Network({
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user