Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/sockets/commands/user/gm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Command } from '../types';
import { SocketUser } from '../../types';
import { guessmerlin } from './guessmerlin';

export const gm: Command = {
command: 'gm',
help: '/gm <playername>: Shortcut for /guessmerlin',
run: async (args: string[], socket: SocketUser) => {
return guessmerlin.run(args, socket);
},
};
35 changes: 35 additions & 0 deletions src/sockets/commands/user/guessmerlin.ts
Original file line number Diff line number Diff line change
@@ -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 <playername>: 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);
},
};
4 changes: 4 additions & 0 deletions src/sockets/commands/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { unmute } from './unmute';
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,
Expand All @@ -33,4 +35,6 @@ export const userCommandsImported: Commands = {
[mute.command]: mute,
[unmute.command]: unmute,
[muted.command]: muted,
[guessmerlin.command]: guessmerlin,
[gm.command]: gm,
};
30 changes: 0 additions & 30 deletions src/sockets/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,36 +496,6 @@ export const userCommandsOLD = {
});
},
},

guessmerlin: {
command: 'guessmerlin',
help: '/guessmerlin <playername>: 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 <playername>: Shortcut for /guessmerlin',
run(args: string[], senderSocket) {
return userCommands.guessmerlin.run(args, senderSocket);
},
},
};

export const userCommands = { ...userCommandsImported, ...userCommandsOLD };
Expand Down