Added tagging of subscribed users when link posted
This commit is contained in:
parent
8cdca1f616
commit
650a891cbb
14
feed-bot.js
14
feed-bot.js
|
@ -106,10 +106,14 @@ var DiscordClient = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
post: function (link) {
|
post: function (link) {
|
||||||
|
var tags = "";
|
||||||
|
for (var userID in Subscriptions.subscribers)
|
||||||
|
tags += "<@" + Subscriptions.subscribers[userID] + "> ";
|
||||||
|
|
||||||
//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: link
|
message: tags + link
|
||||||
}, function (err, message) {
|
}, function (err, message) {
|
||||||
if (err) {
|
if (err) {
|
||||||
Log.error("ERROR: Failed to send message: " + message.substring(0, 15) + "...", err);
|
Log.error("ERROR: Failed to send message: " + message.substring(0, 15) + "...", err);
|
||||||
|
@ -122,20 +126,20 @@ var DiscordClient = {
|
||||||
|
|
||||||
var Subscriptions = {
|
var Subscriptions = {
|
||||||
subscribers: [],
|
subscribers: [],
|
||||||
parse: function(){
|
parse: function () {
|
||||||
JsonFile.readFile("./subscribers.json", (err, obj) => {
|
JsonFile.readFile("./subscribers.json", (err, obj) => {
|
||||||
if(err) Log.error("Unable to parse json subscribers file", err);
|
if (err) Log.error("Unable to parse json subscribers file", err);
|
||||||
this.subscribers = obj || [];
|
this.subscribers = obj || [];
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
subscribe: function (userID, user) {
|
subscribe: function (userID, user) {
|
||||||
this.subscribers.push(userID);
|
this.subscribers.push(userID);
|
||||||
JsonFile.writeFile("./subscribers.json", this.subscribers, (err) => { if(err) Log.error("Unable to write subscribers to json file", err); });
|
JsonFile.writeFile("./subscribers.json", this.subscribers, (err) => { if (err) Log.error("Unable to write subscribers to json file", err); });
|
||||||
Log.event("Subscribed user " + (user ? user + "(" + userID + ")" : userID));
|
Log.event("Subscribed user " + (user ? user + "(" + userID + ")" : userID));
|
||||||
},
|
},
|
||||||
unsubscribe: function (userID, user) {
|
unsubscribe: function (userID, user) {
|
||||||
this.subscribers.splice(this.subscribers.indexOf(userID));
|
this.subscribers.splice(this.subscribers.indexOf(userID));
|
||||||
JsonFile.writeFile("./subscribers.json", this.subscribers, (err) => { if(err) Log.error("Unable to write subscribers to json file", err); });
|
JsonFile.writeFile("./subscribers.json", this.subscribers, (err) => { if (err) Log.error("Unable to write subscribers to json file", err); });
|
||||||
Log.event("Unsubscribed user " + (user ? user + "(" + userID + ")" : userID));
|
Log.event("Unsubscribed user " + (user ? user + "(" + userID + ")" : userID));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue