This commit is contained in:
TheNetsky
2023-09-26 15:55:37 +02:00
parent 2291245657
commit d6691da3b9
4 changed files with 37 additions and 4 deletions

View File

@@ -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": {

View File

@@ -6,5 +6,9 @@
"searches": {
"doMobile": true,
"doDesktop": true
},
"webhook": {
"enabled": true,
"url": ""
}
}

View File

@@ -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)
}

21
src/util/Webhook.ts Normal file
View File

@@ -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(() => { })
}