From 46b514c9bf277c82aa3c3e3525ac80d4b842af75 Mon Sep 17 00:00:00 2001 From: Emily J Date: Mon, 1 Mar 2021 11:54:01 +1100 Subject: [PATCH] splatnet commands --- bot/commands/Splatoon/salmonrun.js | 74 +++++++++++++++++++++++++++ bot/commands/Splatoon/splatnet.js | 50 ++++++++++++++++++ bot/commands/Splatoon/splatoonmaps.js | 56 ++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 bot/commands/Splatoon/salmonrun.js create mode 100644 bot/commands/Splatoon/splatnet.js create mode 100644 bot/commands/Splatoon/splatoonmaps.js diff --git a/bot/commands/Splatoon/salmonrun.js b/bot/commands/Splatoon/salmonrun.js new file mode 100644 index 0000000..6ee80e1 --- /dev/null +++ b/bot/commands/Splatoon/salmonrun.js @@ -0,0 +1,74 @@ +const fetch = require('node-fetch'); +const prettifyMiliseconds = require('pretty-ms'); +const { createPaginationEmbed } = require('eris-pagination'); + +module.exports = class { + constructor (name, category) { + this.name = name, + this.category = category, + this.enabled = true, + this.devOnly = false, + this.aliases = [], + this.userPerms = [], + this.botPerms = [], + this.cooldown = 5000, + this.help = { + description: 'Get current map, weapons and gear for salmon run.', + arguments: '', + details: '', + examples: '' + }; + } + + run (client, message, args, data) { //eslint-disable-line no-unused-vars + message.channel.sendTyping(); + fetch('https://splatoon2.ink/data/coop-schedules.json', { headers: { 'User-Agent': client.config.userAgent }}) + .then(res => res.json()) + .then(json => { + fetch('https://splatoon2.ink/data/timeline.json', { headers: { 'User-Agent': client.config.userAgent }}) + .then(timelineRes => timelineRes.json()) + .then(timelineJson => { + + const embeds = []; + + if ((json.details[0].start_time * 1000) > Date.now() === true) { + embeds.push( + new client.RichEmbed() + .setTitle('Upcoming Salmon Run') + .setColour(client.functions.displayHexColour(message.channel.guild, client.user.id)) + .setImage('https://splatoon2.ink/assets/splatnet/'+json.details[0].stage.image) + .addField('Map', json.details[0].stage.name, true) + .setFooter(`Starting in ${prettifyMiliseconds(json.details[0].start_time * 1000 - Date.now(), { secondsDecimalDigits: 0 })} | Data provided by splatoon2.ink`) + ); + } else { + embeds.push( + new client.RichEmbed() + .setTitle('Current Salmon Run') + .setColour(client.functions.displayHexColour(message.channel.guild, client.user.id)) + .setThumbnail('https://splatoon2.ink/assets/splatnet'+timelineJson.coop.reward_gear.gear.image) + .setImage('https://splatoon2.ink/assets/splatnet/'+json.details[0].stage.image) + .addField('Map', json.details[0].stage.name, true) + .addField('Reward Gear', timelineJson.coop.reward_gear.gear.name, true) + .addField('Weapons', json.details[0].weapons[0].weapon.name+', '+json.details[0].weapons[1].weapon.name+', '+json.details[0].weapons[2].weapon.name+', '+json.details[0].weapons[3].weapon.name) + .setFooter(`Ending in ${prettifyMiliseconds((json.details[0].end_time * 1000) - Date.now(), { secondsDecimalDigits: 0 })} | Data provided by splatoon2.ink`) + ); + } + + embeds.push( + new client.RichEmbed() + .setTitle('Upcoming Salmon Run') + .setColour(client.functions.displayHexColour(message.channel.guild, client.user.id)) + .setImage('https://splatoon2.ink/assets/splatnet/'+json.details[1].stage.image) + .addField('Map', json.details[1].stage.name, true) + .addField('Weapons', json.details[1].weapons[1].weapon.name+', '+json.details[1].weapons[1].weapon.name+', '+json.details[1].weapons[2].weapon.name+', '+json.details[1].weapons[3].weapon.name) + .setFooter(`Starting in ${prettifyMiliseconds(json.details[1].start_time * 1000 - Date.now(), { secondsDecimalDigits: 0 })} | Data provided by splatoon2.ink`) + ); + + createPaginationEmbed(message, embeds); + }); + }) + .catch(err => { + message.channel.createMessage(`${client.emojis.botError} An error has occurred: ${err}`); + }); + } +}; \ No newline at end of file diff --git a/bot/commands/Splatoon/splatnet.js b/bot/commands/Splatoon/splatnet.js new file mode 100644 index 0000000..07b4441 --- /dev/null +++ b/bot/commands/Splatoon/splatnet.js @@ -0,0 +1,50 @@ +const fetch = require('node-fetch'); +const prettifyMiliseconds = require('pretty-ms'); +const { createPaginationEmbed } = require('eris-pagination'); + +module.exports = class { + constructor (name, category) { + this.name = name, + this.category = category, + this.enabled = true, + this.devOnly = false, + this.aliases = [], + this.userPerms = [], + this.botPerms = [], + this.cooldown = 5000, + this.help = { + description: 'See what is currently on offer in the splatnet shop', + arguments: '', + details: '', + examples: '' + }; + } + + run (client, message, args, data) { //eslint-disable-line no-unused-vars + message.channel.sendTyping(); + fetch('https://splatoon2.ink//data/merchandises.json', { headers: { 'User-Agent': client.config.userAgent }}) + .then(res => res.json()) + .then(json => { + const embeds = []; + + for ( let i = 0; i < json.merchandises.length; i++ ) { + const embed = new client.RichEmbed() + .setTitle(json.merchandises[i].gear.name) + .setThumbnail('https://splatoon2.ink/assets/splatnet' + json.merchandises[i].gear.image) + .setColour(client.functions.displayHexColour(message.channel.guild, client.user.id)) + .addField('Price', (json.merchandises[i].price).toString(), true) + .addField('Brand', json.merchandises[i].gear.brand.name, true) + .addField('Ability Slots', (json.merchandises[i].gear.rarity + 1).toString(), true) + .addField('Main Ability', json.merchandises[i].skill.name, true) + .addField('Common Ability', json.merchandises[i].gear.brand.frequent_skill.name, true) + .setFooter('Out of stock in ' + prettifyMiliseconds(json.merchandises[i].end_time * 1000 - Date.now()) + ' | Data provided by splatoon2.ink'); + embeds.push(embed); + } + + createPaginationEmbed(message, embeds); + }) + .catch(err => { + message.channel.createMessage(`${client.emojis.botError} An error has occurred: ${err}`); + }); + } +}; \ No newline at end of file diff --git a/bot/commands/Splatoon/splatoonmaps.js b/bot/commands/Splatoon/splatoonmaps.js new file mode 100644 index 0000000..32fb970 --- /dev/null +++ b/bot/commands/Splatoon/splatoonmaps.js @@ -0,0 +1,56 @@ +const fetch = require('node-fetch'); +const prettifyMiliseconds = require('pretty-ms'); +const { createPaginationEmbed } = require('eris-pagination'); + +module.exports = class { + constructor (name, category) { + this.name = name, + this.category = category, + this.enabled = true, + this.devOnly = false, + this.aliases = ['splatoonmodes'], + this.userPerms = [], + this.botPerms = [], + this.cooldown = 5000, + this.help = { + description: 'Get current and upcoming maps and modes for regular, ranked and league battles.', + arguments: '', + details: '', + examples: '' + }; + } + + run (client, message, args, data) { //eslint-disable-line no-unused-vars + message.channel.sendTyping(); + fetch('https://splatoon2.ink/data/schedules.json', { headers: { 'User-Agent': client.config.userAgent }}) + .then(res => res.json()) + .then(json => { + + const embeds = [ + new client.RichEmbed() + .setTitle('Current Splatoon 2 Maps') + .setColour(client.functions.displayHexColour(message.channel.guild, client.user.id)) + .addField('<:turf_war:814651383911153692> Turf War', `${json.regular[0].stage_a.name}\n${json.regular[0].stage_b.name}`, true) + .addField(`<:ranked:814651402479468544> Ranked: ${json.gachi[0].rule.name}`, `${json.gachi[0].stage_a.name}\n${json.gachi[0].stage_b.name}`, true) + .addField(`<:league:814651415409590363> League: ${json.league[0].rule.name}`, `${json.league[0].stage_a.name}\n${json.league[0].stage_b.name}`, true) + .setFooter(`Maps changing in ${prettifyMiliseconds(json.league[0].end_time * 1000 - Date.now(), { secondsDecimalDigits: 0 })} | Data provided by splatoon2.ink`) + ]; + + for ( let i = 1; i < json.regular.length; i++ ) { + const embed = new client.RichEmbed() + .setTitle('Upcoming Splatoon 2 Maps') + .setColour(client.functions.displayHexColour(message.channel.guild, client.user.id)) + .addField('<:turf_war:814651383911153692> Turf War', `${json.regular[i].stage_a.name}\n${json.regular[i].stage_b.name}`, true) + .addField(`<:ranked:814651402479468544> Ranked: ${json.gachi[i].rule.name}`, `${json.gachi[i].stage_a.name}\n${json.gachi[i].stage_b.name}`, true) + .addField(`<:league:814651415409590363> League: ${json.league[i].rule.name}`, `${json.league[i].stage_a.name}\n${json.league[i].stage_b.name}`, true) + .setFooter(`Available in ${prettifyMiliseconds(json.league[i].start_time * 1000 - Date.now(), { secondsDecimalDigits: 0 })} | Data provided by splatoon2.ink`); + embeds.push(embed); + } + + createPaginationEmbed(message, embeds); + }) + .catch(err => { + message.channel.createMessage(`${client.emojis.botError} An error has occurred: ${err}`); + }); + } +}; \ No newline at end of file