-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiscordBot.js
More file actions
93 lines (79 loc) · 3.67 KB
/
discordBot.js
File metadata and controls
93 lines (79 loc) · 3.67 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
89
90
91
92
93
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
var XMLHttpRequest = require('xhr2');
class DiscordBot {
//Webhook URLs need to be defined in env vars (config vars in heroku). get them at discord dev browser
constructor(spanishChannel, aztecChannel, tlaxChannel, aztecTlax, aztecSpan, spanTlax, general, omen) {
this.spanishChannel = spanishChannel;
this.aztecChannel = aztecChannel;
this.tlaxChannel = tlaxChannel;
this.aztecTlax = aztecTlax;
this.aztecSpan = aztecSpan;
this.spanTlax = spanTlax;
this.general = general;
this.omen = omen;
}
// Sends notification to a specific channel
sendNotif(channel, message) {
console.log(channel, message)
const content = message;
let username, avatar_url, channelURL;
switch(channel){
case "aztecs":
username = 'Aztec Messenger';
avatar_url = "https://images.fineartamerica.com/images-medium-large/2-hernando-cortez-spanish-conquistador-photo-researchers.jpg";
channelURL = this.aztecChannel;
break;
case "spanish":
username = 'Spanish Messenger';
avatar_url = "https://images.fineartamerica.com/images-medium-large/2-hernando-cortez-spanish-conquistador-photo-researchers.jpg";
channelURL = this.spanishChannel;
break;
case "tlax":
username = 'Tlaxcalan Messenger';
avatar_url = "https://images.fineartamerica.com/images-medium-large/2-hernando-cortez-spanish-conquistador-photo-researchers.jpg";
channelURL = this.tlaxChannel;
break;
case "aztecSpan":
username = 'Spanish and Aztec Messenger';
avatar_url = "https://images.fineartamerica.com/images-medium-large/2-hernando-cortez-spanish-conquistador-photo-researchers.jpg";
channelURL = this.aztecSpan;
break;
case "aztecTlax":
username = 'Aztec and Tlaxcalan Messenger';
avatar_url = "https://images.fineartamerica.com/images-medium-large/2-hernando-cortez-spanish-conquistador-photo-researchers.jpg";
channelURL = this.aztecTlax;
break;
case "spanTlax":
username = 'Spanish and Tlaxcalan Messenger';
avatar_url = "https://images.fineartamerica.com/images-medium-large/2-hernando-cortez-spanish-conquistador-photo-researchers.jpg";
channelURL = this.spanTlax;
break;
case "general":
username = 'General Messenger';
avatar_url = "https://images.fineartamerica.com/images-medium-large/2-hernando-cortez-spanish-conquistador-photo-researchers.jpg";
channelURL = this.general;
break;
case "omen":
username = 'Omen Messenger';
avatar_url = "https://images.fineartamerica.com/images-medium-large/2-hernando-cortez-spanish-conquistador-photo-researchers.jpg";
channelURL = this.omen;
break;
}
const request = new XMLHttpRequest();
request.open("POST", channelURL);
request.onload = function(e) {
//console.log(e);
//
};
request.setRequestHeader('Content-type', 'application/json');
const params = {
username,
avatar_url,
content
}
// Send message
request.send(JSON.stringify(params));
}
}
export default DiscordBot;