-
Notifications
You must be signed in to change notification settings - Fork 0
/
message-commands.ts
102 lines (89 loc) · 3.18 KB
/
message-commands.ts
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
/*
* "message-commands.js"
* ---------------------
* keepin' all the "!xyzfuckyou"s code in one file
*/
/* we need stuff from the 'discord.js' library */
import {MessageEmbed} from "discord.js";
/* show help prompt with registered commands (aka ones I coded in) */
export function helpCmd() {
var msgStr = '**Registered Commands:**\n' +
'```!help\n\tshow this information prompt\n' +
'!hi\n\tI will say "Hello" back\n' +
'!roll <die_sides>[*<multiplier>]\n\troll <die_sides> die <multiplier> times```';
var embed = new MessageEmbed()
.setTitle('!help')
.setColor('#0000ff')
.setDescription(msgStr);
return {embed};
}
/* roll, will split 'x*x' strings */
export function rollRNG(item: string, name: string) {
var logStr = ''; // will hold error or success string
var embed = new MessageEmbed()
.setTitle(name + ': !roll ERROR')
.setColor('#ff0000');
var rollScores = '';
if(item == undefined) {
logStr += 'error: no inputs provided';
embed.setDescription('No roll input provided; use "!roll <die sides>*<multiplier>"');
return {logStr, embed};
}
var dieSides:number = 0;
var rollCount:number = 1;
if(item.includes('*')) {
var inputsGiven = item.split('*');
if(inputsGiven.length > 2) {
logStr += 'error: too many inputs provided';
embed.setDescription('Too many roll inputs provided; use "!roll <die sides>*<multiplier>"');
return {logStr, embed};
}
dieSides = <number><unknown>inputsGiven[0];
rollCount = <number><unknown>inputsGiven[1];
}
else dieSides = <number><unknown>item;
if(isNaN(dieSides)) { // We want a number here
logStr += 'error: die sides is NaN';
embed.setDescription('Die side count provided is not a number; make sure to provide a number');
return {logStr, embed};
}
if(isNaN(rollCount)) { // We also want a number here
logStr += 'error: multiplier is NaN';
embed.setDescription('Roll count provided is not a number; make sure to provide a number');
return {logStr, embed};
}
if(dieSides < 4) { // We want to roll at least a d4
logStr += 'error: die side count < 4';
embed.setDescription('Die side count is too low; use a die side number of at least 4');
return {logStr, embed};
}
if(dieSides > 120) { // We do not want to roll more than a d100
logStr += 'error: die side count > 120';
embed.setDescription('Die side count is too high; use a die side number of at most 120');
return {logStr, embed};
}
if(rollCount < 1) {
logStr += 'error: roll count < 1';
embed.setDescription('Roll count is too low; must roll at least 1 time');
return {logStr, embed};
}
if(rollCount > 819) {
logStr += 'error: roll count > 819';
embed.setDescription('Roll count is too high; use multiplier less than 819');
return {logStr, embed};
}
for(let i = 0; i < rollCount; i++) {
var rollScore = Math.floor(Math.random() * dieSides) + 1;
if(i == (rollCount - 1)) {
rollScores += rollScore;
}
else {
rollScores += rollScore + `, `;
}
}
logStr += 'OK';
embed.setTitle(name + ': !roll RESULT')
.setDescription(rollScores)
.setColor('#00ff00');
return {logStr, embed};
}