|
@@ -1,87 +1,35 @@
|
|
|
const Discord = require("discord.js");
|
|
|
const TOKEN = require("./token.js");
|
|
|
-const lowdb = require("lowdb");
|
|
|
-const FileSync = require("lowdb/adapters/FileSync");
|
|
|
-
|
|
|
-const adapter = new FileSync(__dirname + "/db.json");
|
|
|
-const db = lowdb(adapter);
|
|
|
-
|
|
|
-db._.mixin({
|
|
|
- randomElement: array => array[Math.floor(Math.random() * array.length)]
|
|
|
-});
|
|
|
-
|
|
|
-//https://cdn.discordapp.com/emojis/490234360558125057.png?v=1
|
|
|
-
|
|
|
-db.defaults({
|
|
|
- emotes: {
|
|
|
- angery: [
|
|
|
- "488797492352385034",
|
|
|
- "488797455899688971",
|
|
|
- "488796668750200842",
|
|
|
- "488796396175097876",
|
|
|
- "488793566982963231",
|
|
|
- "488793511181811749",
|
|
|
- "488791172085448718",
|
|
|
- "489091926474096651"
|
|
|
- ],
|
|
|
- hug: [
|
|
|
- "489094486132260864",
|
|
|
- "489094428410249218",
|
|
|
- "489094553148850176",
|
|
|
- "489094604935790622",
|
|
|
- "485109695846023209",
|
|
|
- "490234326210969624",
|
|
|
- "490234276676239370",
|
|
|
- "490234106370588681",
|
|
|
- "490234821696815125"
|
|
|
- ],
|
|
|
- big: [
|
|
|
- "489773326386855937",
|
|
|
- "489771762351996928",
|
|
|
- "489771390279483394",
|
|
|
- "489773282036547599"
|
|
|
- ],
|
|
|
- ded: [
|
|
|
- "490234399351373825",
|
|
|
- "490234360558125057"
|
|
|
- ]
|
|
|
- },
|
|
|
- specialUsers: [
|
|
|
- "141880968800763905",
|
|
|
- "307897683849510912",
|
|
|
- "335898304472678402"
|
|
|
- ],
|
|
|
- reactableMentionedUsers: ["307897683849510912"],
|
|
|
- bigUsers : ["432821242366656512"],
|
|
|
- dedUsers: ["326520875027267584"],
|
|
|
- guides: [],
|
|
|
- editors: {
|
|
|
- roles: ["484046157971193866", "305844721622712322"],
|
|
|
- users: [
|
|
|
- "307897683849510912",
|
|
|
- "170116346095468545",
|
|
|
- "335898304472678402"
|
|
|
- ]
|
|
|
- }
|
|
|
-}).write();
|
|
|
+const db = require("./db.js");
|
|
|
+const RSSParser = require("rss-parser");
|
|
|
+const interval = require("interval-promise");
|
|
|
|
|
|
const client = new Discord.Client();
|
|
|
+const parser = new RSSParser();
|
|
|
+const RSS_UPDATE_INTERVAL_MIN = 5;
|
|
|
+
|
|
|
+async function checkFeeds() {
|
|
|
+ let feeds = db.get("rssFeeds").value();
|
|
|
+ let outlets = db.get("feedOutputs").value();
|
|
|
+ for(let feedEntry of feeds) {
|
|
|
+ let feed = await parser.parseURL(feedEntry.url);
|
|
|
+ if(feed.items.length == 0)
|
|
|
+ continue;
|
|
|
+ let latestPost = feed.items[0];
|
|
|
+ if(latestPost.isoDate > feedEntry.lastUpdate) {
|
|
|
+ db.get("rssFeeds").find({ url: feedEntry.url}).assign({lastUpdate: latestPost.isoDate}).write();
|
|
|
+
|
|
|
+ outlets.forEach(ch => {
|
|
|
+ client.channels.get(ch).send(`**${latestPost.title}**\nPosted by ${latestPost.creator}\n${latestPost.link}`);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
function isAuthorised(member) {
|
|
|
- if (
|
|
|
- db
|
|
|
- .get("editors.users")
|
|
|
- .includes(member.id)
|
|
|
- .value()
|
|
|
- )
|
|
|
+ if (db.get("editors.users").includes(member.id).value())
|
|
|
return true;
|
|
|
- if (
|
|
|
- db
|
|
|
- .get("editors.roles")
|
|
|
- .intersectionWith(member.roles.keyArray())
|
|
|
- .isEmpty()
|
|
|
- .value()
|
|
|
- )
|
|
|
+ if (db.get("editors.roles").intersectionWith(member.roles.keyArray()).isEmpty().value())
|
|
|
return false;
|
|
|
return true;
|
|
|
}
|
|
@@ -142,6 +90,7 @@ const commands = {
|
|
|
client.on("ready", () => {
|
|
|
console.log("Ready!");
|
|
|
client.user.setActivity("@NoctBot help", { type: "PLAYING" });
|
|
|
+ interval(checkFeeds, RSS_UPDATE_INTERVAL_MIN * 60 * 1000);
|
|
|
});
|
|
|
|
|
|
client.on("message", m => {
|