aboutsummaryrefslogtreecommitdiff
path: root/src/commands/fun/minesweeper.ts
blob: 2b46e3451864ff652e64e17c376a4d3965a3ce1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
import Minesweeper from 'discord.js-minesweeper';

export default class MinesweeperCommand extends BushCommand {
	public constructor() {
		super('minesweeper', {
			aliases: ['minesweeper'],
			category: 'fun',
			description: {
				content: 'minesweeper command.',
				usage: 'minesweeper <rows> <columns> <mines> [--spaces] [--revealFirstCell]',
				examples: ['minesweeper 10 10 2']
			},
			args: [
				{
					id: 'rows',
					type: 'integer',
					prompt: {
						start: 'How many rows would you like?',
						retry: '{error} Choose a valid number of rows',
						optional: true
					},
					default: 9
				},
				{
					id: 'columns',
					type: 'integer',
					prompt: {
						start: 'How many columns would you like?',
						retry: '{error} Choose a valid number of columns',
						optional: true
					},
					default: 9
				},
				{
					id: 'mines',
					type: 'integer',
					prompt: {
						start: 'How many mines would you like?',
						retry: '{error} Choose a valid number of mines',
						optional: true
					},
					default: 10
				},
				{
					id: 'spaces',
					match: 'flag',
					flag: '--spaces'
				},
				{
					id: 'reveal_first_cell',
					match: 'flag',
					flag: '--revealFirstCell'
				}
			],
			slash: true,
			slashOptions: [
				{
					name: 'rows',
					description: 'How many rows would you like?',
					type: 'INTEGER',
					required: false
				},
				{
					name: 'columns',
					description: 'How many rows would you like?',
					type: 'INTEGER',
					required: false
				},
				{
					name: 'mines',
					description: 'How many rows would you like?',
					type: 'INTEGER',
					required: false
				},
				{
					name: 'spaces',
					description: 'Would you like there to be spaces?',
					type: 'BOOLEAN',
					required: false
				},
				{
					name: 'reveal_first_cell',
					description: 'Would you like to automatically reveal the first cell?',
					type: 'BOOLEAN',
					required: false
				}
			],
			clientPermissions: ['SEND_MESSAGES'],
			userPermissions: ['SEND_MESSAGES']
		});
	}

	public async exec(
		message: BushMessage | BushSlashMessage,
		{
			rows,
			columns,
			mines,
			spaces,
			reveal_first_cell
		}: {
			rows: number;
			columns: number;
			mines: number;
			spaces: boolean;
			reveal_first_cell: boolean;
		}
	): Promise<unknown> {
		const minesweeper = new Minesweeper({
			rows: rows ?? 9,
			columns: columns ?? 9,
			mines: mines ?? 10,
			emote: 'boom',
			revealFirstCell: reveal_first_cell ?? false,
			zeroFirstCell: true,
			spaces: spaces ?? false,
			returnType: 'emoji'
		});
		const matrix = minesweeper.start();
		return await message.util.reply(matrix.toString());
	}
}