Skip to content

Commit

Permalink
More message manager consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Feb 25, 2017
1 parent 26f85fb commit c2e5dad
Show file tree
Hide file tree
Showing 33 changed files with 169 additions and 223 deletions.
6 changes: 6 additions & 0 deletions src/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class Command {
* @type {Boolean}
*/
this.allowDM = true;

/**
* Message manager for sending and managing messages
* @type {MessageManager}
*/
this.messageManager = bot.messageManager;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/commands/Core/Bug.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class BugReport extends Command {
};
}
}
this.bot.messageManager.sendDirectEmbedToOwner(embed);
this.bot.messageManager.sendReply(message, 'Bug report sent.', true, true);
this.messageManager.sendDirectEmbedToOwner(embed);
this.messageManager.reply(message, 'Bug report sent.', true, true);
} else {
const embed = {
author: {
Expand All @@ -79,7 +79,7 @@ class BugReport extends Command {
title: `Bug Report | ${message.author}`,
fields: [{ name: '_ _', value: 'Need to provide a bug report, see `/help` for syntax.' }],
};
this.bot.messageMAnager.sendEmbed(message, embed, true, false);
this.messageManager.embed(message, embed, true, false);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Core/Help.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Help extends Command {
*/
run(message) {
if (message.channel.type !== 'dm') {
this.bot.messageManager.sendReply(message, this.helpReplyMsg, true, false);
this.messageManager.reply(message, this.helpReplyMsg, true, false);
}
this.sendCoreEmbed(message);
this.sendSettingsEmbed(message);
Expand Down Expand Up @@ -119,7 +119,7 @@ class Help extends Command {
};
}
if (commands.length > 0) {
this.bot.messageManager.sendDirectEmbedToAuthor(message, embed, false);
this.messageManager.sendDirectEmbedToAuthor(message, embed, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/Alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Alerts extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const alerts = ws.alerts.filter(a => !a.getExpired());
this.bot.messageManager.sendEmbed(message, new AlertEmbed(this.bot, alerts), true, false);
this.messageManager.embed(message, new AlertEmbed(this.bot, alerts), true, false);
})
.catch(this.logger.error);
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Ondemand/Armor.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Armor extends Command {
text: 'Data evaluated by Warframe Community Developers',
},
};
this.bot.messageManager.sendEmbed(message, embed, true, false);
this.messageManager.embed(message, embed, true, false);
} else {
this.logger.debug('Entered 0-param armor');
this.sendUsage(message);
Expand Down Expand Up @@ -139,7 +139,7 @@ class Armor extends Command {
},
};

this.bot.messageManager.sendEmbed(message, embed, true, false);
this.messageManager.embed(message, embed, true, false);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/ConclaveChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ConclaveChallenges extends Command {
.then((ws) => {
const conclaveChallenges = ws.conclaveChallenges;
const embed = new ConclaveChallengeEmbed(this.bot, conclaveChallenges, category);
this.bot.messageManager.sendEmbed(message, embed, true, false);
this.messageManager.embed(message, embed, true, false);
})
.catch(this.logger.error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/Darvo.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Darvo extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const deal = ws.dailyDeals[0];
this.bot.messageManager.sendEmbed(message, new DarvoEmbed(this.bot, deal), true, false);
this.messageManager.embed(message, new DarvoEmbed(this.bot, deal), true, false);
})
.catch(this.logger.error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/EarthCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class EarthCycle extends Command {
*/
run(message) {
const state = getCurrentEarthCycle();
this.bot.messageManager.sendEmbed(message, new EarthCycleEmbed(this.bot, state), true, false);
this.messageManager.embed(message, new EarthCycleEmbed(this.bot, state), true, false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/Enemies.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Enemies extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const persistentEnemies = ws.persistentEnemies;
this.bot.messageManager.sendEmbed(message,
this.messageManager.embed(message,
new EnemyEmbed(this.bot, persistentEnemies), true, false);
})
.catch(this.logger.error);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/FeaturedDeal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FeaturedDeal extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const sales = ws.flashSales.filter(popularItem => popularItem.isFeatured);
this.bot.messageManager.sendEmbed(message,
this.messageManager.embed(message,
new SalesEmbed(this.bot, sales), true, false);
})
.catch(this.logger.error);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/Fissures.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Fissures extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const fissures = ws.fissures;
this.bot.messageManager.sendEmbed(message,
this.messageManager.embed(message,
new FissureEmbed(this.bot, fissures), true, false);
})
.catch(this.logger.error);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/Invasions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Invasions extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const invasions = ws.invasions.filter(i => !i.completed);
this.bot.messageManager.sendEmbed(message,
this.messageManager.embed(message,
new InvasionEmbed(this.bot, invasions), true, false);
})
.catch(this.logger.error);
Expand Down
34 changes: 13 additions & 21 deletions src/commands/Ondemand/Mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Mod extends Command {
constructor(bot) {
super(bot, 'warframe.misc.mod', 'mod', 'Search the Warframe Wiki for a mod\'s image');
this.regex = new RegExp('^mod(.+)', 'i');
this.noResultStr = `${this.md.codeMulti}No result for search, Operator. Attempt another search query.${this.md.blockEnd}`;
}

/**
Expand All @@ -26,7 +27,7 @@ class Mod extends Command {
run(message) {
const query = this.regex.exec(message.strippedContent.match(this.regex)[0])[1];
if (!query) {
message.reply(`${this.md.codeMulti}Please specify a search term${this.md.blockEnd}`);
this.messageManager.reply(message, this.noResultStr, true, false);
} else {
warframe.getSearchList({
query,
Expand All @@ -49,35 +50,26 @@ class Mod extends Command {
list.items.forEach((item) => {
if (item.id === id) {
sent = true;
message.channel.sendFile(thumbUrl, 'Mod.png', message.author.toString()).then(() => {
if (message.deletable) {
return message.delete(2000);
}
return Promise.resolve();
}).catch(this.logger.error);
const embed = {
title: query,
color: 0xC0C0C0,
description: `Mod result for ${query}`,
image: {
url: thumbUrl,
},
};
this.messageManager.embed(message, embed, true, false);
}
});
if (!sent) {
message.reply(`${this.md.codeMulti}No result for search, Operator. Attempt another search query.${this.md.blockEnd}`)
.then(() => {
if (message.deletable) {
return message.delete(2000);
}
return Promise.resolve();
}).catch(this.logger.error);
this.messageManager.reply(message, this.noResultStr, true, false);
}
});
});
})
.catch((error) => {
this.logger.error(error);
message.reply(`${this.md.codeMulti}No result for search, Operator. Attempt another search query.${this.md.blockEnd}`)
.then(() => {
if (message.deletable) {
return message.delete(2000);
}
return Promise.resolve();
}).catch(this.logger.error);
this.messageManager.reply(message, this.noResultStr, true, false);
});
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/commands/Ondemand/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ class News extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const news = ws.news;
return message.channel.sendEmbed(new NewsEmbed(this.bot, news));
}).then(() => {
if (message.deletable) {
return message.delete(2000);
}
return Promise.resolve();
this.messageManager.embed(message, new NewsEmbed(this.bot, news), true, false);
})
.catch(this.logger.error);
}
Expand Down
8 changes: 1 addition & 7 deletions src/commands/Ondemand/PopularSale.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ class PopularSale extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const sales = ws.flashSales.filter(popularItem => popularItem.isPopular);
return message.channel.sendEmbed(new SalesEmbed(this.bot, sales));
})
.then(() => {
if (message.deletable) {
return message.delete(2000);
}
return new Promise();
this.messageManager.embed(message, new SalesEmbed(this.bot, sales), true, false);
})
.catch(this.logger.error);
}
Expand Down
45 changes: 3 additions & 42 deletions src/commands/Ondemand/Pricecheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Nexus = require('warframe-nexus-query');
const Command = require('../../Command.js');
const PriceCheckEmbed = require('../../embeds/PriceCheckEmbed.js');

/**
* Looks up items from Nexus-stats.com
Expand Down Expand Up @@ -35,48 +36,8 @@ class PriceCheck extends Command {

this.nexusQuerier.priceCheckQueryAttachment(item)
.then((result) => {
let embed = {};
if (typeof result[0] === 'string') {
embed = {
color: 0xff0000,
title: 'Warframe - Pricecheck',
url: 'http://nexus-stats.com',
description: `Pricecheck for: ${item}`,
thumbnail: {
url: 'https://cdn.discordapp.com/icons/195582152849620992/4c1fbd47b3e6c8d49b6d2362c79a537b.jpg',
},
fields: [
{
name: '_ _',
value: result[0],
inline: true,
},
],
footer: {
icon_url: 'https://cdn.discordapp.com/icons/195582152849620992/4c1fbd47b3e6c8d49b6d2362c79a537b.jpg',
text: 'Pricechecks provided by Nexus Stats - https://nexus-stats.com',
},
};
} else {
const attachment = result[0];
embed = {
description: `Price query for ${item}`,
color: parseInt(attachment.color, 16),
type: attachment.type,
title: attachment.title,
url: attachment.url,
fields: attachment.fields,
thumbnail: attachment.thumbnail,
footer: attachment.footer,
};
}
return message.channel.sendEmbed(embed);
})
.then(() => {
if (message.deletable) {
return message.delete(2000);
}
return Promise.resolve();
this.messageManager.embed(message,
new PriceCheckEmbed(this.bot, result, item), true, false);
})
.catch(this.logger.error);
}
Expand Down
7 changes: 1 addition & 6 deletions src/commands/Ondemand/PrimeAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ class PrimeAccess extends Command {
.then(platform => this.bot.worldStates[platform].getData())
.then((ws) => {
const news = ws.news.filter(n => n.isPrimeAccess());
return message.channel.sendEmbed(new PrimeAccessEmbed(this.bot, news, 'primeaccess'));
}).then(() => {
if (message.deletable) {
return message.delete(2000);
}
return Promise.resolve();
this.messageManager.embed(message, new PrimeAccessEmbed(this.bot, news, 'primeaccess'), true, false);
})
.catch(this.logger.error);
}
Expand Down
16 changes: 3 additions & 13 deletions src/commands/Ondemand/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,22 @@ class FrameProfile extends Command {
*/
run(message) {
let frame = message.strippedContent.match(this.regex)[1];
let promise;
if (frame) {
frame = frame.trim().toLowerCase();

profiles.forEach((profile) => {
if (new RegExp(profile.regex, 'ig').test(frame)) {
promise = message.reply(`Warfame Profile | ${profile.name} : ${profile.url}`);
this.messageManager.reply(message, `Warfame Profile | ${profile.name} : ${profile.url}`, true, false);
}
});
} else {
promise = message.channel.sendEmbed({
this.messageManager.embed(message, {
title: 'Available Profiles',
fields: [{ name: '_ _', value: profiles.map(profile => profile.name).join('\n') }],
footer: {
icon_url: 'https://avatars1.githubusercontent.com/u/24436369',
text: 'Data evaluated by Warframe Community Developers',
},
});
}
if (promise) {
promise.then(() => {
if (message.deletable) {
message.delete(10000);
}
})
.catch(this.logger.error);
}, true, false);
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions src/commands/Ondemand/Raid.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,10 @@ class Raid extends Command {
.then((platform) => {
const url = encodeURI(`https://api.trials.wf/api/player/${platform.toLowerCase()}/${query}/completed`);
const raidCache = new Cache(url, 999999);

raidCache.getDataJson().then((data) => {
const embed = new RaidEmbed(this.bot, data, query);
return message.channel.sendEmbed(embed);
this.messageManager.embed(message, new RaidEmbed(this.bot, data, query), true, false);
});
})
.then(() => {
if (message.deletable) {
return message.delete(2000);
}
return Promise.resolve();
})
.catch(this.logger.error);
}
}
Expand Down
Loading

0 comments on commit c2e5dad

Please sign in to comment.