Merge remote-tracking branch 'theguydanish/master'
# Conflicts: # package-lock.json # package.json
This commit is contained in:
		
						commit
						900219deb1
					
				
					 4 changed files with 42 additions and 94 deletions
				
			
		|  | @ -15,7 +15,6 @@ | |||
|         "axios": "0.21.1", | ||||
|         "bootstrap": "5.0.2", | ||||
|         "dayjs": "1.10.6", | ||||
|         "discord.js": "12.5.3", | ||||
|         "express": "4.17.1", | ||||
|         "form-data": "4.0.0", | ||||
|         "jsonwebtoken": "8.5.1", | ||||
|  |  | |||
|  | @ -2,7 +2,6 @@ const axios = require("axios"); | |||
| const {R} = require("redbean-node"); | ||||
| const FormData = require('form-data'); | ||||
| const nodemailer = require("nodemailer"); | ||||
| const Discord = require('discord.js'); | ||||
| 
 | ||||
| class Notification { | ||||
|     static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { | ||||
|  | @ -54,8 +53,45 @@ class Notification { | |||
|             return await Notification.smtp(notification, msg) | ||||
| 
 | ||||
|         } else if (notification.type === "discord") { | ||||
|             return await Notification.discord(notification, msg) | ||||
| 
 | ||||
|             try { | ||||
|               // If heartbeatJSON is null, assume we're testing.
 | ||||
|               if(heartbeatJSON == null) { | ||||
|                 let data = { | ||||
|                   username: 'Uptime-Kuma', | ||||
|                   content: msg | ||||
|                 } | ||||
|                 let res = await axios.post(notification.discordWebhookUrl, data) | ||||
|                 return true; | ||||
|               } | ||||
|               // If heartbeatJSON is not null, we go into the normal alerting loop.
 | ||||
|               if(heartbeatJSON['status'] == 0) { | ||||
|                 var alertColor = "16711680"; | ||||
|               } else if(heartbeatJSON['status'] == 1) { | ||||
|                 var alertColor = "65280"; | ||||
|               } | ||||
|               let data = { | ||||
|                 username: 'Uptime-Kuma', | ||||
|                 embeds: [{ | ||||
|                   title: "Uptime-Kuma Alert", | ||||
|                   color: alertColor, | ||||
|                   fields: [ | ||||
|                     { | ||||
|                       name: "Time (UTC)", | ||||
|                       value: heartbeatJSON["time"] | ||||
|                     }, | ||||
|                     { | ||||
|                       name: "Message", | ||||
|                       value: msg | ||||
|                     } | ||||
|                   ] | ||||
|                 }] | ||||
|               } | ||||
|               let res = await axios.post(notification.discordWebhookUrl, data) | ||||
|               return true; | ||||
|             } catch(error) { | ||||
|               console.log(error) | ||||
|               return false; | ||||
|             } | ||||
|         } else { | ||||
|             throw new Error("Notification type is not supported") | ||||
|         } | ||||
|  | @ -119,18 +155,6 @@ class Notification { | |||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     static async discord(notification, msg) { | ||||
|         const client = new Discord.Client(); | ||||
|         await client.login(notification.discordToken) | ||||
| 
 | ||||
|         const channel = await client.channels.fetch(notification.discordChannelID); | ||||
|         await channel.send(msg); | ||||
| 
 | ||||
|         client.destroy() | ||||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| module.exports = { | ||||
|  |  | |||
|  | @ -127,19 +127,9 @@ | |||
| 
 | ||||
|                         <template v-if="notification.type === 'discord'"> | ||||
|                             <div class="mb-3"> | ||||
|                                 <label for="discord-token" class="form-label">Discord Bot Token</label> | ||||
|                                 <input type="text" class="form-control" id="discord-token" required v-model="notification.discordToken" autocomplete="false"> | ||||
|                                 <div class="form-text">You should create a Discord app and create a bot from <a href="https://discord.com/developers/applications" target="_blank">here</a>.</div> | ||||
|                             </div> | ||||
| 
 | ||||
|                             <div class="mb-3"> | ||||
|                                 <label for="discordChannelID" class="form-label">Channel ID</label> | ||||
|                                 <input type="text" class="form-control" id="discordChannelID" required v-model="notification.discordChannelID" autocomplete="false"> | ||||
|                                 <div class="form-text"> | ||||
|                                     You should add the bot to your channel. <br /> | ||||
|                                     <a href="https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-" target="_blank">Where can I find the channel id?</a><br /> | ||||
|                                     <a href="https://discordapi.com/permissions.html#8" target="_blank">How to add a bot to your channel?</a> | ||||
|                                 </div> | ||||
|                                 <label for="discord-webhook-url" class="form-label">Discord Webhook URL</label> | ||||
|                                 <input type="text" class="form-control" id="discord-webhook-url" required v-model="notification.discordWebhookUrl" autocomplete="false"> | ||||
|                                 <div class="form-text">You can get this by going to Server Settings -> Integrations -> Create Webhook</div> | ||||
|                             </div> | ||||
|                         </template> | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										65
									
								
								yarn.lock
									
									
									
									
									
								
							
							
						
						
									
										65
									
								
								yarn.lock
									
									
									
									
									
								
							|  | @ -25,20 +25,6 @@ | |||
|     "@babel/helper-validator-identifier" "^7.14.5" | ||||
|     to-fast-properties "^2.0.0" | ||||
| 
 | ||||
| "@discordjs/collection@^0.1.6": | ||||
|   version "0.1.6" | ||||
|   resolved "https://registry.yarnpkg.com/@discordjs/collection/-/collection-0.1.6.tgz#9e9a7637f4e4e0688fd8b2b5c63133c91607682c" | ||||
|   integrity sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ== | ||||
| 
 | ||||
| "@discordjs/form-data@^3.0.1": | ||||
|   version "3.0.1" | ||||
|   resolved "https://registry.yarnpkg.com/@discordjs/form-data/-/form-data-3.0.1.tgz#5c9e6be992e2e57d0dfa0e39979a850225fb4697" | ||||
|   integrity sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg== | ||||
|   dependencies: | ||||
|     asynckit "^0.4.0" | ||||
|     combined-stream "^1.0.8" | ||||
|     mime-types "^2.1.12" | ||||
| 
 | ||||
| "@popperjs/core@2.9.2": | ||||
|   version "2.9.2" | ||||
|   resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.9.2.tgz#adea7b6953cbb34651766b0548468e743c6a2353" | ||||
|  | @ -203,13 +189,6 @@ abbrev@1: | |||
|   resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" | ||||
|   integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== | ||||
| 
 | ||||
| abort-controller@^3.0.0: | ||||
|   version "3.0.0" | ||||
|   resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" | ||||
|   integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== | ||||
|   dependencies: | ||||
|     event-target-shim "^5.0.0" | ||||
| 
 | ||||
| accepts@~1.3.4, accepts@~1.3.7: | ||||
|   version "1.3.7" | ||||
|   resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd" | ||||
|  | @ -746,20 +725,6 @@ detect-libc@^1.0.2: | |||
|   resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" | ||||
|   integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= | ||||
| 
 | ||||
| discord.js@12.5.3: | ||||
|   version "12.5.3" | ||||
|   resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-12.5.3.tgz#56820d473c24320871df9ea0bbc6b462f21cf85c" | ||||
|   integrity sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw== | ||||
|   dependencies: | ||||
|     "@discordjs/collection" "^0.1.6" | ||||
|     "@discordjs/form-data" "^3.0.1" | ||||
|     abort-controller "^3.0.0" | ||||
|     node-fetch "^2.6.1" | ||||
|     prism-media "^1.2.9" | ||||
|     setimmediate "^1.0.5" | ||||
|     tweetnacl "^1.0.3" | ||||
|     ws "^7.4.4" | ||||
| 
 | ||||
| ecc-jsbn@~0.1.1: | ||||
|   version "0.1.2" | ||||
|   resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9" | ||||
|  | @ -850,11 +815,6 @@ etag@~1.8.1: | |||
|   resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" | ||||
|   integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc= | ||||
| 
 | ||||
| event-target-shim@^5.0.0: | ||||
|   version "5.0.1" | ||||
|   resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" | ||||
|   integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== | ||||
| 
 | ||||
| expand-brackets@^2.1.4: | ||||
|   version "2.1.4" | ||||
|   resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-2.1.4.tgz#b77735e315ce30f6b6eff0f83b04151a22449622" | ||||
|  | @ -1916,11 +1876,6 @@ node-addon-api@^3.0.0: | |||
|   resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" | ||||
|   integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== | ||||
| 
 | ||||
| node-fetch@^2.6.1: | ||||
|   version "2.6.1" | ||||
|   resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" | ||||
|   integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== | ||||
| 
 | ||||
| node-gyp@3.x: | ||||
|   version "3.8.0" | ||||
|   resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.8.0.tgz#540304261c330e80d0d5edce253a68cb3964218c" | ||||
|  | @ -2249,11 +2204,6 @@ postcss@^8.1.10, postcss@^8.3.5: | |||
|     nanoid "^3.1.23" | ||||
|     source-map-js "^0.6.2" | ||||
| 
 | ||||
| prism-media@^1.2.9: | ||||
|   version "1.3.1" | ||||
|   resolved "https://registry.yarnpkg.com/prism-media/-/prism-media-1.3.1.tgz#418acd2b122bedea2e834056d678f9a5ad2943ae" | ||||
|   integrity sha512-nyYAa3KB4qteJIqdguKmwxTJgy55xxUtkJ3uRnOvO5jO+frci+9zpRXw6QZVcfDeva3S654fU9+26P2OSTzjHw== | ||||
| 
 | ||||
| process-nextick-args@~2.0.0: | ||||
|   version "2.0.1" | ||||
|   resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" | ||||
|  | @ -2529,11 +2479,6 @@ set-value@^2.0.0, set-value@^2.0.1: | |||
|     is-plain-object "^2.0.3" | ||||
|     split-string "^3.0.1" | ||||
| 
 | ||||
| setimmediate@^1.0.5: | ||||
|   version "1.0.5" | ||||
|   resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285" | ||||
|   integrity sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU= | ||||
| 
 | ||||
| setprototypeof@1.1.1: | ||||
|   version "1.1.1" | ||||
|   resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683" | ||||
|  | @ -2854,11 +2799,6 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: | |||
|   resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" | ||||
|   integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= | ||||
| 
 | ||||
| tweetnacl@^1.0.3: | ||||
|   version "1.0.3" | ||||
|   resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" | ||||
|   integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== | ||||
| 
 | ||||
| type-is@~1.6.17, type-is@~1.6.18: | ||||
|   version "1.6.18" | ||||
|   resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" | ||||
|  | @ -3005,11 +2945,6 @@ wrappy@1: | |||
|   resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" | ||||
|   integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= | ||||
| 
 | ||||
| ws@^7.4.4: | ||||
|   version "7.5.3" | ||||
|   resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.3.tgz#160835b63c7d97bfab418fc1b8a9fced2ac01a74" | ||||
|   integrity sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg== | ||||
| 
 | ||||
| ws@~7.4.2: | ||||
|   version "7.4.6" | ||||
|   resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c" | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue