more bingo commands

- added /username bingo command
pull/15/head
Julius 6 years ago
parent d0085a2bfd
commit 44db9f844c

@ -33,7 +33,20 @@ async function submitUsername() {
let username = unameInput.value.replace(/^\s+|\s+$/g, ''); let username = unameInput.value.replace(/^\s+|\s+$/g, '');
if (username.length > 1) { if (username.length > 1) {
let response = await postGraphqlQuery(` await setUsername(username);
} else {
showError('You need to provide a username (minimum 2 characters)!');
return false;
}
}
/**
* Sets the username for a user
* @param username {String} - the username
* @returns {Promise<boolean>}
*/
async function setUsername(username) {
let response = await postGraphqlQuery(`
mutation($username:String!) { mutation($username:String!) {
bingo { bingo {
setUsername(username: $username) { setUsername(username: $username) {
@ -42,15 +55,11 @@ async function submitUsername() {
} }
} }
}`, {username: username}); }`, {username: username});
if (response.status === 200) { if (response.status === 200) {
return true; return true;
} else {
showError(`Failed to submit username. HTTP Error: ${response.status}`);
console.error(response);
return false;
}
} else { } else {
showError('You need to provide a username (minimum 2 characters)!'); showError(`Failed to submit username. HTTP Error: ${response.status}`);
console.error(response);
return false; return false;
} }
} }
@ -158,36 +167,49 @@ async function executeCommand(message) {
addChatMessage({content: content, htmlContent: content, type: 'INFO'}); addChatMessage({content: content, htmlContent: content, type: 'INFO'});
} }
let jsStyle = document.querySelector('#js-style'); let jsStyle = document.querySelector('#js-style');
message = message.replace(/\s/g, ''); message = message.replace(/\s+$/g, '');
switch(message) { let command = /(\/\w+) ?(.*)?/g.exec(message);
case '/help': if (command && command.length >= 2) {
reply(` switch(command[1]) {
<b>Commands: </b><br> case '/help':
reply(`
<br><b>Commands: </b><br>
/help - shows this help <br> /help - shows this help <br>
/hideinfo - hides all info messages <br> /hideinfo - hides all info messages <br>
/showinfo - shows all info messages <br> /showinfo - shows all info messages <br>
/ping - shows the current ping <br> /ping - shows the current ping <br>
/username {Username} - sets the username <br><br>
Admin commands: <br>
/abortround - aborts the current round <br> /abortround - aborts the current round <br>
`); `);
break; break;
case '/hideinfo': case '/hideinfo':
jsStyle.innerHTML = '.chatMessage[msg-type="INFO"] {display: none}'; jsStyle.innerHTML = '.chatMessage[msg-type="INFO"] {display: none}';
break; break;
case '/showinfo': case '/showinfo':
jsStyle.innerHTML = '.chatMessage[msg-type="INFO"] {}'; jsStyle.innerHTML = '.chatMessage[msg-type="INFO"] {}';
break; break;
case '/ping': case '/ping':
reply(`Ping: ${await ping()} ms`); reply(`Ping: ${await ping()} ms`);
break; break;
case '/abortround': case '/abortround':
reply(await setRoundFinished()); reply(await setRoundFinished());
break; break;
default: case '/username':
reply('Unknown command'); if (command[2]) {
break; await setUsername(command[2]);
reply(`Your username is <b>${command[2]}</b> now.`)
} else {
reply('You need to provide a username');
}
break;
default:
reply('Unknown command');
break;
}
let chatContent = document.querySelector('#chat-content');
chatContent.scrollTop = chatContent.scrollHeight;
} }
let chatContent = document.querySelector('#chat-content');
chatContent.scrollTop = chatContent.scrollHeight;
} }
/** /**

Loading…
Cancel
Save