Add passing of parameters to commands
Fix a couple of issues
This commit is contained in:
parent
049ce4d2a8
commit
e6b2ed52ef
21
app/bot.js
21
app/bot.js
|
@ -16,14 +16,14 @@ module.exports = {
|
||||||
.then(() => setInterval(() => checkFeedsInGuilds(client.guilds, guildsData), config.feedCheckIntervalSec * 1000)); //set up an interval to check all the feeds
|
.then(() => setInterval(() => checkFeedsInGuilds(client.guilds, guildsData), config.feedCheckIntervalSec * 1000)); //set up an interval to check all the feeds
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onCommand(commandObj, commandsObj, params, guildData, message) {
|
onCommand(commandObj, commandsObj, params, guildData, message, config, client, botName) {
|
||||||
switch (commandObj.command) {
|
switch (commandObj.command) {
|
||||||
case commandsObj.addFeed.command:
|
case commandsObj.addFeed.command:
|
||||||
return addFeed();
|
return addFeed(client, guildData, message, config.maxCacheSize);
|
||||||
case commandsObj.removeFeed.command:
|
case commandsObj.removeFeed.command:
|
||||||
return removeFeed();
|
return removeFeed(guildData, message, botName);
|
||||||
case commandsObj.viewFeeds.command:
|
case commandsObj.viewFeeds.command:
|
||||||
return viewFeeds();
|
return viewFeeds(guildData);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onNonCommandMsg(message, guildData) {
|
onNonCommandMsg(message, guildData) {
|
||||||
|
@ -34,7 +34,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function addFeed(client, guildsData, message, maxCacheSize) {
|
function addFeed(client, guildData, message, maxCacheSize) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const feedUrl = [...GetUrls(message.content)][0];
|
const feedUrl = [...GetUrls(message.content)][0];
|
||||||
const channel = message.mentions.channels.first();
|
const channel = message.mentions.channels.first();
|
||||||
|
@ -57,10 +57,10 @@ function addFeed(client, guildsData, message, maxCacheSize) {
|
||||||
|
|
||||||
//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 (!guildsData[message.guild.id])
|
if (!guildData)
|
||||||
guildsData[message.guild.id] = new GuildData({ id: message.guild.id, feeds: [] });
|
guildData = new GuildData({ id: message.guild.id, feeds: [] });
|
||||||
|
|
||||||
guildsData[message.guild.id].feeds.push(feedData);
|
guildData.feeds.push(feedData);
|
||||||
resolve("Your new feed has been saved!");
|
resolve("Your new feed has been saved!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -69,19 +69,18 @@ function addFeed(client, guildsData, message, maxCacheSize) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFeed(guildsData, message, botName) {
|
function removeFeed(guildData, message, botName) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const parameters = message.content.split(" ");
|
const parameters = message.content.split(" ");
|
||||||
if (parameters.length !== 3)
|
if (parameters.length !== 3)
|
||||||
resolve(`Please use the command as such:\n\`\`\` ${botName} remove-feed feedid\`\`\``);
|
resolve(`Please use the command as such:\n\`\`\` ${botName} remove-feed feedid\`\`\``);
|
||||||
else {
|
else {
|
||||||
const guildData = guildsData[message.guild.id];
|
|
||||||
const idx = guildData.feeds.findIndex(feed => feed.id === parameters[2]);
|
const idx = guildData.feeds.findIndex(feed => feed.id === parameters[2]);
|
||||||
if (!Number.isInteger(idx))
|
if (!Number.isInteger(idx))
|
||||||
reject("Can't find feed with id " + parameters[2]);
|
reject("Can't find feed with id " + parameters[2]);
|
||||||
else {
|
else {
|
||||||
guildData.feeds.splice(idx, 1);
|
guildData.feeds.splice(idx, 1);
|
||||||
reject("Feed removed!");
|
resolve("Feed removed!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
"discordInvite": "https://discord.gg/SSkbwSJ",
|
"discordInvite": "https://discord.gg/SSkbwSJ",
|
||||||
"defaultDMResponse": "This bot does not have any handling for direct messages. To learn more or get help please visit %s, or join my Discord server here: %s"
|
"defaultDMResponse": "This bot does not have any handling for direct messages. To learn more or get help please visit %s, or join my Discord server here: %s"
|
||||||
},
|
},
|
||||||
|
"maxCacheSize": 100,
|
||||||
"feedCheckIntervalSec": 30,
|
"feedCheckIntervalSec": 30,
|
||||||
"commands": {
|
"commands": {
|
||||||
"version": {
|
"version": {
|
||||||
|
|
Loading…
Reference in a new issue