Added reconnect timer
This commit is contained in:
parent
1763d7e068
commit
5d1d43fd56
|
@ -1,5 +1,10 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Reconnect timer to repeatedly try reconnect at intervals
|
||||||
|
|
||||||
## 1.1.0 pre
|
## 1.1.0 pre
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
17
feed-bot.js
17
feed-bot.js
|
@ -13,6 +13,7 @@ var Config = require("./config.json"); //config file containing other settings
|
||||||
var DiscordClient = {
|
var DiscordClient = {
|
||||||
bot: null,
|
bot: null,
|
||||||
feedTimer = null,
|
feedTimer = null,
|
||||||
|
reconnectTimer = null,
|
||||||
startup: function () {
|
startup: function () {
|
||||||
//check if we can connect to discordapp.com to authenticate the bot
|
//check if we can connect to discordapp.com to authenticate the bot
|
||||||
Dns.resolve("discordapp.com", function (err) {
|
Dns.resolve("discordapp.com", function (err) {
|
||||||
|
@ -41,13 +42,19 @@ var DiscordClient = {
|
||||||
DiscordClient.checkPastMessagesForLinks();
|
DiscordClient.checkPastMessagesForLinks();
|
||||||
},
|
},
|
||||||
onDisconnect: function (err, code) {
|
onDisconnect: function (err, code) {
|
||||||
//do a bunch of logging
|
Log.event("Bot was disconnected! " + err ? err : "" + code ? code : "No disconnect code provided", "Discord.io");;
|
||||||
Log.event("DiscordClient was disconnected! " + code ? code : "No disconnect code provided", "Discord.io");
|
|
||||||
if (err) Log.error("DiscordClient disconnected!", err);
|
|
||||||
Log.info("Trying to reconnect bot");
|
|
||||||
|
|
||||||
//then actually attempt to reconnect
|
clearInterval(DiscordClient.feedTimer); //stop the feed timer
|
||||||
|
|
||||||
|
//set up a timer to try reconnect every 5sec
|
||||||
|
DiscordClient.reconnectTimer = setInterval(function () {
|
||||||
|
try {
|
||||||
DiscordClient.bot.connect();
|
DiscordClient.bot.connect();
|
||||||
|
}
|
||||||
|
catch (ex) {
|
||||||
|
Log.error("Exception thrown trying to reconnect bot." + ex.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onMessage: function (user, userID, channelID, message) {
|
onMessage: function (user, userID, channelID, message) {
|
||||||
//check if the message contains a link, in the right channel, and not the latest link from the rss feed
|
//check if the message contains a link, in the right channel, and not the latest link from the rss feed
|
||||||
|
|
Loading…
Reference in a new issue