-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.js
38 lines (35 loc) · 861 Bytes
/
webhook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Overheard from '../dist'
const { WEBHOOK_URL } = process.env
/**
* Send Discord webhook
* @param {string} title
* @param {string} description
* @returns {Promise<void>}
*/
const send = async (title, description) => {
const res = await fetch(WEBHOOK_URL, {
method: 'POST',
body: {
content: 'Example Discord Embed.',
embed: {
title,
description,
timestamp: new Date().toString(),
color: 6486117,
},
},
})
if (!res.ok) {
throw new Error(`[${res.status}] ${res.statusText}`)
}
}
// Main
;(() => {
const overheard = new Overheard().start()
overheard.addEventListener('error', (event) => {
console.error(event.error)
})
overheard.addEventListener('realm', async (event) => {
await send(`Hello Title! ${event.name} ${event.phase}`, 'Embed Description')
})
})()