-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs-hooks.js
More file actions
88 lines (71 loc) · 1.34 KB
/
js-hooks.js
File metadata and controls
88 lines (71 loc) · 1.34 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
79
80
81
82
83
84
85
86
87
88
const request = require('request-promise');
class hook {
// takes in webhook and content
constructor(webhook, content='') {
this.webhook = webhook;
this.webhookForm = {
content: content,
embeds: []
};
};
// input name and value and outputs a new form
fieldForm(name, value, inline=true) {
let form = {
name: name,
value: value,
inline: inline
};
return form;
};
embedForm() {
let form = {
author: {
name: '',
url: '',
icon_url: '',
},
title: '',
url: '',
color: 15258703,
fields: [],
thumbnail: {
url: ''
},
image: {
url: ''
},
footer: {
text: '',
icon_url: ''
}
};
return form;
};
newEmbed(embed) {
this.webhookForm.embeds.push(embed);
};
// specify the position of the embed and adds a field to it
newField(embed, field) {
this.webhookForm.embeds[embed].fields.push(field);
};
// sends the request to webhook with the content
async sendWebhookContent(){
let options = {
method: 'POST',
uri: this.webhook,
headers: {
'Content-Type': 'application/json'
},
body: this.webhookForm,
json: true
};
// sends request and gets the status code
let response = await new Promise(resolve => {
request(options, (e, r) => {
resolve(r.statusCode);
});
});
return response;
};
};
module.exports = {hook};