1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 16:45:58 +01:00

Implement /set command.

This commit is contained in:
Juliusz Chroboczek 2020-09-23 21:01:29 +02:00
parent cca19444d6
commit 667412e6ae
3 changed files with 60 additions and 2 deletions

3
README
View file

@ -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:

View file

@ -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: " ";

View file

@ -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) {