-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
142 lines (112 loc) · 4.61 KB
/
app.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var Discord = require('discord.js');
var Consumers = require('./modules/consumers.js');
var Validation = require('./modules/validation.js');
var WowApiService = require("./modules/wowApiService.js");
var config = require("./config.json");
client = new Discord.Client();
client.login(config.discordToken);
client.on("ready", function(){
console.log("Gladitron Bot now fully operational.")
client.user.setGame("World of Warcraft");
})
client.on('message', message => {
//Ignore the message if not properly prefixed.
if (message.content.indexOf(config.prefix) !== 0) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
var consumerSettings = Consumers.getConsumerSettings(message.channel.guild.id);
if(command === "setrealm")
{
if(args < 1)
{
message.channel.send("Please specify a realm name.\n\nUsage: ```" + config.prefix + "setrealm {realmName}```");
return;
}
newRealm = args.join("-").toLowerCase();
Validation.validateRealm(newRealm, consumerSettings.locale, function(isValid) {
if(!isValid)
{
message.channel.send("You didn't enter a valid realm name. Try again.\n\nUsage: ```" + config.prefix + "setrealm {realmName}```");
return;
}
consumerSettings.realm = newRealm;
Consumers.updateConsumerSettings(consumerSettings);
message.channel.send("Realm has been updated to: " + consumerSettings.realm);
});
}
else if(command === "setguild")
{
if(args.length < 1)
{
message.channel.send("Please specify a guild name.\n\nUsage: ```" + config.prefix + "setguild {guildName}```");
return;
}
newGuild = args.join(" ");
Validation.validateGuild(newGuild, consumerSettings.realm, consumerSettings.locale, function(isValid) {
if(!isValid)
{
message.channel.send("That guild doesn't exist. Try again.\n\nUsage: ```" + config.prefix + "setguild {setguild}```");
return;
}
consumerSettings.guild = newGuild;
Consumers.updateConsumerSettings(consumerSettings);
message.channel.send("Guild has been updated to: " + consumerSettings.guild);
});
}
else if(command === "setlocale")
{
if(args.length < 1)
{
message.channel.send("Please specify a locale.\n\nUsage: ```" + config.prefix + "setlocale {en_US|en_EU|en_KR|en_TW}```");
return;
}
newLocale = args[0];
Validation.validateLocale(newLocale, function(isValid) {
if(!isValid)
{
message.channel.send("That's not a valid locale.\n\nUsage: ```" + config.prefix + "setlocale {en_US|en_EU|en_KR|en_TW}```");
return;
}
consumerSettings.locale = newLocale;
Consumers.updateConsumerSettings(consumerSettings);
message.channel.send("Locale has been updated to: " + consumerSettings.locale);
});
}
else if(command === "ladder")
{
if(args.length < 1)
{
message.channel.send("Please specify a bracket.\n\nUsage: ```" + config.prefix + "ladder {2v2|3v3|rbg} {count (optional, default 10)}```");
}
var bracket = args[0];
var count = 10;
if(args.length >= 2 && !isNaN(args[1]))
{
count = parseInt(args[1]);
}
if(!Validation.validateBracket(bracket))
{
message.channel.send("That isn't a valid bracket. Try again.\n\nUsage: ```" + config.prefix + "ladder {2v2|3v3|rbg} {count (optional, default 10)}```");
return;
}
WowApiService.getLadder(consumerSettings, bracket, count, function(data) {
var msg = "```\"" + consumerSettings.guild + "\" Ladder for " + bracket.toUpperCase() + ":\n";
for(var i = 0; i < data.length; i++)
{
var nameSpacer = "";
for(var j = 0; j < 5 - (i + 1).toString().length; j++)
{
nameSpacer += " ";
}
var ratingSpacer = " ";
for(var j = 0; j < 20 - data[i].name.length; j++)
{
ratingSpacer += " ";
}
msg += (i + 1) + "." + nameSpacer + data[i].name + ratingSpacer + data[i].rating + "\n";
}
msg += "```";
message.channel.send(msg);
});
}
});