-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexalted-roller.js
102 lines (95 loc) · 2.99 KB
/
exalted-roller.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
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
const {
AWSLambdaServer,
CommandOptionType,
SlashCommand,
SlashCreator,
CommandContext,
} = require("slash-create");
const RollModule = require("./roll.js");
const toNumber = require("lodash/toNumber.js");
const roll = RollModule.default;
const parseResults = RollModule.parseResults;
const creator = new SlashCreator({
applicationID: process.env.DISCORD_APP_ID,
publicKey: process.env.DISCORD_PUBLIC_KEY,
token: process.env.DISCORD_BOT_TOKEN,
});
class RollCommand extends SlashCommand {
constructor(creator) {
super(creator, {
name: "d10",
description: "Roll d10 for exalted 3e",
options: [
{
type: CommandOptionType.INTEGER,
name: "dice",
description: "Number of d10 to roll",
required: true,
min_value: 1,
},
{
type: CommandOptionType.INTEGER,
name: "double",
description: "Double X's: dice over this number count as 2 successes",
min_value: 1,
max_value: 11,
},
{
type: CommandOptionType.INTEGER,
name: "autosuccesses",
description: "Autosuccesses to add to roll",
min_value: 1,
},
{
type: CommandOptionType.STRING,
name: "reroll",
description: "Numbers to reroll (comma separated)",
},
{
type: CommandOptionType.INTEGER,
name: "target-number",
description: "Roll target (default 7)",
min_value: 1,
max_value: 10,
},
],
});
}
/** @param {CommandContext} ctx */
async run(ctx) {
const _numDice = ctx.options.dice;
const numDice = toNumber(_numDice);
const results = roll(numDice, {
autosuccesses: ctx.options.autosuccesses,
double: ctx.options.double,
rerollArray: ctx.options.reroll?.split(",").map((n) => toNumber(n)) ?? [],
targetNumber: ctx.options["target-number"],
});
return parseResults(results);
}
}
creator
// The first argument is required, the second argument is the name or "target" of the export.
// It defaults to 'interactions', so it would not be strictly necessary here.
.withServer(new AWSLambdaServer(module.exports, "handler"))
.registerCommands([RollCommand]);
creator.on("debug", (message) => console.log(message));
creator.on("warn", (message) => console.warn(message));
creator.on("error", (error) => console.error(error.message));
creator.on("synced", () => console.info("Commands synced!"));
creator.on("commandRun", (command, _, ctx) =>
console.info(
`${ctx.user.username}#${ctx.user.discriminator} (${ctx.user.id}) ran command ${command.commandName}`
)
);
creator.on("commandRegister", (command) =>
console.info(`Registered command ${command.commandName}`)
);
creator.on("commandError", (command, error) =>
console.error(`Command ${command.commandName}:`, error)
);
if (process.env.SYNC) {
console.log("syncing commands");
creator.syncCommands();
creator.syncCommandsIn("190664048147169280");
}