more bingo commands

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

@ -33,6 +33,19 @@ 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) {
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(` let response = await postGraphqlQuery(`
mutation($username:String!) { mutation($username:String!) {
bingo { bingo {
@ -49,10 +62,6 @@ async function submitUsername() {
console.error(response); console.error(response);
return false; return false;
} }
} else {
showError('You need to provide a username (minimum 2 characters)!');
return false;
}
} }
/** /**
@ -158,15 +167,19 @@ 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);
if (command && command.length >= 2) {
switch(command[1]) {
case '/help': case '/help':
reply(` reply(`
<b>Commands: </b><br> <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;
@ -182,6 +195,14 @@ async function executeCommand(message) {
case '/abortround': case '/abortround':
reply(await setRoundFinished()); reply(await setRoundFinished());
break; break;
case '/username':
if (command[2]) {
await setUsername(command[2]);
reply(`Your username is <b>${command[2]}</b> now.`)
} else {
reply('You need to provide a username');
}
break;
default: default:
reply('Unknown command'); reply('Unknown command');
break; break;
@ -189,6 +210,7 @@ async function executeCommand(message) {
let chatContent = document.querySelector('#chat-content'); let chatContent = document.querySelector('#chat-content');
chatContent.scrollTop = chatContent.scrollHeight; chatContent.scrollTop = chatContent.scrollHeight;
} }
}
/** /**
* Sends a message to the chat * Sends a message to the chat

Loading…
Cancel
Save