-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
73 lines (65 loc) · 1.82 KB
/
game.js
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
import { capitalize } from './utils.js';
export function getResult(p1, p2) {
let gameResult;
if (RPSChoices[p1.objectName] && RPSChoices[p1.objectName][p2.objectName]) {
// o1 wins
gameResult = {
win: p1,
lose: p2,
verb: RPSChoices[p1.objectName][p2.objectName],
};
} else if (
RPSChoices[p2.objectName] &&
RPSChoices[p2.objectName][p1.objectName]
) {
// o2 wins
gameResult = {
win: p2,
lose: p1,
verb: RPSChoices[p2.objectName][p1.objectName],
};
} else {
// tie -- win/lose don't
gameResult = { win: p1, lose: p2, verb: 'tie' };
}
return formatResult(gameResult);
}
function formatResult(result) {
const { win, lose, verb } = result;
return verb === 'tie'
? `<@${win.id}> and <@${lose.id}> draw with **${win.objectName}**`
: `<@${win.id}>'s **${win.objectName}** ${verb} <@${lose.id}>'s **${lose.objectName}**`;
}
// this is just to figure out winner + verb
const RPSChoices = {
SOL: {
description: 'sedimentary, igneous, or perhaps even metamorphic',
virus: 'outwaits',
computer: 'smashes',
scissors: 'crushes',
},
USDC: {
description: 'yeehaw~',
scissors: 'puts away',
wumpus: 'lassos',
rock: 'steel-toe kicks',
},
};
export function getRPSChoices() {
return Object.keys(RPSChoices);
}
// Function to fetch shuffled options for select menu
export function getShuffledOptions() {
const allChoices = getRPSChoices();
const options = [];
for (let c of allChoices) {
// Formatted for select menus
// https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
options.push({
label: capitalize(c),
value: c.toLowerCase(),
description: RPSChoices[c]['description'],
});
}
return options.sort(() => Math.random() - 0.5);
}