-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.js
81 lines (73 loc) · 2.58 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const { EmbedBuilder, WebhookClient, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');
const { webhookId, webhookToken } = require('./webhook-config.json');
const webhookClient = new WebhookClient({ id: webhookId, token: webhookToken });
const http = require('http');
let host = 'http://localhost:3000';
require('dotenv').config();
let tiktokUsername = process.env.tiktokUsername;
let url_roominfo = host + '/roominfo?tiktokUsername=' + tiktokUsername;
let link = 'https://www.tiktok.com/' + tiktokUsername + '/live';
http.get(url_roominfo,(res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
let json = JSON.parse(body);
// do something with JSON
// console.log(json);
const embed = new EmbedBuilder(
{
color: 0xFF2BF2,
title: json.title,
url: link,
author: {
name: json.owner.nickname + ' is now live on Tiktok!',
icon_url: json.cover.url_list[0],
url: link,
},
fields: [
{
name: 'Game',
value: json.game_tag[0]['show_name'],
inline: true,
},
{
name: 'View',
value: json.user_count,
inline: true,
},
],
image: {
url: '',
},
timestamp: new Date().toISOString(),
footer: {
text: '',
icon_url: '',
},
}
);
const button = new ButtonBuilder(
{
type: 2,
style: ButtonStyle.Link,
label: 'Watch Stream',
url: json.share_url,
}
);
const row = new ActionRowBuilder()
.addComponents(button)
webhookClient.send({
content: '@everyone ' + json.owner.nickname + ' is live now🔴',
components: [row],
embeds: [embed],
});
} catch (error) {
console.error(error.message);
};
});
}).on("error", (error) => {
console.error(error.message);
});