diff options
Diffstat (limited to 'client/commands.js')
-rw-r--r-- | client/commands.js | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/client/commands.js b/client/commands.js index 0bd3c65..5f27c29 100644 --- a/client/commands.js +++ b/client/commands.js @@ -1,6 +1,6 @@ commands = { "verify": (_1, _2) => { - localSystemMessage("Use this fingerprint to verify the server's identity: " + require('crypto').createHash("sha256").update(window.serverVerifyKey).digest("base64")); + localSystemMessage(l("commands/verify") + "<br><pre style='margin: 0 !important;'>" + require('crypto').createHash("sha256").update(window.serverVerifyKey).digest("base64").match(/.{1,35}/g).join("\n") + "</pre>", true); }, "nick": (argument, _) => { if (argument.trim() === "") argument = require('os').userInfo().username; @@ -8,7 +8,7 @@ commands = { let oldUserName = userName; userName = argument; localStorage.setItem("username", userName); - systemMessage(`${oldUserName} changed their name to "${argument}"`, `Your name is now "${argument}"`); + systemMessage(sl("commands/nick/other", [["%2", oldUserName], ["%1", argument]]), l("commands/nick/self").replace("%1", argument)); }, "background": (argument, _) => { if (argument.trim() === "") argument = null; @@ -17,15 +17,15 @@ commands = { try { require('fs').readFileSync(argument); } catch (e) { - localSystemMessage("Unable to change the background image: " + e.message); + localSystemMessage(l("commands/background/error").replace("%1", e.message)); return; } localStorage.setItem("background", argument); - localSystemMessage("Successfully changed the background image to " + require('path').resolve(argument)); + localSystemMessage(l("commands/background/changed").replace("%1", require('path').resolve(argument))); } else { localStorage.removeItem("background"); - localSystemMessage("Successfully removed the background image"); + localSystemMessage(l("commands/background/removed")); } updateBackground(); @@ -36,24 +36,24 @@ commands = { if (parts.length === 0) { colors = [ "ffffff", "ffffff" ]; localStorage.setItem("colors", JSON.stringify(colors)); - systemMessage(`${userName} changed their profile colors to the default ones`, `Your profile colors are now the default ones`); + systemMessage(sl("commands/color/reset/other", [["%1", userName]]), l("commands/color/reset/self")); return; } else if (parts.length === 1) { parts[1] = parts[0]; } if (!parts[0].match(/(^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$)/gm)) { - localSystemMessage("The first color is not a valid hexadecimal color code"); + localSystemMessage(l("commands/color/invalid/first")); return; } if (!parts[1].match(/(^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$)/gm)) { - localSystemMessage("The second color is not a valid hexadecimal color code"); + localSystemMessage(l("commands/color/invalid/second")); return; } colors = [ parts[0], parts[1] ]; - systemMessage(`${userName} changed their profile colors`, `Your profile colors are now #${parts[0]} and #${parts[1]}`); + systemMessage(sl("commands/color/changed/other", [["%1", userName]]), l("commands/color/changed/self").replace("%1", parts[0].trim()).replace("%2", parts[1].trim())); }, "list": (argument, _) => { send({ @@ -69,7 +69,7 @@ commands = { }, "ban": (argument, _) => { if (argument.trim() === "") { - localSystemMessage("Please specify the IP address of a client you want to block"); + localSystemMessage(l("commands/ban")); return; } @@ -81,7 +81,7 @@ commands = { }, "unban": (argument, _) => { if (argument.trim() === "") { - localSystemMessage("Please specify the IP address of a client you want to unblock"); + localSystemMessage(l("commands/unban")); return; } @@ -99,7 +99,7 @@ commands = { }, "op": (argument, _) => { if (argument.trim() === "") { - localSystemMessage("Please specify the IP address of a client you want to make an operator"); + localSystemMessage(l("commands/op")); return; } @@ -111,7 +111,7 @@ commands = { }, "deop": (argument, _) => { if (argument.trim() === "") { - localSystemMessage("Please specify the IP address of a client you want to not make an operator"); + localSystemMessage(l("commands/deop")); return; } @@ -125,7 +125,7 @@ commands = { let parts = argument.split(" "); if (parts.length < 2) { - localSystemMessage("Please specify the IP address of the client the message to send"); + localSystemMessage(l("commands/msg")); return; } @@ -139,7 +139,7 @@ commands = { }, "r": (argument, _) => { if (argument.trim() === "") { - localSystemMessage("Please specify the message to send"); + localSystemMessage(l("commands/r")); return; } @@ -152,30 +152,42 @@ commands = { }, "ping": (_1, _2) => { if (window.connected) { - localSystemMessage("Your ping is: " + window.ping + " ms"); + localSystemMessage(l("commands/ping").replace("%1", window.ping)); } else { - localSystemMessage("You are not currently connected to a server"); + localSystemMessage(l("commands/_server2")); } }, "url": (_1, _2) => { if (window.connected) { - localSystemMessage("The server you are connected to is: " + window.serverURL); + localSystemMessage(l("commands/url") + " " + window.serverURL); } else { - localSystemMessage("You are not currently connected to a server"); + localSystemMessage(l("commands/_server2")); } }, "version": (_1, _2) => { if (window.connected) { - localSystemMessage("Localchat version " + stripHTML(window.version) + "<br>Node.js version " + process.versions.node + "<br>Chrome version " + process.versions.chrome + "<br>Electron version " + process.versions.electron + "<br>Server version " + stripHTML(window.serverVersion), true); + localSystemMessage(l("commands/version/localchat") + " " + stripHTML(window.version) + "<br>" + l("commands/version/node") + " " + process.versions.node + "<br>" + l("commands/version/chrome") + " " + process.versions.chrome + "<br>" + l("commands/version/electron") + " " + process.versions.electron + "<br>" + l("commands/version/server") + " " + stripHTML(window.serverVersion), true); } else { - localSystemMessage("Localchat version " + stripHTML(window.version) + "<br>Node.js version " + process.versions.node + "<br>Chrome version " + process.versions.chrome + "<br>Electron version " + process.versions.electron, true); + localSystemMessage(l("commands/version/localchat") + " " + stripHTML(window.version) + "<br>" + l("commands/version/node") + " " + process.versions.node + "<br>" + l("commands/version/chrome") + " " + process.versions.chrome + "<br>" + l("commands/version/electron") + " " + process.versions.electron, true); + } + }, + "changelog": (_1, _2) => { + localSystemMessage(window.changeLog.trim().replace("%1", window.version).replaceAll("\n", "<br>"), true); + }, + "channel": (_1, _2) => { + if (require('fs').existsSync(window.applicationData + "/LocalchatBetaChannel")) { + require('fs').unlinkSync(window.applicationData + "/LocalchatBetaChannel"); + localSystemMessage(l("commands/channel/stable")); + } else { + require('fs').writeFileSync(window.applicationData + "/LocalchatBetaChannel", ""); + localSystemMessage(l("commands/channel/beta")); } }, "_": (argument, command) => { - localSystemMessage("Sorry, /" + command + " is not a valid slash command, use /help to get a list"); + localSystemMessage(l("commands/_").replace("%1", command)); }, "help": (_1, _2) => { - localSystemMessage("Available commands: " + Object.keys(commands).filter(i => i !== "_").sort((a, b) => a.localeCompare(b)).join(", ")); + localSystemMessage(l("commands/help") + " " + Object.keys(commands).filter(i => i !== "_").sort((a, b) => a.localeCompare(b)).join(", ")); }, "reload": (_1, _2) => { location.reload(); @@ -194,7 +206,7 @@ function runCommand(message) { if (window.connected) { commands[command](argument, command); } else { - localSystemMessage("Please connect to the server before using slash commands"); + localSystemMessage(l("commands/_server")); } } else { commands["_"](argument, command); |