Skip to content

Commit ebf1798

Browse files
committed
More updates
1 parent 8d85a15 commit ebf1798

2 files changed

Lines changed: 105 additions & 45 deletions

File tree

server-src/commands.js

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class CommandHandler {
2+
static HIDE_MESSAGE = "HIDE_MESSAGE";
23
constructor(wss) {
34
if (!wss) {
45
return;
@@ -190,8 +191,9 @@ class CommandHandler {
190191
"broadcast",
191192
function (args, userInfo, senderClient) {
192193
var foundClients = searchUsersByKey(args[0], senderClient);
193-
var message = args.slice(1, args.length).join(" ");
194+
var message = args.join(" ");
194195
sendFeedbackGlobalWithName(message, "[Notice]");
196+
return CommandHandler.HIDE_MESSAGE;
195197
},
196198
"<Message>[br]Broadcasts a message with the [bold][Notice][/bold] name",
197199
true
@@ -383,6 +385,7 @@ class CommandHandler {
383385
foundClients.forEach((otherClient) => {
384386
sendClientCommand(otherClient, "slowrotate");
385387
});
388+
return CommandHandler.HIDE_MESSAGE;
386389
},
387390
"<Username>[br]Makes the specified users screen veeeeeeeeeery slowly start rotating to the left. VEEEEEEEEEEEEERY slow so that eventually they’ll start to realize their screen is a bit off",
388391
true
@@ -405,14 +408,15 @@ class CommandHandler {
405408
var message = args.slice(1, args.length).join(" ");
406409
if (message.trim().length < 1) {
407410
sendFeedbackLocal(
408-
otherClient,
411+
senderClient,
409412
"Message needs to be at least one character."
410413
);
411-
return;
414+
return CommandHandler.HIDE_MESSAGE;
412415
}
413416
foundClients.forEach((otherClient) => {
414417
sendClientCommand(otherClient, "importantMessage", message);
415418
});
419+
return CommandHandler.HIDE_MESSAGE;
416420
},
417421
"<Username> <Message>[br]Makes the screen of the target empty (besides the background color) except for a small black box, and if you click it - it slowly fades out and reveals a message, then after a second it returns the screen back to normal like nothing happened.",
418422
true
@@ -425,7 +429,55 @@ class CommandHandler {
425429
sendClientCommand(otherClient, "cheeseStorm");
426430
});
427431
},
428-
'<Username>[br]Many cheese images will show up on the users screen and each stay there for a few seconds. When the user clicks them, they go away and show "+1 cheese".'
432+
'<Username>[br]Many cheese images will show up on the users screen and each stay there for a few seconds. When the user clicks them, they go away and show "+1 cheese".',
433+
true
434+
);
435+
addCommand(
436+
"quote",
437+
function (args, userInfo, senderClient) {
438+
var foundClients = searchUsersByKey(args[0], senderClient);
439+
if (foundClients.length == 0) {
440+
sendFeedbackLocal(senderClient, "No user was found");
441+
return CommandHandler.HIDE_MESSAGE;
442+
}
443+
if (foundClients.length !== 1) {
444+
sendFeedbackLocal(
445+
senderClient,
446+
"Too many users are selected, only one user needs to be chosen."
447+
);
448+
return CommandHandler.HIDE_MESSAGE;
449+
}
450+
var foundClient = foundClients[0];
451+
var message = args.slice(1, args.length).join(" ");
452+
var currentYear = new Date().getFullYear();
453+
if (message.length > 0) {
454+
sendFeedbackGlobalWithName(
455+
`“${message}” -${userInfo.username}, ${currentYear}`,
456+
"[Notice]"
457+
);
458+
} else {
459+
var lastMessage = null;
460+
var info = getUserInfo(foundClient);
461+
for (var messageData of wss._rrRoomMessages) {
462+
if (messageData.username == info.username) {
463+
lastMessage = messageData.message;
464+
}
465+
}
466+
if (!lastMessage) {
467+
sendFeedbackLocal(senderClient, "Couldn't find message");
468+
return CommandHandler.HIDE_MESSAGE;
469+
}
470+
sendFeedbackGlobalWithName(
471+
`“${lastMessage}” -${getUserInfo(foundClient).username}, ${currentYear}`,
472+
"[Notice]"
473+
);
474+
}
475+
return CommandHandler.HIDE_MESSAGE;
476+
},
477+
"<Username> <Message (Optional)[br]Only doing the quote and username will have the “[Notice]” say “quote goes here” -<username>, " +
478+
new Date().getFullYear() +
479+
"” and the quote is the most recent message that the specified user sent. However if you write your own quote, it’ll just say the same thing but with the quote being the thing you said.",
480+
false
429481
);
430482

431483
////////////////////////////////////////////////////
@@ -461,16 +513,17 @@ class CommandHandler {
461513
return false;
462514
}
463515

464-
async doCommand(args, client) {
516+
doCommand(args, client) {
465517
var commandName = args[0];
466518

467519
if (this.commandExists(commandName)) {
468520
try {
469-
await this.commands[commandName](
521+
var output = this.commands[commandName](
470522
args.slice(1),
471523
this.getUserInfo(client),
472524
client
473525
);
526+
return output;
474527
} catch (e) {
475528
console.log(
476529
`[Command warning]: Command ${commandName} failed with error ${e}`
@@ -585,7 +638,7 @@ class CommandHandler {
585638
return; //No message, just return.
586639
}
587640

588-
this.doCommand(splitMessage, client);
641+
return this.doCommand(splitMessage, client);
589642
}
590643
}
591644

server-src/server.js

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,49 +1984,56 @@ async function startRoomWSS(roomid) {
19841984
}
19851985
}
19861986
if (json.type == "postMessage") {
1987-
if (typeof json.message == "string") {
1988-
if (json.message.length > cons.MAX_MESSAGE_SIZE) {
1989-
ws.send(
1990-
JSON.stringify({
1991-
type: "newMessage",
1992-
message:
1993-
"The message you tried to post is too long.[br]The message was not posted.",
1994-
isServer: true,
1995-
displayName: "[Notice]",
1996-
})
1997-
);
1998-
return;
1999-
}
2000-
wss.clients.forEach((cli) => {
2001-
if (!cli._rrIsReady) {
1987+
var commandResult = null;
1988+
if (hasPermission("commands", ws)) {
1989+
commandResult = wss._rrCommandHandler.handleMessage(
1990+
ws,
1991+
json.message
1992+
);
1993+
}
1994+
if (commandResult !== commandHandler.HIDE_MESSAGE) {
1995+
if (typeof json.message == "string") {
1996+
if (json.message.length > cons.MAX_MESSAGE_SIZE) {
1997+
ws.send(
1998+
JSON.stringify({
1999+
type: "newMessage",
2000+
message:
2001+
"The message you tried to post is too long.[br]The message was not posted.",
2002+
isServer: true,
2003+
displayName: "[Notice]",
2004+
})
2005+
);
20022006
return;
20032007
}
2004-
cli.send(
2005-
JSON.stringify({
2006-
type: "newMessage",
2007-
message: json.message,
2008-
username: ws._rrUsername,
2008+
wss.clients.forEach((cli) => {
2009+
if (!cli._rrIsReady) {
2010+
return;
2011+
}
2012+
cli.send(
2013+
JSON.stringify({
2014+
type: "newMessage",
2015+
message: json.message,
2016+
username: ws._rrUsername,
2017+
displayName: displayName,
2018+
color: ws._rrUserColor,
2019+
font: ws._rrUserFont,
2020+
})
2021+
);
2022+
});
2023+
2024+
if (!json.message.trim().startsWith(";")) {
2025+
//Filter out command messages in history.
2026+
messageChatNumber += 1;
2027+
wss._rrRoomMessages.push({
20092028
displayName: displayName,
2029+
username: ws._rrUsername,
2030+
message: json.message,
20102031
color: ws._rrUserColor,
20112032
font: ws._rrUserFont,
2012-
})
2013-
);
2014-
});
2015-
if (hasPermission("commands", ws)) {
2016-
wss._rrCommandHandler.handleMessage(ws, json.message);
2017-
}
2018-
2019-
if (!json.message.trim().startsWith(";")) {
2020-
//Filter out command messages in history.
2021-
messageChatNumber += 1;
2022-
wss._rrRoomMessages.push({
2023-
displayName: displayName,
2024-
username: ws._rrUsername,
2025-
message: json.message,
2026-
color: ws._rrUserColor,
2027-
font: ws._rrUserFont,
2028-
});
2029-
wss._rrRoomMessages = wss._rrRoomMessages.slice(-50);
2033+
});
2034+
ws._rrLastMessagePosted = json.message;
2035+
wss._rrRoomMessages = wss._rrRoomMessages.slice(-50);
2036+
}
20302037
}
20312038
}
20322039
}

0 commit comments

Comments
 (0)