-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageBuilder.js
142 lines (142 loc) · 3.88 KB
/
MessageBuilder.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var Discord = require("discord.js");
class MessageBuilder {
constructor(bot) {
this.bot = bot;
this.data = {};
}
text(t) {
if (!this.data.content) {
this.data.content = "";
}
this.data.content += t;
return this;
}
link(text, link) {
if (!this.data.content) {
this.data.content = "";
}
this.data.content += `[${text}](${link})`;
return this;
}
button(basic, execute) {
var btn = new Discord.ButtonBuilder();
if (!basic.id && !basic.url) {
throw new Error("All buttons except URL must have ID.");
}
if (basic.id) {
btn.setCustomId(basic.id);
}
if (basic.disabled) {
btn.setDisabled(!0);
} else {
btn.setDisabled(!1);
}
if (basic.emoji) {
btn.setEmoji(basic.emoji);
}
if (basic.text) {
btn.setLabel(basic.text);
}
if (!basic.emoji && !basic.text) {
throw new Error("Can't have an empty button.");
}
var colorlib = {
"blue": "Primary",
"gray": "Secondary",
"lime": "Success",
"red": "Danger"
};
basic.color = basic.color.toLowerCase();
if (!colorlib[basic.color] && !basic.url) {
throw new Error("Unknown color.");
}
if (basic.url) {
btn.setStyle(Discord.ButtonStyle.Link);
btn.setURL(basic.url);
} else {
btn.setStyle(Discord.ButtonStyle[colorlib[basic.color]]);
}
if (!this.data.components) {
this.data.components = [];
}
if (basic.row) {
if (!this.data.components[(basic.row - 1)]) {
this.data.components[(basic.row - 1)] = new Discord.ActionRowBuilder();
}
this.data.components[(basic.row - 1)].addComponents(btn);
} else {
if (!this.data.components[0]) {
this.data.components[0] = new Discord.ActionRowBuilder();
}
if (this.data.components[0].components.length < 5) {
this.data.components[0].addComponents(btn);
} else {
if (!this.data.components[1]) {
this.data.components[1] = new Discord.ActionRowBuilder();
}
if (this.data.components[1].components.length < 5) {
this.data.components[1].addComponents(btn);
} else {
if (!this.data.components[2]) {
this.data.components[2] = new Discord.ActionRowBuilder();
}
if (this.data.components[2].components.length < 5) {
this.data.components[2].addComponents(btn);
} else {
if (!this.data.components[3]) {
this.data.components[3] = new Discord.ActionRowBuilder();
}
if (this.data.components[3].components.length < 5) {
this.data.components[3].addComponents(btn);
} else {
if (!this.data.components[4]) {
this.data.components[4] = new Discord.ActionRowBuilder();
}
if (this.data.components[4].components.length < 5) {
this.data.components[4].addComponents(btn);
} else {
throw new Error("Can't have more than 25 buttons in a single message.");
}
}
}
}
}
}
if (!basic.url) {
if (this.bot.buttons.get(basic.id)) {
throw new Error("ID must be unique.");
}
this.bot.buttons.set(basic.id, Object.assign(basic, {
execute
}));
}
return this;
}
ephemeral() {
this.data.ephemeral = !0;
return this;
}
notEphemeral() {
this.data.ephemeral = !1;
return this;
}
embed(d) {
if (!this.data.embeds) {
this.data.embeds = [];
}
if (this.data.embeds.length < 10) {
this.data.embeds.push(d);
return this;
} else {
throw new Error("Message can't have more than 10 embeds.");
}
}
file(d) {
if (!this.data.files) {
this.data.files = [];
}
this.data.files.push(d);
return this;
}
}
module.exports = MessageBuilder;