Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports.run = async (bot, message, args) => {
- //Const vars
- const {PubgAPI, PubgAPIErrors, REGION, MATCH} = require('pubg-api-redis');
- const SEASON = {
- EA2017pre1: '2017-pre1',
- EA2017pre2: '2017-pre2',
- EA2017pre3: '2017-pre3',
- EA2017pre4: '2017-pre4',
- EA2017pre5: '2017-pre5',
- EA2017pre6: '2017-pre6'
- };
- const pubgAPI = new PubgAPI({apikey: bot.settingscfg.pubgapikey});
- const mysql = require('mysql');
- //Function
- if (bot.servers.get(message.guild.id).pubgRanksDistribute) {
- //Get the configuration file for the servers PUBGsettings
- var fs = require('fs');
- var filename = `/home/TokaHimiko/pubgsettings/${message.guild.id}.json`;
- var pubgsettings = require(filename);
- var isLinked = true;
- var playerinfo;
- var playertofind;
- if (pubgsettings.players.length < 1) {
- //If there are no players linked in the server yet.. Defaulting to false.
- isLinked = false;
- }
- if (isLinked) {
- isLinked = false; //Setting value to false as we don't know if the player is in the serverlist yet.
- if (args.length >= 1) {
- playertofind = message.mentions.users.first().id;
- } else {
- playertofind = message.author.id;
- }
- pubgsettings.players.forEach((player, i) => {
- if (player.player.discordid == playertofind) {
- isLinked = true;
- playerinfo = player.player;
- }
- });
- }
- if (isLinked) {
- var con = mysql.createConnection({
- host: bot.settingscfg.mysqlHost,
- user: bot.settingscfg.mysqlUser,
- password: bot.settingscfg.mysqlPass,
- database: bot.settingscfg.mysqlData
- });
- await con.connect(err => {
- if (err) console.error(err);
- con.query(`SELECT * FROM pubgranks WHERE discorduser = '${playerinfo.discordid}' AND discordserver = '${message.guild.id}'`, (err, rows) => {
- if (err) return console.error(err);
- if (rows.length <= 0) {
- con.query(`INSERT INTO pubgranks (discordserver, discorduser, pubgname) VALUES ('${message.guild.id}', '${playerinfo.discordid}', '${playerinfo.pubgname}')`, (err, rows) => {
- if (err) return console.error(err);
- console.log("Inserted pubgname in mysql database server.");
- })
- } else {
- console.log("user already exists");
- }
- });
- });
- let awaitmessage = await message.channel.send("```Fetching rankings for " + playerinfo.pubgname + ". \nThis may take up to 2 minutes.```");
- try {
- pubgAPI.getProfileByNickname(playerinfo.pubgname).
- then(async(profile) => {
- const data = profile.content;
- var contentstats = data.Stats;
- });
- } catch (err) {
- console.error(err);
- awaitmessage.delete();
- }
- if(stats.length > 0) {
- var {solo, duo, squad, solofpp, duofpp, squadfpp} = false;
- var {na, eu, as, oc, sa, sea, krjp} = false;
- var bestRank = 20000000;
- contentstats.forEach((stat, i) => {
- //EU Checks
- if (stat.Season === SEASON.EA2017pre6 && stat.Region == 'eu') {
- eu = true;
- switch (stat.Match) {
- case "solo":
- solo = false;
- break;
- case "duo":
- duo = false;
- break;
- case "squad":
- squad = true;
- break;
- case "solo-fpp":
- solofpp = false;
- break;
- case "duo-fpp":
- duofpp = false;
- break;
- case "squad-fpp":
- squadfpp = true;
- break;
- }
- }
- });
- var stats;
- //Fetching stats for each Region!
- if (eu) {
- if (solo) {
- stats = profile.getStats({
- region: 'eu',
- season: SEASON.EA2017pre6,
- match: 'solo'
- });
- if (stats.rankData.rating <= bestRank) {
- bestRank = stats.rankData.rating;
- }
- }
- if (duo) {
- stats = profile.getStats({
- region: 'eu',
- season: SEASON.EA2017pre6,
- match: 'duo'
- });
- if (stats.rankData.rating <= bestRank) {
- bestRank = stats.rankData.rating;
- }
- }
- if (squad) {
- stats = profile.getStats({
- region: 'eu',
- season: SEASON.EA2017pre6,
- match: 'squad'
- });
- if (stats.rankData.rating <= bestRank) {
- bestRank = stats.rankData.rating;
- }
- }
- if (solofpp) {
- stats = profile.getStats({
- region: 'eu',
- season: SEASON.EA2017pre6,
- match: 'solo-fpp'
- });
- if (stats.rankData.rating <= bestRank) {
- bestRank = stats.rankData.rating;
- }
- }
- if (duofpp) {
- stats = profile.getStats({
- region: 'eu',
- season: SEASON.EA2017pre6,
- match: 'duo-fpp'
- });
- if (stats.rankData.rating <= bestRank) {
- bestRank = stats.rankData.rating;
- }
- }
- if (squadfpp) {
- stats = profile.getStats({
- region: 'eu',
- season: SEASON.EA2017pre6,
- match: 'squad-fpp'
- });
- if (stats.rankData.rating <= bestRank) {
- bestRank = stats.rankData.rating;
- }
- }
- }
- if (args.length >= 1) {
- message.channel.send("```" + message.author.username + ", I've updated the rank of " + message.mentions.users.first().username + " accordingly to their best rank available: " + bestRank + "```");
- } else {
- message.channel.send("```" + message.author.username + ", I've updated your rank accordingly to your best rank available: " + bestRank + "```");
- }
- con.query(`UPDATE pubgranks SET currentRank = "${bestRank}" WHERE discordserver = "${message.guild.id}" AND discorduser = "${playerinfo.discordid}"`, (err, rows) => {
- if (err) return console.error(err);
- console.log("Updated the database");
- });
- awaitmessage.delete();
- }
- } else {
- let prefix = await bot.servers.get(message.guild.id).prefix;
- if (args.length >= 1) {
- message.channel.send(`${message.author}, ${message.mentions.users.first()} has not yet linked their account to this server. `);
- } else {
- message.channel.send(`You've not yet linked your PUBG name to the bot in this server. Please use ${prefix}pubgaccount <username>`);
- }
- }
- } else {
- message.channel.send(`This server has not enabled this command. Message an server administrator to enable it.`);
- }
- }
- module.exports.commandinfo = async (bot, message, args) => {
- let prefix = bot.servers.get(message.guild.id).prefix;
- let botcolor = await message.guild.fetchMember(bot.user.id).displayHexColor;
- var embed = {
- embed: {
- "title": "Help command for <command>",
- "description": "",
- "fields": [
- {
- "name": "Usage: " + prefix + "",
- "value": "",
- "inline": false
- }
- ],
- "color": 3485
- }
- }
- return embed;
- }
- module.exports.help = {
- name: "pubgrole",
- alias: "pupdate",
- permission: "none",
- category: "pubg",
- helpcommand: false
- }
- //Usage:
- // name: = command name, for example "help"
- // permission: = level of permission, insert one of the flags: https://discord.js.org/#/docs/main/stable/class/Permissions?scrollTo=s-FLAGS
- // category: category of the command
- // helpcommand: if there is an help command available
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement