-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.js
70 lines (63 loc) · 1.88 KB
/
send.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
const { TextChannel, GuildMember, MessageEmbed } = require("discord.js")
const Log = require("./logging.js")
function sendSuccess(recv, msg){
return sendMain(recv, msg, Log.success)
}
function sendFail(recv, msg){
return sendMain(recv, msg, Log.fail)
}
function sendInfo(recv, msg){
return sendMain(recv, msg, Log.info)
}
function sendColor(recv, msg, color){
return sendMain(recv, msg, Log.color, color)
}
function sendMain(recv, msg, log_func, color){
return new Promise( (done, error) => {
var send_to;
if(recv instanceof TextChannel || recv instanceof GuildMember){
send_to = recv;
}
else{
send_to = recv.channel;
}
send_to.send(msg)
.then(message => {
if(msg instanceof MessageEmbed){
log_func(`Sent embed`, color)
} else {
log_func(`Sent message: ${message.content}`, color)
}
done(message);
})
.catch(error);
});
}
function sendError(recv, err){
return new Promise( (done, error) => {
var send_to;
if(recv instanceof TextChannel || recv instanceof GuildMember){
send_to = recv;
}
else{
send_to = recv.channel;
}
const error_embed = new MessageEmbed()
.setColor('#FFECAC')
.setTitle('An error has occurred')
.setDescription('```ts\n'+err+'```')
.setFooter("Retrieved")
.setTimestamp()
send_to.send(error_embed).then( sent_msg => {
Log.fail(`Sent error: ${err}`)
done(sent_msg)
}).catch(error)
})
}
module.exports = {
success: sendSuccess,
fail: sendFail,
info: sendInfo,
color: sendColor,
error: sendError
}