-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(alert): the ability to send to discord webhook url
- Loading branch information
Showing
13 changed files
with
154 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.alertToDiscord = void 0; | ||
const format_custom_date_1 = require("./format-custom-date"); | ||
const axios_1 = __importDefault(require("axios")); | ||
const db_1 = require("../database/db"); | ||
async function alertToDiscord(fromIpAddress, toIpAddress) { | ||
const configuration = await db_1.db.configuration.findFirst(); | ||
if (!configuration) { | ||
console.error('no configuration found'); | ||
return false; | ||
} | ||
if (!configuration.discord_webhook_url) { | ||
console.error('no discord webhook url found'); | ||
return false; | ||
} | ||
const embeds = [ | ||
{ | ||
title: '', | ||
color: 5174599, | ||
footer: { | ||
text: `📅 ${(0, format_custom_date_1.formatCustomDate)(new Date())}`, | ||
}, | ||
fields: [ | ||
{ | ||
name: 'CDNS Update!', | ||
value: `You're ip address has been updated from ${fromIpAddress} to ${toIpAddress}!`, | ||
}, | ||
], | ||
}, | ||
]; | ||
const data = JSON.stringify({ embeds }); | ||
const headers = { 'Content-Type': 'application/json' }; | ||
try { | ||
await axios_1.default.post(configuration.discord_webhook_url, data, { headers }); | ||
} | ||
catch (error) { | ||
// @ts-ignore | ||
console.error(error?.response?.data?.message); | ||
return false; | ||
} | ||
return true; | ||
} | ||
exports.alertToDiscord = alertToDiscord; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatCustomDate = void 0; | ||
function formatCustomDate(date) { | ||
const options = { | ||
year: 'numeric', | ||
month: '2-digit', | ||
day: '2-digit', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
second: '2-digit', | ||
hour12: true, | ||
timeZoneName: 'short', | ||
}; | ||
const formattedDate = date.toLocaleString('en-US', options); | ||
return formattedDate; | ||
} | ||
exports.formatCustomDate = formatCustomDate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.timeToCron = exports.getIPAddress = exports.CloudflareApiClient = void 0; | ||
exports.alertToDiscord = exports.formatCustomDate = exports.timeToCron = exports.getIPAddress = exports.CloudflareApiClient = void 0; | ||
var cloudflare_api_client_1 = require("./cloudflare-api-client"); | ||
Object.defineProperty(exports, "CloudflareApiClient", { enumerable: true, get: function () { return cloudflare_api_client_1.CloudflareApiClient; } }); | ||
var get_ip_address_1 = require("./get-ip-address"); | ||
Object.defineProperty(exports, "getIPAddress", { enumerable: true, get: function () { return get_ip_address_1.getIPAddress; } }); | ||
var time_to_cron_1 = require("./time-to-cron"); | ||
Object.defineProperty(exports, "timeToCron", { enumerable: true, get: function () { return time_to_cron_1.timeToCron; } }); | ||
var format_custom_date_1 = require("./format-custom-date"); | ||
Object.defineProperty(exports, "formatCustomDate", { enumerable: true, get: function () { return format_custom_date_1.formatCustomDate; } }); | ||
var alert_to_discord_1 = require("./alert-to-discord"); | ||
Object.defineProperty(exports, "alertToDiscord", { enumerable: true, get: function () { return alert_to_discord_1.alertToDiscord; } }); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { CloudflareApi, ZoneInfo, CloudflareApiClient } from './cloudflare-api-client'; | ||
export { getIPAddress } from './get-ip-address'; | ||
export { timeToCron } from './time-to-cron'; | ||
export { formatCustomDate } from './format-custom-date'; | ||
export { alertToDiscord } from './alert-to-discord'; |