Browse Source

Update commands to use message.reply, rather than promises

The promise method was just too annoying, better to go back to .reply
master
benji7425 4 years ago
parent
commit
b682b8af5c
  1. 34
      app/commands/add-feed.js
  2. 0
      app/commands/on-text-message.js
  3. 4
      app/commands/remove-feed.js
  4. 4
      app/commands/view-feeds.js
  5. 15
      app/index.js

34
app/commands/add-feed.js

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

0
app/commands/on-text-message.js

4
app/commands/remove-feed.js

@ -11,8 +11,8 @@ module.exports = new Core.Command({
function invoke({ message, params, guildData, client }) {
const idx = guildData.feeds.findIndex(feed => feed.id === params[2]);
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);
return Promise.resolve("Feed removed!");
message.reply("Feed removed!");
}

4
app/commands/view-feeds.js

@ -10,7 +10,7 @@ module.exports = new Core.Command({
function invoke({ message, params, guildData, client }) {
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"));
}

15
app/index.js

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

Loading…
Cancel
Save