-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWoDDiceBot.js
107 lines (99 loc) · 3.07 KB
/
WoDDiceBot.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
103
104
105
106
107
const DiscordBot = require('extensiblediscordbot'),
Action = require('./DiceRoller').Action;
class WoDDiceBot extends DiscordBot
{
constructor(conf)
{
super(conf);
}
async hoist(client)
{
let settings = await super.hoist(client);
this.attachCommands();
return settings;
}
attachCommands()
{
super.attachCommands();
this.attachCommand('roll', this.simpleRoll);
this.attachCommand('help', this.displayHelpText);
}
displayHelpText(commandParts, message)
{
message.reply([
"`!roll <n> [diff-<d>] [spec]`",
" `!roll 5 would` roll five dice at the standard difficulty of 6",
" `!roll 6 diff-7` would roll six dice but only consider 7s a success",
" `!roll 7 spec` would roll 7 dice and consider tens two successes",
" `!roll 7 diff-7 -- rolling strength + brawl` would treat the text after the double dashes as a comment which is for the sake of posterity"
]);
}
simpleRoll(commandParts, message, comment)
{
let messageParts = message.content.split('--'),
messageText = message.content.toLowerCase(),
poolMatch = messageText.match(/\s(\d+)\s?/),
difficultyMatch = messageText.match(/diff\-(\d+)/),
specialty = messageText.indexOf('spec')>-1,
pool = 5,
difficulty = 6;
if(difficultyMatch)
{
difficulty = parseInt(difficultyMatch[1]);
}
if(poolMatch)
{
pool = parseInt(poolMatch[1]);
}
let action = new Action(pool, difficulty, specialty);
let results = action.getResults();
this.displayResults(message, results, comment);
}
displayResults(message, results, comment)
{
let response = [`You rolled ${results.pool} dice at a difficulty of ${results.difficulty}.`];
if(comment)
{
response.push(`Comment provided: ${comment}`);
}
if(results.specialty)
{
response.push("It was considered a specialty roll.");
}
if(results.botch)
{
response.push('You botched!');
}
else
{
response.push(`You got ${results.successes} successes.`);
}
let diceRolled = [];
for(let dieRoll of results.dice)
{
let die = dieRoll.result;
if(die >= results.difficulty)
{
if(die === 10 && results.specialty)
{
diceRolled.push(`***${die}***`);
}
else
{
diceRolled.push(`**${die}**`);
}
}
else if(die === 1)
{
diceRolled.push(`__${die}__`);
}
else
{
diceRolled.push(die);
}
}
response.push('Dice rolled: ['+diceRolled.join(', ')+']');
message.reply(response);
}
}
module.exports = WoDDiceBot;