Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fomorian/Razorback construction and Events #125

Merged
merged 16 commits into from
Sep 20, 2017
30 changes: 30 additions & 0 deletions src/commands/Worldstate/Construction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const Command = require('../../Command.js');
const EventEmbed = require('../../embeds/ConstructionEmbed.js');

/**
* Displays the current simaris target
*/
class Construction extends Command {
/**
* Constructs a callable command
* @param {Genesis} bot The bot object
*/
constructor(bot) {
super(bot, 'warframe.worldstate.construction', 'construction', 'Display current construction progress.');
this.regex = new RegExp(`^${this.call}(?:\\s+on\\s+([pcsxb14]{2,3}))?$`, 'i');
}

async run(message) {
const platformParam = message.strippedContent.match(this.regex)[1];
const platform = platformParam || await this.bot.settings
.getChannelSetting(message.channel, 'platform');
const ws = await this.bot.caches[platform].getDataJson();
await this.messageManager.embed(message, new EventEmbed(this.bot,
ws.constructionProgress, platform.toUpperCase()), true, true);
return this.messageManager.statuses.SUCCESS;
}
}

module.exports = Construction;
39 changes: 39 additions & 0 deletions src/commands/Worldstate/Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

const Command = require('../../Command.js');
const EventEmbed = require('../../embeds/EventEmbed.js');

/**
* Displays the current event statuses
*/
class Event extends Command {
/**
* Constructs a callable command
* @param {Genesis} bot The bot object
*/
constructor(bot) {
super(bot, 'warframe.worldstate.events', 'events', 'Display current events.');
this.regex = new RegExp(`^${this.call}(?:\\s+on\\s+([pcsxb14]{2,3}))?$`, 'i');
}

async run(message) {
const platformParam = message.strippedContent.match(this.regex)[1];
const platform = platformParam || await this.bot.settings
.getChannelSetting(message.channel, 'platform');
const ws = await this.bot.caches[platform].getDataJson();
if (ws.events.length > 0) {
const results = [];
ws.events.forEach(event => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected parentheses around arrow function argument having a body with curly braces. (arrow-parens)

results.push(this.messageManager.embed(message,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 8 spaces but found 10. (indent)
Trailing spaces not allowed. (no-trailing-spaces)

new EventEmbed(this.bot, event, platform.toUpperCase()), true, true));
});
await Promise.all(results);
return this.messageManager.statuses.SUCCESS;
}
await this.messageManager.embed(message, new EventEmbed(this.bot,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces not allowed. (no-trailing-spaces)

undefined, platform.toUpperCase()), true, true);
return this.messageManager.statuses.FAILURE;
}
}

module.exports = Event;
29 changes: 29 additions & 0 deletions src/embeds/ConstructionEmbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const BaseEmbed = require('./BaseEmbed.js');

/**
* Generates daily deal embeds
*/
class ConstructionEmbed extends BaseEmbed {
/**
* @param {Genesis} bot - An instance of Genesis
* @param {Construction} constructionProgress - The current construction information
* @param {string} platform - The platform the event is for
*/
constructor(bot, constructionProgress, platform) {
super();

this.color = 0xff6961;
this.fields = [{
name: `[${platform}] Construction Status:`,
value: '```' +
`Razorback: ${constructionProgress.razorbackProgress}` +
`Fomorian: ${constructionProgress.fomorianProgress}` +
`Unknown: ${constructionProgress.unknwonProgress}` +
'```',
}];
}
}

module.exports = ConstructionEmbed;
91 changes: 34 additions & 57 deletions src/embeds/EventEmbed.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,34 @@
'use strict';

const BaseEmbed = require('./BaseEmbed.js');

/**
* Generates fissure embeds
*/
class EventEmbed extends BaseEmbed {
/**
* @param {Genesis} bot - An instance of Genesis
* @param {Array.<Event>} events - The fissures to be included in the embed
*/
constructor(bot, events) {
super();

if (events.length < 2) {
this.title = 'Worldstate - Events';
this.description = 'Events';
}

if (events.length > 1) {
this.fields = events.map(e => ({
name: `${e.description}`,
value: `Takes place on: ${e.concurrentNodes.join(', ')}\nRewards: ${e.rewards.join(', ')}`,
}));
} else if (events.length === 0) {
this.fields = {
name: 'Currently no events',
value: '_ _',
};
} else {
const e = events[0];
this.title = 'Event! ';
this.description = `${e.description} against ${e.faction}`;
this.fields = [
{
name: 'Rewards',
value: e.rewards.join('\n'),
inline: true,
},
{
name: 'Nodes',
value: `${e.concurrentNodes.join('\n')}\n${e.node ? e.node : ''}\n${e.victimNode ? e.victimNode : ''}`,
inline: true,
},
];
this.footer.text = e.toolTip ? e.toolTip : this.footer.text;
}

this.color = events.length > 2 ? 0x00ff00 : 0xff0000;
this.thumbnail = {
url: 'https://i.imgur.com/EfIRu6v.png',
};
}
}

module.exports = EventEmbed;
'use strict';

const BaseEmbed = require('./BaseEmbed.js');

/**
* Generates daily deal embeds
*/
class EventEmbed extends BaseEmbed {
/**
* @param {Genesis} bot - An instance of Genesis
* @param {Event} event - The deal to be included in the embed
* @param {string} platform - The platform the event is for
*/
constructor(bot, event, platform) {
super();

this.color = 0xfdec96;

if (event) {
this.title = `[${platform}] ${event.description}`;
this.fields = [];

if (event.victimNode) {
this.fields.push({name: '_ _', value: `Defend ${event.victimNode} by attacking the ${event.faction} at ${event.node}.` });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected indentation of 8 spaces but found 10. (indent)
A space is required after '{'. (object-curly-spacing)

}
this.fields.push({ name: 'Rewards', value: event.rewards.map(reward => reward.asString).join('; ') });
this.fields.push({ name: 'Completion Score', value: String(event.maximumScore) });
} else {
this.title = 'No Current Events';
}
}
}

module.exports = EventEmbed;