-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreportChanges.ts
213 lines (207 loc) · 5.77 KB
/
reportChanges.ts
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import { type Embed, post } from 'https://deno.land/x/dishooks@v1.1.0/mod.ts'
import config from './config.json' with { type: 'json' }
import { chunkArray, random } from './helpers.ts'
import type { change } from './video.ts'
import { getYouTubeArchives } from './archive.ts'
const botInfo = {
username: 'TTTakedown Tracker',
avatar:
'https://cdn.discordapp.com/attachments/1156660229472264232/1156756524572606556/logo.png',
github: 'https://github.com/jerbear2008/tttakedown-tracker',
}
const randomQuote = () =>
random([
'Bro be usin\' his dog',
'Bro has a bag',
'Goonin\' with the boys',
'Have you no shame?',
'I can\'t do this no more',
'Nah, that\'s the Joker. That\'s him.',
'NEXT TIKTOK',
'On the bus',
'Ooooooh nooooooooo',
'Pathetic, you can do better',
'That\'s a bowl full of sauce',
'That\'s gross',
'This is how they be makin\' the sidewalks',
'This just be the harsh reality',
'Well, if it isn\'t the consequences of my own actions',
'You see this big guy? He be eatin\' aaaall the little guys.',
'You\'re a liar!',
])
export async function reportChanges(changes: change[]) {
console.log(changes.map(change => `Change: ${change.type} in "${change.video.data.title}"`).join('\n'))
const embeds = await Promise.all(changes.map(getEmbed))
const promises: Promise<unknown>[] = []
for (const chunk of chunkArray(embeds, 10)) {
for (const webhook of config.reportingWebhooks) {
promises.push(post(webhook, {
username: botInfo.username,
avatar_url: botInfo.avatar,
embeds: chunk,
}))
}
}
await Promise.all(promises)
}
export async function getEmbed(change: change): Promise<Embed> {
const basicDetails = {
author: {
name: botInfo.username,
icon_url: botInfo.avatar,
url: botInfo.github,
},
footer: {
text: randomQuote(),
},
}
const archiveUrl = await getYouTubeArchives(change.video.data.id) ??
`https://archive.org/details/youtube-${change.video.data.id}`
switch (change.type) {
case 'newVideo':
return {
...basicDetails,
title: `New Video: "${change.video.data.title}"`,
url: change.video.url,
color: 2895153, // transparent, #2c2d31
fields: [
{
name: 'ID',
value: `\`${change.video.data.id}\``,
inline: true,
},
{
name: 'Length',
value: change.video.humanDuration,
inline: true,
},
{
name: 'Archive',
value: archiveUrl, // todo: improve
inline: true,
},
],
image: {
url: change.video.data.thumbnailURL,
},
}
case 'removedVideo':
return {
...basicDetails,
title: `Video Deleted: "${change.video.data.title}"`,
url: change.video.url,
color: 15614019, // discord red
fields: [
{
name: 'ID',
value: `\`${change.video.data.id}\``,
inline: true,
},
{
name: 'Length',
value: change.video.humanDuration,
inline: true,
},
{
name: 'Archive',
value: archiveUrl, // todo: improve
inline: true,
},
],
image: {
url: change.video.data.thumbnailURL,
},
}
case 'lengthChange':
return {
...basicDetails,
title: `${
Math.abs(change.video.data.duration - change.oldDuration)
} seconds ${
change.video.data.duration > change.oldDuration ? 'added' : 'removed'
}: "${change.video.data.title}"`,
url: change.video.url,
color: 15982188, // discord yellow
fields: [
{
name: 'ID',
value: `\`${change.video.data.id}\``,
inline: true,
},
{
name: 'Old Length',
value: change.oldHumanDuration,
inline: true,
},
{
name: 'New Length',
value: change.video.humanDuration,
inline: true,
},
{
name: 'Original Archive',
value: archiveUrl, // todo: improve
inline: true,
},
],
image: {
url: change.video.data.thumbnailURL,
},
}
case 'titleChange':
return {
...basicDetails,
title: `Title changed: "${change.video.data.title}"`,
description: `Old title: "${change.oldTitle}"`,
url: change.video.url,
color: 14242717, // discord fuchsia
fields: [
{
name: 'ID',
value: `\`${change.video.data.id}\``,
inline: true,
},
{
name: 'Length',
value: change.video.humanDuration,
inline: true,
},
{
name: 'Archive',
value: archiveUrl, // todo: improve
inline: true,
},
],
image: {
url: change.video.data.thumbnailURL,
},
}
case 'relistedVideo':
return {
...basicDetails,
title: `Video relisted: "${change.video.data.title}"`,
url: change.video.url,
color: 15982188, // discord yellow
fields: [
{
name: 'ID',
value: `\`${change.video.data.id}\``,
inline: true,
},
{
name: 'Length',
value: change.video.humanDuration,
inline: true,
},
{
name: 'Archive',
value: archiveUrl, // todo: improve
inline: true,
},
],
image: {
url: change.video.data.thumbnailURL,
},
}
}
}