From 2aaded33fc9bf27ad0eafe524c3133b4debbdc4f Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 15 Aug 2024 12:09:21 +1000 Subject: [PATCH 1/2] Refactored guessMerlin command --- src/sockets/commands/user/guessmerlin.ts | 35 ++++++++++++++++++++++++ src/sockets/commands/user/index.ts | 2 ++ src/sockets/sockets.ts | 22 --------------- 3 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 src/sockets/commands/user/guessmerlin.ts diff --git a/src/sockets/commands/user/guessmerlin.ts b/src/sockets/commands/user/guessmerlin.ts new file mode 100644 index 000000000..e1c5eee24 --- /dev/null +++ b/src/sockets/commands/user/guessmerlin.ts @@ -0,0 +1,35 @@ +import { Command } from '../types'; +import { SocketUser } from '../../types'; +import { rooms, sendReplyToCommand } from '../../sockets'; +import { Phase } from '../../../gameplay/phases/types'; + +export const guessmerlin: Command = { + command: 'guessmerlin', + help: '/guessmerlin : Solely for fun, submit your guess of who you think is Merlin.', + run: async (args: string[], socket: SocketUser) => { + if (args.length != 2) { + sendReplyToCommand(socket, 'Please specify a single username.'); + return; + } + + // Check the guesser is at a table + if ( + !socket.request.user.inRoomId || + !rooms[socket.request.user.inRoomId].gameStarted || + rooms[socket.request.user.inRoomId].phase === Phase.Finished + ) { + sendReplyToCommand( + socket, + 'You must be at a running table to guess Merlin.', + ); + return; + } + + const msgToClient = rooms[socket.request.user.inRoomId].submitMerlinGuess( + socket.request.user.username, + args[1], + ); + + sendReplyToCommand(socket, msgToClient); + }, +}; diff --git a/src/sockets/commands/user/index.ts b/src/sockets/commands/user/index.ts index 0e815388a..a6f9291d2 100644 --- a/src/sockets/commands/user/index.ts +++ b/src/sockets/commands/user/index.ts @@ -15,6 +15,7 @@ import { unmute } from './unmute'; import { mods } from './mods'; import { pmmod } from './pmmod'; import { r } from './r'; +import { guessmerlin } from './guessmerlin'; export const userCommandsImported: Commands = { [help.command]: help, @@ -33,4 +34,5 @@ export const userCommandsImported: Commands = { [mute.command]: mute, [unmute.command]: unmute, [muted.command]: muted, + [guessmerlin.command]: guessmerlin, }; diff --git a/src/sockets/sockets.ts b/src/sockets/sockets.ts index a90074661..a211520ea 100644 --- a/src/sockets/sockets.ts +++ b/src/sockets/sockets.ts @@ -497,28 +497,6 @@ export const userCommandsOLD = { }, }, - guessmerlin: { - command: 'guessmerlin', - help: '/guessmerlin : Solely for fun, submit your guess of who you think is Merlin.', - run(args: string[], senderSocket) { - // Check the guesser is at a table - let messageToClient; - if ( - senderSocket.request.user.inRoomId === undefined || - rooms[senderSocket.request.user.inRoomId].gameStarted !== true || - rooms[senderSocket.request.user.inRoomId].phase === Phase.Finished - ) { - messageToClient = 'You must be at a running table to guess Merlin.'; - } else { - messageToClient = rooms[ - senderSocket.request.user.inRoomId - ].submitMerlinGuess(senderSocket.request.user.username, args[1]); - } - - return { message: messageToClient, classStr: 'server-text noselect' }; - }, - }, - gm: { command: 'gm', help: '/gm : Shortcut for /guessmerlin', From fd0174c72d8d760d0683bc1608e9ec4af9b33fe6 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 15 Aug 2024 12:13:44 +1000 Subject: [PATCH 2/2] Refactord gm command --- src/sockets/commands/user/gm.ts | 11 +++++++++++ src/sockets/commands/user/index.ts | 2 ++ src/sockets/sockets.ts | 8 -------- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 src/sockets/commands/user/gm.ts diff --git a/src/sockets/commands/user/gm.ts b/src/sockets/commands/user/gm.ts new file mode 100644 index 000000000..6c0f5b500 --- /dev/null +++ b/src/sockets/commands/user/gm.ts @@ -0,0 +1,11 @@ +import { Command } from '../types'; +import { SocketUser } from '../../types'; +import { guessmerlin } from './guessmerlin'; + +export const gm: Command = { + command: 'gm', + help: '/gm : Shortcut for /guessmerlin', + run: async (args: string[], socket: SocketUser) => { + return guessmerlin.run(args, socket); + }, +}; diff --git a/src/sockets/commands/user/index.ts b/src/sockets/commands/user/index.ts index a6f9291d2..4f72386ea 100644 --- a/src/sockets/commands/user/index.ts +++ b/src/sockets/commands/user/index.ts @@ -16,6 +16,7 @@ import { mods } from './mods'; import { pmmod } from './pmmod'; import { r } from './r'; import { guessmerlin } from './guessmerlin'; +import { gm } from './gm'; export const userCommandsImported: Commands = { [help.command]: help, @@ -35,4 +36,5 @@ export const userCommandsImported: Commands = { [unmute.command]: unmute, [muted.command]: muted, [guessmerlin.command]: guessmerlin, + [gm.command]: gm, }; diff --git a/src/sockets/sockets.ts b/src/sockets/sockets.ts index a211520ea..6fccc2739 100644 --- a/src/sockets/sockets.ts +++ b/src/sockets/sockets.ts @@ -496,14 +496,6 @@ export const userCommandsOLD = { }); }, }, - - gm: { - command: 'gm', - help: '/gm : Shortcut for /guessmerlin', - run(args: string[], senderSocket) { - return userCommands.guessmerlin.run(args, senderSocket); - }, - }, }; export const userCommands = { ...userCommandsImported, ...userCommandsOLD };