Browse Source

Added ability to request a list of subscribed users in chat

shorten
benji7425 4 years ago
parent
commit
d54767eb1b
  1. 1
      config.json
  2. 38
      feed-bot.js

1
config.json

@ -7,6 +7,7 @@
"logRequestMessage": "!logsplease",
"subscribeRequestMessage": "!subscribe",
"unsubscribeRequestMessage": "!unsubscribe",
"subscribersListRequestMessage": "!sublist",
"logFile": "./log",
"subscribersFile": "./subscribers.json"
}

38
feed-bot.js

@ -63,22 +63,28 @@ var DiscordClient = {
else {
switch (message) {
case Config.subscribeRequestMessage:
Subscriptions.subscribe(userID, user);
Subscriptions.subscribe(channelID, userID, user);
break;
case Config.unsubscribeRequestMessage:
Subscriptions.unsubscribe(userID, user);
Subscriptions.unsubscribe(channelID, userID, user);
break;
case Config.logRequestMessage:
DiscordClient.bot.uploadFile({
to: channelID,
file: Config.logFile
}, (err, message) => {
if (err) Log.error("Failed to upload log file: " + message, err);
else Log.event("Uploaded log file for user " + user + "(" + userID + ")");
case Config.subscribersListRequestMessage:
DiscordClient.bot.sendMessage({
to: Config.channelID,
message: DiscordClient.bot.fixMessage("<@" + Subscriptions.subscribers.join("> <@") + ">")
});
}
}
}
else if (message === Config.logRequestMessage) {
DiscordClient.bot.uploadFile({
to: channelID,
file: Config.logFile
}, (err, message) => {
if (err) Log.error("Failed to upload log file: " + message, err);
else Log.event("Uploaded log file for user " + user + "(" + userID + ")");
});
}
},
checkPastMessagesForLinks: function () {
var limit = 100;
@ -135,18 +141,28 @@ var Subscriptions = {
this.subscribers = obj || [];
});
},
subscribe: function (userID, user) {
subscribe: function (channelID, userID, user) {
if (this.subscribers.indexOf(userID) === -1) {
this.subscribers.push(userID); //subscribe the user if they aren't already subscribed
this.writeToFile();
Log.event("Subscribed user " + (user ? user + "(" + userID + ")" : userID));
DiscordClient.bot.sendMessage({
to: channelID,
message: "You have successfully subscribed"
});
}
},
unsubscribe: function (userID, user) {
unsubscribe: function (channelID, userID, user) {
if (this.subscribers.indexOf(userID) > -1) {
this.subscribers.splice(this.subscribers.indexOf(userID));
this.writeToFile();
Log.event("Unsubscribed user " + (user ? user + "(" + userID + ")" : userID));
DiscordClient.bot.sendMessage({
to: channelID,
message: "You have successfully unsubscribed"
});
}
},
writeToFile: function () {

Loading…
Cancel
Save