Update for proper compatibility with current core code
This commit is contained in:
parent
2b0750dada
commit
aeba653e9f
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,4 @@
|
||||||
### Discord bots ####
|
guilds.json
|
||||||
*-data.json
|
|
||||||
token.json
|
token.json
|
||||||
log
|
log
|
||||||
|
|
||||||
|
|
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
|
@ -8,7 +8,11 @@
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Launch Program",
|
"name": "Launch Program",
|
||||||
"program": "${workspaceRoot}/app/index.js"
|
"program": "${workspaceRoot}/app/index.js",
|
||||||
|
"args":[
|
||||||
|
"token.json",
|
||||||
|
"guilds.json"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
7
.vscode/settings.json
vendored
7
.vscode/settings.json
vendored
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"files.exclude": {
|
|
||||||
"log": true,
|
|
||||||
"token.json": true,
|
|
||||||
"_config.yml": true
|
|
||||||
}
|
|
||||||
}
|
|
29
app/index.js
29
app/index.js
|
@ -4,11 +4,12 @@ const GuildData = require("./models/guild-data.js");
|
||||||
const FeedData = require("./models/feed-data.js");
|
const FeedData = require("./models/feed-data.js");
|
||||||
const Config = require("./config.json");
|
const Config = require("./config.json");
|
||||||
|
|
||||||
function onReady(client, guildsData) {
|
//IMPLEMENTATIONS//
|
||||||
|
function onReady(coreClient) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
parseLinksInGuilds(client.guilds, guildsData)
|
parseLinksInGuilds(coreClient.actual.guilds, coreClient.guildsData)
|
||||||
.then(() => checkFeedsInGuilds(client.guilds, guildsData))
|
.then(() => checkFeedsInGuilds(coreClient.actual.guilds, coreClient.guildsData))
|
||||||
.then(() => setInterval(() => checkFeedsInGuilds(client.guilds, guildsData), Config.feedCheckIntervalSec * 1000))
|
.then(() => setInterval(() => checkFeedsInGuilds(coreClient.actual.guilds, coreClient.guildsData), Config.feedCheckIntervalSec * 1000))
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
|
@ -19,9 +20,10 @@ function onTextMessage(message, guildData) {
|
||||||
if (message.channel.name === feedData.channelName)
|
if (message.channel.name === feedData.channelName)
|
||||||
feedData.cachedLinks.push(...GetUrls(message.content)); //spread the urlSet returned by GetUrls into the cache array
|
feedData.cachedLinks.push(...GetUrls(message.content)); //spread the urlSet returned by GetUrls into the cache array
|
||||||
});
|
});
|
||||||
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFeed({ guildData, message, client }) {
|
function addFeed({ command, params, guildData, botName, message, coreClient }) {
|
||||||
const feedUrl = [...GetUrls(message.content)][0];
|
const feedUrl = [...GetUrls(message.content)][0];
|
||||||
const channel = message.mentions.channels.first();
|
const channel = message.mentions.channels.first();
|
||||||
|
|
||||||
|
@ -39,7 +41,7 @@ function addFeed({ guildData, message, client }) {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
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(coreClient.actual, 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
|
||||||
|
@ -56,7 +58,7 @@ function addFeed({ guildData, message, client }) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFeed({ params, guildData, botName }) {
|
function removeFeed({ command, params, guildData, botName, message, coreClient }) {
|
||||||
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]);
|
return Promise.reject("Can't find feed with id " + params[2]);
|
||||||
|
@ -65,13 +67,14 @@ function removeFeed({ params, guildData, botName }) {
|
||||||
return Promise.resolve("Feed removed!");
|
return Promise.resolve("Feed removed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
function viewFeeds(guildData) {
|
function viewFeeds({ command, params, guildData, botName, message, coreClient }) {
|
||||||
if (!guildData)
|
if (!guildData)
|
||||||
return Promise.reject("Guild not setup");
|
return Promise.reject("Guild not setup");
|
||||||
|
|
||||||
return Promise.resolve(guildData.feeds.map(f => f.toString()).join("\n"));
|
return Promise.resolve(guildData.feeds.map(f => f.toString()).join("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//INTERNAL FUNCTIONS//
|
||||||
function checkFeedsInGuilds(guilds, guildsData) {
|
function checkFeedsInGuilds(guilds, guildsData) {
|
||||||
Object.keys(guildsData).forEach(key => guildsData[key].checkFeeds(guilds));
|
Object.keys(guildsData).forEach(key => guildsData[key].checkFeeds(guilds));
|
||||||
}
|
}
|
||||||
|
@ -86,12 +89,16 @@ function parseLinksInGuilds(guilds, guildsData) {
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
//CLIENT SETUP//
|
||||||
|
const token = require("../" + process.argv[2]).token,
|
||||||
|
dataFile = process.argv[3],
|
||||||
|
commands = require("./commands.json"),
|
||||||
|
implementations = {
|
||||||
onReady,
|
onReady,
|
||||||
onTextMessage,
|
onTextMessage,
|
||||||
addFeed,
|
addFeed,
|
||||||
removeFeed,
|
removeFeed,
|
||||||
viewFeeds
|
viewFeeds
|
||||||
};
|
};
|
||||||
|
const client = new Core.Client(token, dataFile, commands, implementations, GuildData);
|
||||||
Core.bootstrap(require("../" + process.argv[2]), module.exports, GuildData, require("./commands.json"));
|
client.bootstrap();
|
|
@ -1,5 +1,5 @@
|
||||||
//my imports
|
//my imports
|
||||||
const DiscordUtil = require("discordjs-util");
|
const DiscordUtil = require("../../discord-bot-core").util;
|
||||||
|
|
||||||
//external lib imports
|
//external lib imports
|
||||||
const Dns = require("dns"); //for host resolution checking
|
const Dns = require("dns"); //for host resolution checking
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
const DiscordUtil = require("../../discord-bot-core").util;
|
const DiscordUtil = require("../../discord-bot-core").util;
|
||||||
|
const FeedData = require("./feed-data.js");
|
||||||
|
|
||||||
module.exports = class GuildData {
|
module.exports = class GuildData {
|
||||||
constructor({ id }) {
|
constructor({ id, feeds }) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.feeds = (feeds || []).map(feed => new FeedData(feed));
|
||||||
|
}
|
||||||
|
|
||||||
|
cachePastPostedLinks(guild) {
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
|
this.feeds.forEach(feed => {
|
||||||
|
promises.push(feed.updatePastPostedLinks(guild).catch(DiscordUtil.dateError));
|
||||||
|
});
|
||||||
|
|
||||||
|
return Promise.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkFeeds(guilds) {
|
||||||
|
this.feeds.forEach(feed => feed.check(guilds.get(this.id)));
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -3,7 +3,7 @@
|
||||||
"main": "app/index.js",
|
"main": "app/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "cd ./discord-bot-core && npm install",
|
"postinstall": "cd ./discord-bot-core && npm install",
|
||||||
"start": "node app/index.js token.json"
|
"start": "node app/index.js token.json guilds.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "11.1.0",
|
"discord.js": "11.1.0",
|
||||||
|
|
Loading…
Reference in a new issue