diff --git a/package.json b/package.json index a154d6c..faa6b61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "microsoft-rewards-script", - "version": "1.0.1", + "version": "1.0.2", "description": "Automatically do tasks for Microsoft Rewards but in TS", "main": "index.js", "scripts": { diff --git a/src/config.json b/src/config.json index ecbb7a7..0c8f4a6 100644 --- a/src/config.json +++ b/src/config.json @@ -6,5 +6,9 @@ "searches": { "doMobile": true, "doDesktop": true + }, + "webhook": { + "enabled": true, + "url": "" } } \ No newline at end of file diff --git a/src/util/Logger.ts b/src/util/Logger.ts index 347c7dc..3d518e2 100644 --- a/src/util/Logger.ts +++ b/src/util/Logger.ts @@ -1,18 +1,26 @@ +import { Webhook } from './Webhook' + export function log(title: string, message: string, type?: 'log' | 'warn' | 'error') { const currentTime = new Date().toISOString() + let str = '' + switch (type) { case 'warn': - console.warn(`[${currentTime}] [WARN] [${title}] ${message}`) + str = `[${currentTime}] [WARN] [${title}] ${message}` + console.warn(str) break case 'error': - console.error(`[${currentTime}] [ERROR] [${title}] ${message}`) + str = `[${currentTime}] [ERROR] [${title}] ${message}` + console.error(str) break default: - console.log(`[${currentTime}] [LOG] [${title}] ${message}`) + str = `[${currentTime}] [LOG] [${title}] ${message}` + console.log(str) break } + if (str) Webhook(str) } \ No newline at end of file diff --git a/src/util/Webhook.ts b/src/util/Webhook.ts new file mode 100644 index 0000000..b1a4125 --- /dev/null +++ b/src/util/Webhook.ts @@ -0,0 +1,21 @@ +import axios from 'axios' + +import { webhook } from '../config.json' + +export async function Webhook(content: string) { + if (!webhook.enabled) return + if (webhook.url.length < 10) return + + const request = { + method: 'POST', + url: webhook.url, + headers: { + 'Content-Type': 'application/json' + }, + data: { + 'content': content + } + } + + await axios(request).catch(() => { }) +} \ No newline at end of file