-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
105 lines (95 loc) · 3.76 KB
/
main.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*--------------------------------------------------------------------------------------\
| _______ _ _____ _ _ _ ________ ___ ___ ___ __ |
| |__ __| (_) / ____| | | (_) / ____ \ |__ \ / _ \__ \/_ | |
| | | __ _ _ | (___ | |_ _ _ __| |_ ___ / / ___| \ ) | | | | ) || | |
| | |/ _` | | \___ \| __| | | |/ _` | |/ _ \ | | | | / /| | | |/ / | | |
| | | (_| | | ____) | |_| |_| | (_| | | (_) | | | |___ | / /_| |_| / /_ | | |
| |_|\__,_|_| |_____/ \__|\__,_|\__,_|_|\___/ \ \____| / |____|\___/____||_| |
| \________/ |
\--------------------------------------------------------------------------------------*/
const request = require('request');
var repo = process.env.GITHUB_REPOSITORY || "LeGitHubDeTai/github-to-discord",
webhook = process.env.DISCORD_WEBHOOK || null,
username = process.env.DISCORD_USERNAME || "Tai Studio Bot",
avatar_url = process.env.DISCORD_AVATAR || "https://raw.githubusercontent.com/LeGitHubDeTai/github-to-discord/main/icon.png",
content = process.env.CONTENT || null,
title = process.env.MESSAGE_TITLE || "New Version",
description = process.env.MESSAGE_DESCRIPTION || "Tai Studio",
url = process.env.MESSAGE_URL || `https://github.com/${repo}`,
color = process.env.MESSAGE_COLOR || 5814783,
section_name = process.env.SECTION_NAME || "ChangeLog",
author_name = process.env.AUTHOR_NAME || "Tai Studio",
author_url = process.env.AUTHOR_URL || "https://tai-studio.netlify.app/",
author_avatar = process.env.AUTHOR_AVATAR || "https://tai-studio.netlify.app/img/logo/Tai_Studio.png",
footer_text = process.env.FOOTER_TEXT || "- Tai Studio © 2022 -",
footer_url = process.env.FOOTER_URL || "https://tai-studio.netlify.app/img/logo/Tai_Studio.png",
image = process.env.IMAGE || null;
var getRepo = {
url: `https://api.github.com/repos/${repo}/releases/latest`,
headers: {
'User-Agent': 'request'
}
}
request.get(getRepo, function(err, response, body){
var tag_name = "";
var bodyJson = JSON.parse(response['body']);
if(bodyJson.tag_name != null){
tag_name = bodyJson.tag_name;
}
var embed =
{
"title": `${title} ${tag_name}`,
"description": `${description}`,
"url": `${url}`,
"color": `${color}`,
"fields": [
{
"name": `${section_name}`,
"value": `${name(JSON.parse(response['body']).body, '##', '')}`
}
],
"author": {
"name": `${author_name}`,
"url": `${author_url}`,
"icon_url": `${author_avatar}`
},
"footer": {
"text": `${footer_text}`,
"icon_url": `${footer_url}`
},
"thumbnail": {
"url": `https://raw.githubusercontent.com/${repo}/icon.png`
}
},
bodyE = {
"username": `${username}`,
"avatar_url": `${avatar_url}`
};
if(content != null){
bodyE.content = content;
}
if(image != null){
embed.image = {"url": `${image}`}
}
bodyE.embeds = [embed];
var options = {
url: `${webhook}`,
headers: {
'Content-Type': 'application/json',
'User-Agent': 'request'
},
body: JSON.stringify(bodyE)
};
console.log(options);
request.post(options, function (error, response, body) {
if(error) console.log(error);
console.log(body);
})
})
function name(str,replaceWhat,replaceTo){
if(replaceWhat != null){
replaceWhat = replaceWhat.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
var re = new RegExp(replaceWhat, 'g');
return str.replace(re,replaceTo);
}
}