From 6d3cbf645fdb2bbca21889bcd1803a63a2faa526 Mon Sep 17 00:00:00 2001
From: Cristiano Pires <cpires@labsxd.com>
Date: Thu, 31 Aug 2023 18:17:25 +0100
Subject: [PATCH] notification engine setup

---
 server.js | 29 +++++++++++++++++++++++------
 test.js   |  2 --
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/server.js b/server.js
index 5e7d885..becf5eb 100644
--- a/server.js
+++ b/server.js
@@ -50,22 +50,27 @@ const bot = new Client({ intents: [
       ]
 });
 var retryCounter = 0;
-(function login()
+function login()
 {
     bot.login(process.env.discord_token).catch(()=>
     {
-        if(retryCounter==900) return startLimitProtectionTimer();
+        console.log('Server: Falhou o login', retryCounter)
+        if(retryCounter>=900) return startLimitProtectionTimer();
         login();
         retryCounter++;
     });
-})()
+}
+login();
 function startLimitProtectionTimer()
 {
-    console.log('Server: Rate Limit Protection - Waiting before trying again.')
+    console.log('Server: Rate Limit Protection - Sending notification')
+    sendNotification('Server Rate Limit Protection - Something broke.');
     setTimeout(() => {
-        login();
         retryCounter = 0;
-    }, 60*60*1000);
+        console.log('Server: Rate Limit Protection Reset');
+        sendNotification('Nothing was fixed but it will try again.');
+        login();
+    }, 24*60*60*1000);
 }
 function connectToDB()
 {
@@ -198,4 +203,16 @@ function moveAFKs(){
 async function serversWithMusicOn()
 {
     return await GuildM.find({music:true}).then(g=>{return g})
+}
+
+async function sendNotification(message)
+{
+    fetch('https://ntfy.wordfights.com/RemChanv2',{
+        method: 'POST',
+            headers: {
+                'Content-Type': 'application/json',
+                'Accept': 'application/json', 
+            },
+            body: message
+    } )
 }
\ No newline at end of file
diff --git a/test.js b/test.js
index d148bc8..e69de29 100644
--- a/test.js
+++ b/test.js
@@ -1,2 +0,0 @@
-
-