Repository navigation
Expand file tree
/
Copy pathrun.js
More file actions
78 lines (60 loc) · 2.08 KB
/
Copy pathrun.js
File metadata and controls
78 lines (60 loc) · 2.08 KB
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
const { /*Client,*/ WebhookClient, MessageEmbed } = require('discord.js');
var http = require('http');
// const client = new Client();
const hook = {
web: new WebhookClient('XXXXXXXXXXXXXXXXXX', 'XXXXXXXX_DISCORD_WEBHOOK_TOKEN_REDACTED_XXXXXXXX'),
mobile: new WebhookClient('XXXXXXXXXXXXXXXXXX', 'XXXXXXXX_DISCORD_WEBHOOK_TOKEN_REDACTED_XXXXXXXX'),
back: new WebhookClient('XXXXXXXXXXXXXXXXXX', 'XXXXXXXX_DISCORD_WEBHOOK_TOKEN_REDACTED_XXXXXXXX'),
}
var receive = []
const sendEmbed = (embed, branch) => {
switch (branch) {
case "web": return (hook.web.send(embed));
case "mobile": return (hook.mobile.send(embed));
case "back": return (hook.back.send(embed));
};
}
const messageCommit = (obj) => {
if (!(obj.sender && obj.head_commit && obj.ref))
return;
const branch = obj.ref.split('/')[2]
const embed = new MessageEmbed()
.setTitle("New Push on " + branch)
.setColor("#5be6ff")
.setDescription("[" + "`" + obj.head_commit.id.slice(0, 7) + "`" + "](" + obj.head_commit.url + ") " + obj.head_commit.message + " - " + obj.head_commit.author.name)
.setURL(obj.head_commit.url)
.setAuthor(obj.head_commit.author.name, obj.sender.avatar_url);
sendEmbed(embed, branch)
}
const githubMessage = () => {
while (receive.length) {
const obj = receive.shift();
messageCommit(obj);
}
}
http.createServer((req, res) => {
let data = '';
req.on('data', (chunk) => {
data += chunk;
});
req.on('end', () => {
receive.push(JSON.parse(data))
githubMessage()
data = ''
});
res.writeHead(200);
res.end();
}).listen(4200);
// client.on('ready', () => {
// console.log(`Logged in as ${client.user.tag}!`);
// });
// client.on('message', (msg) => {
// if (msg.content === 'ping' || msg.content === 'ppng') {
// msg.reply("pong");
// msg.channel.send({embed: {
// color: 3447003,
// description: "A very simple Embed !!!!!"
// }});
// }
// });
// client.login('token du bot');