Skip to content

Commit 80237ed

Browse files
committed
updated
1 parent b54d705 commit 80237ed

File tree

2 files changed

+143
-32
lines changed

2 files changed

+143
-32
lines changed

Diff for: core.js

+94-15
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ class Core {
5050
});
5151
}
5252
}
53-
module.exports = Core;
53+
try {
54+
module.exports = Core;
55+
}
56+
catch (error) {
57+
console.log("[corejs] starting plain vanilla instance, as nodejs exports were not available");
58+
}
5459
class ConnectionHash extends Core {
5560
constructor(core, network, uuid, hash, player) {
5661
super(core.getKey());
@@ -79,6 +84,7 @@ class ConnectionHash extends Core {
7984
requestSession() {
8085
return __awaiter(this, void 0, void 0, function* () {
8186
var key = this.core.getKey();
87+
var core = this.core;
8288
var hash = this.hash;
8389
return new Promise(function (resolve, reject) {
8490
try {
@@ -89,7 +95,10 @@ class ConnectionHash extends Core {
8995
throw new Error(jsonresponse.error + ". " + jsonresponse.msg);
9096
}
9197
else {
92-
resolve(new SessionRequest(new Core(key), jsonresponse.uuid, jsonresponse.token, jsonresponse.validated, new Player(new Core(key), jsonresponse.player.coreid, jsonresponse.player.username, jsonresponse.player.uuid, jsonresponse.player.verified), new Network(new Core(key), new Instance(new Core(key), jsonresponse.network.uuid, jsonresponse.network.name, "NTW")), "player"));
98+
var player = new Player(core, jsonresponse.player.coreid, jsonresponse.player.username, jsonresponse.player.uuid, jsonresponse.player.verified);
99+
var instance = new Network(core, new Instance(core, jsonresponse.network.uuid, jsonresponse.network.name, "NTW"));
100+
var sessionRequest = new SessionRequest(core, jsonresponse.uuid, jsonresponse.token, jsonresponse.validated, player, instance, "player");
101+
resolve(sessionRequest);
93102
}
94103
}).catch(function (error) {
95104
throw new Error(error);
@@ -102,7 +111,6 @@ class ConnectionHash extends Core {
102111
});
103112
}
104113
}
105-
module.exports.ConnectionHash;
106114
class CheckoutElement extends Core {
107115
constructor(core, products, successFunction) {
108116
super(core.getKey());
@@ -125,7 +133,6 @@ class CheckoutElement extends Core {
125133
});
126134
}
127135
}
128-
module.exports.CheckoutElement;
129136
class Elements extends Core {
130137
constructor(core) {
131138
super(core.getKey());
@@ -135,7 +142,6 @@ class Elements extends Core {
135142
return new CheckoutElement(this.core, products, successFunction);
136143
}
137144
}
138-
module.exports.Elements;
139145
class Instance extends Core {
140146
constructor(core, uuid, name, type) {
141147
super(core.getKey());
@@ -154,7 +160,6 @@ class Instance extends Core {
154160
return new Network(this.core, this);
155161
}
156162
}
157-
module.exports.Instance;
158163
class Network extends Core {
159164
constructor(core, instance) {
160165
super(core.getKey());
@@ -235,8 +240,9 @@ class Network extends Core {
235240
}
236241
else {
237242
var response = new Array();
238-
jsonresponse.forEach(ConnectionHash => {
239-
response.push(new ConnectionHash().fromArray(ConnectionHash));
243+
jsonresponse.forEach(hashData => {
244+
var hash = new ConnectionHash(new Core(key));
245+
response.push(hash.fromArray(hashData));
240246
});
241247
resolve(response);
242248
}
@@ -251,17 +257,96 @@ class Network extends Core {
251257
});
252258
}
253259
}
254-
module.exports.Network;
260+
class Session extends Core {
261+
constructor(core, uuid, hash, device, location, usage, network, player) {
262+
super(core.getKey());
263+
this.core = core;
264+
this.uuid = uuid;
265+
this.hash = hash;
266+
this.device = device;
267+
this.location = location;
268+
this.usage = usage;
269+
this.network = network;
270+
this.player = player;
271+
}
272+
fromArray(array) {
273+
this.uuid = array.uuid;
274+
this.hash = array.hash;
275+
this.device = new SessionDevice(array.device.brand, array.device.device, array.device.model, array.device.os);
276+
this.location = new SessionLocation(array.location.city, array.location.state, array.location.country_code);
277+
this.usage = new SessionUsage(array.usage.creation, array.usage.uses);
278+
this.network = new Network(this.core, new Instance(this.core, array.network.uuid, array.network.name, "NTW"));
279+
this.player = new Player(this.core, array.player.coreid, array.player.username, array.player.uuid, array.player.verified);
280+
return this;
281+
}
282+
}
283+
class SessionDevice {
284+
constructor(brand, device, model, os) {
285+
this.brand = brand;
286+
this.device = device;
287+
this.model = model;
288+
this.os = os;
289+
}
290+
}
291+
class SessionLocation {
292+
constructor(city, state, country_code) {
293+
this.city = city;
294+
this.state = state;
295+
this.country_code = country_code;
296+
}
297+
}
255298
class SessionRequest extends Core {
256299
constructor(core, uuid, token, validated, player, network, type) {
257300
super(core.getKey());
301+
this.core = core;
258302
this.uuid = uuid;
259303
this.token = token;
260304
this.validated = validated;
261305
this.player = player;
262306
this.network = network;
263307
this.type = type;
264308
}
309+
isValidated() {
310+
return this.validated;
311+
}
312+
getValidationUrl() {
313+
return "https://api.purecore.io/link/discord/redirect/?uuid=" + this.uuid + "&hash=" + this.token;
314+
}
315+
getToken() {
316+
return this.token;
317+
}
318+
getSession() {
319+
return __awaiter(this, void 0, void 0, function* () {
320+
var key = this.core.getKey();
321+
var core = this.core;
322+
var token = this.token;
323+
return new Promise(function (resolve, reject) {
324+
try {
325+
return fetch("https://api.purecore.io/rest/2/session/hash/token/exchange/?key=" + key + "&token=" + token, { method: "GET" }).then(function (response) {
326+
return response.json();
327+
}).then(function (jsonresponse) {
328+
if ("error" in jsonresponse) {
329+
throw new Error(jsonresponse.error + ". " + jsonresponse.msg);
330+
}
331+
else {
332+
resolve(new Session(core).fromArray(jsonresponse));
333+
}
334+
}).catch(function (error) {
335+
throw new Error(error);
336+
});
337+
}
338+
catch (e) {
339+
throw new Error(e.message);
340+
}
341+
});
342+
});
343+
}
344+
}
345+
class SessionUsage {
346+
constructor(creation, uses) {
347+
this.creation = creation;
348+
this.uses = uses;
349+
}
265350
}
266351
class StoreCategory {
267352
constructor(uuid, name, description, network, upgradable) {
@@ -272,7 +357,6 @@ class StoreCategory {
272357
this.upgradable = upgradable;
273358
}
274359
}
275-
module.exports.StoreCategory;
276360
class StoreItem {
277361
constructor(uuid, name, description, category, network, price, contextualizedPerks) {
278362
this.uuid = uuid;
@@ -287,7 +371,6 @@ class StoreItem {
287371
return this.uuid;
288372
}
289373
}
290-
module.exports.StoreItem;
291374
class Perk {
292375
constructor(uuid, network, name, description, type, category) {
293376
this.uuid = uuid;
@@ -298,22 +381,19 @@ class Perk {
298381
this.category = category;
299382
}
300383
}
301-
module.exports.Perk;
302384
class PerkCategory {
303385
constructor(uuid, name, network) {
304386
this.uuid = uuid;
305387
this.name = name;
306388
this.network = network;
307389
}
308390
}
309-
module.exports.PerkCategory;
310391
class PerkContextualized {
311392
constructor(perk, quantity) {
312393
this.perk = perk;
313394
this.quantity = quantity;
314395
}
315396
}
316-
module.exports.PerkContextualized;
317397
class Player extends Core {
318398
constructor(core, id, username, uuid, verified) {
319399
super(core.getKey());
@@ -333,4 +413,3 @@ class Player extends Core {
333413
return this.username;
334414
}
335415
}
336-
module.exports.Player;

Diff for: main.js

+49-17
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,57 @@ client.on('message', msg => {
146146

147147
} else if (cmd == "link") {
148148

149-
new Core().fromDiscord(msg.guild.id, auth.token, true).then(function (core) {
149+
if (args.length < 3) {
150+
new Core().fromDiscord(msg.guild.id, auth.token, true).then(function (core) {
150151

151-
var url = "https://api.purecore.io/link/discord/associate/?key=" + core.getKey();
152-
const embed = new Discord.RichEmbed()
153-
.setColor('#ff8a65')
154-
.addField('Link your account', 'Link your game accounts by [clicking here](' + url + ')', false)
155-
.setThumbnail(msg.author.avatarURL)
156-
.setTimestamp()
157-
.setFooter('the all-in-one community managment solution');
158-
msg.channel.send(embed);
152+
var url = "https://api.purecore.io/link/discord/associate/?key=" + core.getKey();
153+
const embed = new Discord.RichEmbed()
154+
.setColor('#ff8a65')
155+
.addField('Link your account', 'Link your game accounts by [clicking here](' + url + ')', false)
156+
.setThumbnail(msg.author.avatarURL)
157+
.setTimestamp()
158+
.setFooter('the all-in-one community managment solution');
159+
msg.channel.send(embed);
160+
161+
}).catch(function (reason) {
162+
const embed = new Discord.RichEmbed()
163+
.setColor('#ff8a65')
164+
.addField('❌ There was an error while generating your authentication url', reason, false)
165+
.setTimestamp()
166+
.setFooter('the all-in-one community managment solution');
167+
msg.channel.send(embed);
168+
});
169+
} else {
170+
if (args[2] == "global") {
171+
new Core().fromDiscord(msg.guild.id, auth.token, true).then(function (core) {
172+
173+
var url = "https://api.purecore.io/link/discord/associate/?key=" + core.getKey();
174+
const embed = new Discord.RichEmbed()
175+
.setColor('#ff8a65')
176+
.addField('Global profile linking', 'Link your game accounts by [clicking here](' + url + ')', false)
177+
.setThumbnail(msg.guild.iconURL)
178+
.setTimestamp()
179+
.setFooter('the all-in-one community managment solution');
180+
msg.channel.send(embed);
181+
182+
}).catch(function (reason) {
183+
const embed = new Discord.RichEmbed()
184+
.setColor('#ff8a65')
185+
.addField('❌ There was an error while generating your authentication url', reason, false)
186+
.setTimestamp()
187+
.setFooter('the all-in-one community managment solution');
188+
msg.channel.send(embed);
189+
});
190+
} else {
191+
const embed = new Discord.RichEmbed()
192+
.setColor('#ff8a65')
193+
.addField('❌ Unknown argument', false)
194+
.setTimestamp()
195+
.setFooter('the all-in-one community managment solution');
196+
msg.channel.send(embed);
197+
}
198+
}
159199

160-
}).catch(function (reason) {
161-
const embed = new Discord.RichEmbed()
162-
.setColor('#ff8a65')
163-
.addField('❌ There was an error while generating your authentication url', reason, false)
164-
.setTimestamp()
165-
.setFooter('the all-in-one community managment solution');
166-
msg.channel.send(embed);
167-
});
168200
} else {
169201

170202
const embed = new Discord.RichEmbed()

0 commit comments

Comments
 (0)