-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
const fetch = require('node-fetch'); | ||
|
||
const RivenStatEmbed = require('../../embeds/RivenStatEmbed'); | ||
const Command = require('../../models/Command.js'); | ||
const { apiBase, setupPages } = require('../../CommonFunctions'); | ||
|
||
/** | ||
* Displays the stats for a warframe | ||
*/ | ||
class FrameStats extends Command { | ||
/** | ||
* Constructs a callable command | ||
* @param {Genesis} bot The bot object | ||
*/ | ||
constructor(bot) { | ||
super(bot, 'warframe.misc.rivens', 'riven', 'Get current riven sales stats'); | ||
this.regex = new RegExp(`^${this.call}\\s?(.+)?`, 'i'); | ||
this.usages = [ | ||
{ | ||
description: 'Get stats for a Weapon riven', | ||
parameters: ['riven name'], | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* Run the command | ||
* @param {Message} message Message with a command to handle, reply to, | ||
* or perform an action based on parameters. | ||
* @param {CommandContext} ctx Command Context object, with settings, platform, locale, etc | ||
* @returns {string} success status | ||
*/ | ||
async run(message, ctx) { | ||
let weapon = message.strippedContent.match(this.regex)[1]; | ||
|
||
if (weapon) { | ||
weapon = weapon.trim().toLowerCase(); | ||
const results = await fetch(`${apiBase}/${ctx.platform}/rivens/search/${weapon}`).then(data => data.json()); | ||
if (Object.keys(results).length > 0) { | ||
const pages = []; | ||
|
||
Object.keys(results).forEach((resultKey) => { | ||
pages.push(new RivenStatEmbed(this.bot, results[resultKey], resultKey, ctx.i18n)); | ||
}); | ||
|
||
await setupPages(pages, { message, settings: this.settings, mm: this.messageManager }); | ||
return this.messageManager.statuses.SUCCESS; | ||
} | ||
this.messageManager.reply(message, `No results for ${weapon}`, true, true); | ||
return this.messageManager.statuses.FAILURE; | ||
} | ||
this.messageManager.reply(message, 'No query specified', true, true); | ||
return this.messageManager.statuses.FAILURE; | ||
} | ||
} | ||
|
||
module.exports = FrameStats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
const BaseEmbed = require('./BaseEmbed.js'); | ||
|
||
/** | ||
* Generates enemy embeds | ||
*/ | ||
class RivenStatEmbed extends BaseEmbed { | ||
/** | ||
* @param {Genesis} bot - An instance of Genesis | ||
* @param {Object} rivenResult details to derive data from | ||
* @param {string} resultKey The query that this search corresponds to | ||
* @param {fn} i18n internationalization function to give string in apprpriate language | ||
*/ | ||
constructor(bot, rivenResult, resultKey, i18n) { | ||
super(); | ||
this.fields = []; | ||
if(rivenResult.rerolled) { | ||
this.fields.push(...[{ | ||
name: i18n`Rerolled`, | ||
value: '\u200B', | ||
inline: false, | ||
}, { | ||
name: i18n`Average Cost`, | ||
value: `${rivenResult.rerolled.avg}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Standard Deviation`, | ||
value: `${rivenResult.rerolled.stddev}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Minimum Cost`, | ||
value: `${rivenResult.rerolled.min}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Maximum Cost`, | ||
value: `${rivenResult.rerolled.max}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Popularity`, | ||
value: `${rivenResult.rerolled.pop}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Median Cost`, | ||
value: `${rivenResult.rerolled.median}`, | ||
inline: true, | ||
}]); | ||
} | ||
|
||
if(rivenResult.unrolled) { | ||
this.fields.push(...[{ | ||
name: '\u200B', | ||
value: '\u200B', | ||
inline: false, | ||
},{ | ||
name: i18n`Unrolled`, | ||
value: '\u200B', | ||
inline: false, | ||
}, { | ||
name: i18n`Average Cost`, | ||
value: `${rivenResult.unrolled.avg}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Standard Deviation`, | ||
value: `${rivenResult.unrolled.stddev}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Minimum Cost`, | ||
value: `${rivenResult.unrolled.min}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Maximum Cost`, | ||
value: `${rivenResult.unrolled.max}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Popularity`, | ||
value: `${rivenResult.unrolled.pop}`, | ||
inline: true, | ||
}, { | ||
name: i18n`Median Cost`, | ||
value: `${rivenResult.unrolled.median}`, | ||
inline: true, | ||
}]); | ||
} | ||
|
||
if (!this.fields.length) { | ||
this.description = i18n`No data available`; | ||
} | ||
|
||
this.title = resultKey; | ||
this.color = 0x84659F; | ||
this.type = 'rich'; | ||
} | ||
} | ||
|
||
module.exports = RivenStatEmbed; |