Merged feature/subscribers-role into develop
This commit is contained in:
commit
b4b88a56ba
|
@ -1,23 +1,24 @@
|
||||||
{
|
{
|
||||||
"feedUrl": "https://www.youtube.com/feeds/videos.xml?user=EthosLab",
|
"feedUrl": "https://www.youtube.com/feeds/videos.xml?user=EthosLab",
|
||||||
"channelID": "264420391282409473",
|
"channelID": "264420391282409473",
|
||||||
|
"serverID": "264420391282409473",
|
||||||
"pollingInterval": 5000,
|
"pollingInterval": 5000,
|
||||||
"numLinksToCache": 10,
|
"numLinksToCache": 10,
|
||||||
"messageDeleteDelay": 10000,
|
"messageDeleteDelay": 10000,
|
||||||
"youtubeMode": true,
|
"youtubeMode": true,
|
||||||
|
"allowSubscriptions": true,
|
||||||
|
"subscribersRoleID": "272788856447959040",
|
||||||
"logFile": "./log",
|
"logFile": "./log",
|
||||||
"subscribersFile": "./subscribers.json",
|
|
||||||
"userCommands": {
|
"userCommands": {
|
||||||
"subscribe": "!subscribe",
|
"subscribe": "!subscribe",
|
||||||
"unsubscribe": "!unsubscribe",
|
"unsubscribe": "!unsubscribe",
|
||||||
"subscribersList": "!sublist",
|
|
||||||
"help": "!help"
|
"help": "!help"
|
||||||
},
|
},
|
||||||
"developerCommands": {
|
"developerCommands": {
|
||||||
"logUpload": "!logsplease",
|
"logUpload": "!logsplease",
|
||||||
"cacheList": "!cacheList"
|
"cacheList": "!cacheList"
|
||||||
},
|
},
|
||||||
"developers":[
|
"developers": [
|
||||||
"117966411548196870"
|
"117966411548196870"
|
||||||
]
|
]
|
||||||
}
|
}
|
76
feed-bot.js
76
feed-bot.js
|
@ -106,29 +106,19 @@ var DiscordClient = {
|
||||||
//send a messsage containing the new feed link to our discord channel
|
//send a messsage containing the new feed link to our discord channel
|
||||||
DiscordClient.bot.sendMessage({
|
DiscordClient.bot.sendMessage({
|
||||||
to: Config.channelID,
|
to: Config.channelID,
|
||||||
message: "<@" + Subscriptions.subscribers.join("> <@") + ">" + link
|
message: Subscriptions.mention() + link
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
//actions to perform when certain messages are detected, along with channel or user requirements
|
//actions to perform when certain messages are detected, along with channel or user requirements
|
||||||
messageTriggers: [
|
messageTriggers: [
|
||||||
{
|
{
|
||||||
message: Config.userCommands.subscribe,
|
message: Config.userCommands.subscribe,
|
||||||
action: (user, userID, channelID, message) => { Subscriptions.subscribe(user, userID, channelID, message); },
|
action: (user, userID, channelID, message) => { if (Config.allowSubscriptions) Subscriptions.subscribe(user, userID, channelID, message); },
|
||||||
channelID: Config.channelID
|
channelID: Config.channelID
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: Config.userCommands.unsubscribe,
|
message: Config.userCommands.unsubscribe,
|
||||||
action: (user, userID, channelID, message) => { Subscriptions.unsubscribe(user, userID, channelID, message); },
|
action: (user, userID, channelID, message) => { if (Config.allowSubscriptions) Subscriptions.unsubscribe(user, userID, channelID, message); },
|
||||||
channelID: Config.channelID
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: Config.userCommands.subscribersList,
|
|
||||||
action: (user, userID, channelID, message) => {
|
|
||||||
DiscordClient.bot.sendMessage({
|
|
||||||
to: Config.channelID,
|
|
||||||
message: DiscordClient.bot.fixMessage("<@" + Subscriptions.subscribers.join("> <@") + ">")
|
|
||||||
}, (err, response) => { setTimeout(() => { DiscordClient.bot.deleteMessage({ channelID: channelID, messageID: response.id }); }, Config.messageDeleteDelay); });
|
|
||||||
},
|
|
||||||
channelID: Config.channelID
|
channelID: Config.channelID
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -165,39 +155,44 @@ var DiscordClient = {
|
||||||
};
|
};
|
||||||
|
|
||||||
var Subscriptions = {
|
var Subscriptions = {
|
||||||
subscribers: [],
|
|
||||||
parse: function () {
|
|
||||||
JsonFile.readFile(Config.subscribersFile, (err, obj) => {
|
|
||||||
if (err) Log.error("Unable to parse json subscribers file", err);
|
|
||||||
this.subscribers = obj || [];
|
|
||||||
});
|
|
||||||
},
|
|
||||||
subscribe: function (user, userID, channelID, message) {
|
subscribe: function (user, userID, channelID, message) {
|
||||||
if (this.subscribers.indexOf(userID) === -1) {
|
DiscordClient.bot.addToRole({
|
||||||
this.subscribers.push(userID); //subscribe the user if they aren't already subscribed
|
serverID: Config.serverID,
|
||||||
this.writeToFile();
|
userID: userID,
|
||||||
Log.event("Subscribed user " + (user ? user + "(" + userID + ")" : userID));
|
roleID: Config.subscribersRoleID
|
||||||
|
}, (err, response) => {
|
||||||
|
if (err) Log.raw(err);
|
||||||
|
Log.info(response);
|
||||||
|
});
|
||||||
|
|
||||||
DiscordClient.bot.sendMessage({
|
Log.event("Subscribed user " + (user ? user + "(" + userID + ")" : userID));
|
||||||
to: channelID,
|
|
||||||
message: "You have successfully subscribed"
|
DiscordClient.bot.sendMessage({
|
||||||
}, (err, response) => { setTimeout(() => { DiscordClient.bot.deleteMessage({ channelID: channelID, messageID: response.id }); }, Config.messageDeleteDelay); });
|
to: channelID,
|
||||||
}
|
message: "You have successfully subscribed"
|
||||||
|
}, (err, response) => { setTimeout(() => { DiscordClient.bot.deleteMessage({ channelID: channelID, messageID: response.id }); }, Config.messageDeleteDelay); }); //delete the subscription confirmation message after a delay
|
||||||
},
|
},
|
||||||
|
|
||||||
unsubscribe: function (user, userID, channelID, message) {
|
unsubscribe: function (user, userID, channelID, message) {
|
||||||
if (this.subscribers.indexOf(userID) > -1) {
|
DiscordClient.bot.removeFromRole({
|
||||||
this.subscribers.splice(this.subscribers.indexOf(userID), 1);
|
serverID: Config.serverID,
|
||||||
this.writeToFile();
|
userID: userID,
|
||||||
Log.event("Unsubscribed user " + (user ? user + "(" + userID + ")" : userID));
|
roleID: Config.subscribersRoleID
|
||||||
|
}, (err, response) => {
|
||||||
|
if (err) Log.raw(err);
|
||||||
|
Log.info(response);
|
||||||
|
});
|
||||||
|
|
||||||
DiscordClient.bot.sendMessage({
|
Log.event("Unsubscribed user " + (user ? user + "(" + userID + ")" : userID));
|
||||||
to: channelID,
|
|
||||||
message: "You have successfully unsubscribed"
|
DiscordClient.bot.sendMessage({
|
||||||
}, (err, response) => { setTimeout(() => { DiscordClient.bot.deleteMessage({ channelID: channelID, messageID: response.id }); }, Config.messageDeleteDelay); });
|
to: channelID,
|
||||||
}
|
message: "You have successfully unsubscribed"
|
||||||
|
}, (err, response) => { setTimeout(() => { DiscordClient.bot.deleteMessage({ channelID: channelID, messageID: response.id }); }, Config.messageDeleteDelay); }); //delete the un-subscription confirmation message after a delay
|
||||||
},
|
},
|
||||||
writeToFile: function () {
|
|
||||||
JsonFile.writeFile(Config.subscribersFile, this.subscribers, (err) => { if (err) Log.error("Unable to write subscribers to json file", err); });
|
mention: function () {
|
||||||
|
return "<@&" + Config.subscribersRoleID + "> ";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -290,7 +285,6 @@ var intervalFunc = () => { }; //do nothing by default
|
||||||
|
|
||||||
//IIFE to kickstart the bot when the app loads
|
//IIFE to kickstart the bot when the app loads
|
||||||
(function () {
|
(function () {
|
||||||
Subscriptions.parse();
|
|
||||||
DiscordClient.startup();
|
DiscordClient.startup();
|
||||||
setInterval(() => { intervalFunc(); }, Config.pollingInterval);
|
setInterval(() => { intervalFunc(); }, Config.pollingInterval);
|
||||||
})();
|
})();
|
7
log.js
7
log.js
|
@ -20,6 +20,10 @@ function log(message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logRaw(obj) {
|
||||||
|
Console.log(obj);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
info: function (message) {
|
info: function (message) {
|
||||||
if (message)
|
if (message)
|
||||||
|
@ -36,5 +40,8 @@ module.exports = {
|
||||||
//log the message, attach innerEx information if it was passed
|
//log the message, attach innerEx information if it was passed
|
||||||
log("[ERROR] " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : ""));
|
log("[ERROR] " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : ""));
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
raw: function (obj) {
|
||||||
|
if (obj) logRaw(obj);
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in a new issue