Commit 667412e6 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement /set command.

parent cca19444
......@@ -109,6 +109,9 @@ to all users:
- `/me text`: sends a chat message starting with the sender's username;
- `/leave`: equivalent to clicking the *Disconnect* button.
- `/set var val`: sets the value of a configuration variable without any
error checking. Without parameters, displays the current configuration.
- `/unset var`: removes a configuration variable.
The following commands are only available to users with operator
privileges:
......
......@@ -297,6 +297,11 @@ textarea.form-reply {
background: #ececec;
}
.message-system {
font-size: 10px;
background: #ececec;
}
.message-row:after, .message-row:before {
display: table;
content: " ";
......
......@@ -126,6 +126,27 @@ function updateSettings(settings) {
storeSettings(s);
}
/**
* @param {string} key
* @param {any} value
*/
function updateSetting(key, value) {
let s = {};
s[key] = value;
updateSettings(s);
}
/**
* @param {string} key
*/
function delSetting(key) {
let s = getSettings();
if(!(key in s))
return;
delete(s[key]);
storeSettings(s)
}
/**
* @param {string} id
*/
......@@ -1209,7 +1230,9 @@ function addToChatbox(peerId, nick, kind, message){
let container = document.createElement('div');
container.classList.add('message');
row.appendChild(container);
if (userpass.username === nick) {
if(!peerId)
container.classList.add('message-system');
else if(userpass.username === nick) {
container.classList.add('message-sender');
}
if(kind !== 'me') {
......@@ -1333,6 +1356,33 @@ function handleInput() {
}
serverConnection.groupAction('clearchat');
return;
case '/set':
if(!rest) {
let settings = getSettings();
let s = "";
for(let key in settings)
s = s + `${key}: ${JSON.stringify(settings[key])}\n`
addToChatbox(null, null, null, s);
return;
}
let parsed = parseCommand(rest);
let value;
if(parsed[1]) {
try {
value = JSON.parse(parsed[1])
} catch(e) {
displayError(e);
return;
}
} else {
value = true;
}
updateSetting(parsed[0], value);
reflectSettings();
return;
case '/unset':
delSetting(rest.trim());
return;
case '/lock':
case '/unlock':
if(!serverConnection.permissions.op) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment