Update commands to use message.reply, rather than promises

The promise method was just too annoying, better to go back to .reply
This commit is contained in:
benji7425 2017-09-24 21:39:34 +01:00
parent dc889096a5
commit b682b8af5c
5 changed files with 26 additions and 27 deletions

View File

@ -29,22 +29,20 @@ function invoke({ message, params, guildData, client }) {
maxCacheSize: Config.maxCacheSize maxCacheSize: Config.maxCacheSize
}); });
return new Promise((resolve, reject) => { //ask the user if they're happy with the details they set up, save if yes, don't if no
//ask the user if they're happy with the details they set up, save if yes, don't if no Core.util.ask(client, message.channel, message.member, "Are you happy with this (yes/no)?\n" + feedData.toString())
Core.util.ask(client, message.channel, message.member, "Are you happy with this (yes/no)?\n" + feedData.toString()) .then(responseMessage => {
.then(responseMessage => {
//if they responded yes, save the feed and let them know, else tell them to start again //if they responded yes, save the feed and let them know, else tell them to start again
if (responseMessage.content.toLowerCase() === "yes") { if (responseMessage.content.toLowerCase() === "yes") {
if (!guildData) if (!guildData)
guildData = new GuildData({ id: message.guild.id, feeds: [] }); guildData = new GuildData({ id: message.guild.id, feeds: [] });
guildData.feeds.push(feedData); guildData.feeds.push(feedData);
guildData.cachePastPostedLinks(message.guild) guildData.cachePastPostedLinks(message.guild)
.then(() => resolve("Your new feed has been saved!")); .then(() => message.reply("Your new feed has been saved!"));
} }
else else
reject("Your feed has not been saved, please add it again with the correct details"); message.reply("Your feed has not been saved, please add it again with the correct details");
}); });
});
} }

View File

@ -11,8 +11,8 @@ module.exports = new Core.Command({
function invoke({ message, params, guildData, client }) { function invoke({ message, params, guildData, client }) {
const idx = guildData.feeds.findIndex(feed => feed.id === params[2]); const idx = guildData.feeds.findIndex(feed => feed.id === params[2]);
if (!Number.isInteger(idx)) if (!Number.isInteger(idx))
return Promise.reject("Can't find feed with id " + params[2]); message.reply("Can't find feed with id " + params[2]);
guildData.feeds.splice(idx, 1); guildData.feeds.splice(idx, 1);
return Promise.resolve("Feed removed!"); message.reply("Feed removed!");
} }

View File

@ -10,7 +10,7 @@ module.exports = new Core.Command({
function invoke({ message, params, guildData, client }) { function invoke({ message, params, guildData, client }) {
if (!guildData) if (!guildData)
return Promise.reject("Guild not setup"); message.reply("Guild not setup");
return Promise.resolve(guildData.feeds.map(f => f.toString()).join("\n")); message.reply(guildData.feeds.map(f => f.toString()).join("\n"));
} }

View File

@ -13,17 +13,18 @@ client.on("beforeLogin", () => {
setInterval(() => checkFeedsInGuilds(client.guilds, client.guildsData), Config.feedCheckIntervalSec * 1000); setInterval(() => checkFeedsInGuilds(client.guilds, client.guildsData), Config.feedCheckIntervalSec * 1000);
}); });
client.on("ready", (coreClient) => { client.on("ready", () => {
parseLinksInGuilds(coreClient.actual.guilds, coreClient.guildsData) parseLinksInGuilds(client.guilds, client.guildsData)
.then(() => checkFeedsInGuilds(coreClient.actual.guilds, coreClient.guildsData)); .then(() => checkFeedsInGuilds(client.guilds, client.guildsData));
}); });
client.on("message", message => { client.on("message", message => {
const guildData = client.guildsData[message.guild.id]; const guildData = client.guildsData[message.guild.id];
guildData.feeds.forEach(feedData => { if (guildData)
if (message.channel.name === feedData.channelName) guildData.feeds.forEach(feedData => {
feedData.cachedLinks.push(...GetUrls(message.content)); if (message.channel.name === feedData.channelName)
}); feedData.cachedLinks.push(...GetUrls(message.content));
});
}); });
client.bootstrap(); client.bootstrap();