catto.js 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Application.js +112 -0
- package/Bot.js +45 -11
- package/User.js +7 -0
- package/index.js +1 -1
- package/index.test.js +5 -1
- package/package.json +1 -1
- package/utils.js +4 -1
package/Application.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
module.exports = class {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
this.options = Object.assign({
|
|
4
|
+
"id": "",
|
|
5
|
+
"name": "",
|
|
6
|
+
"icon": "",
|
|
7
|
+
"description": "",
|
|
8
|
+
"cover_image": "",
|
|
9
|
+
"guild_id": "",
|
|
10
|
+
"bot_public": !1,
|
|
11
|
+
"bot_require_code_grant": !1,
|
|
12
|
+
"terms_of_service_url": "",
|
|
13
|
+
"privacy_policy_url": "",
|
|
14
|
+
"install_params": null,
|
|
15
|
+
"verify_key": "",
|
|
16
|
+
"flags": 0,
|
|
17
|
+
"tags": []
|
|
18
|
+
}, options || {});
|
|
19
|
+
}
|
|
20
|
+
get id() {
|
|
21
|
+
return this.options.id;
|
|
22
|
+
}
|
|
23
|
+
get name() {
|
|
24
|
+
return this.options.name;
|
|
25
|
+
}
|
|
26
|
+
get iconHash() {
|
|
27
|
+
return this.options.icon;
|
|
28
|
+
}
|
|
29
|
+
get description() {
|
|
30
|
+
return this.options.description;
|
|
31
|
+
}
|
|
32
|
+
get coverImageHas() {
|
|
33
|
+
return this.options.cover_image;
|
|
34
|
+
}
|
|
35
|
+
get server() {
|
|
36
|
+
return this.options.guild_id;
|
|
37
|
+
}
|
|
38
|
+
get isPublic() {
|
|
39
|
+
return this.options.bot_public;
|
|
40
|
+
}
|
|
41
|
+
get requireCodeGrant() {
|
|
42
|
+
return this.options.bot_require_code_grant;
|
|
43
|
+
}
|
|
44
|
+
get TOS() {
|
|
45
|
+
return this.options.terms_of_service_url;
|
|
46
|
+
}
|
|
47
|
+
get privacyPolicy() {
|
|
48
|
+
return this.options.privacy_policy_url;
|
|
49
|
+
}
|
|
50
|
+
get installParams() {
|
|
51
|
+
return this.options.install_params;
|
|
52
|
+
}
|
|
53
|
+
get verifyKey() {
|
|
54
|
+
return this.options.verify_key;
|
|
55
|
+
}
|
|
56
|
+
get badges() {
|
|
57
|
+
var i = 24;
|
|
58
|
+
var p = this.options.flags;
|
|
59
|
+
var f = [];
|
|
60
|
+
while (--i > -1) {
|
|
61
|
+
if (![22, 21, 20, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0].includes(i) && p >= (1 << i)) {
|
|
62
|
+
p -= (1 << i);
|
|
63
|
+
f.push(i);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
var fl = [
|
|
67
|
+
null,
|
|
68
|
+
null,
|
|
69
|
+
null,
|
|
70
|
+
null,
|
|
71
|
+
null,
|
|
72
|
+
null,
|
|
73
|
+
null,
|
|
74
|
+
null,
|
|
75
|
+
null,
|
|
76
|
+
null,
|
|
77
|
+
null,
|
|
78
|
+
null,
|
|
79
|
+
"GATEWAY_PRESENCE",
|
|
80
|
+
"GATEWAY_PRESENCE_LIMITED",
|
|
81
|
+
"GATEWAY_GUILD_MEMBERS",
|
|
82
|
+
"GATEWAY_GUILD_MEMBERS_LIMITED",
|
|
83
|
+
"VERIFICATION_PENDING_GUILD_LIMIT",
|
|
84
|
+
"EMBEDDED",
|
|
85
|
+
"GATEWAY_MESSAGE_CONTENT",
|
|
86
|
+
"GATEWAY_MESSAGE_CONTENT_LIMITED",
|
|
87
|
+
null,
|
|
88
|
+
null,
|
|
89
|
+
null,
|
|
90
|
+
"APPLICATION_COMMAND_BADGE"
|
|
91
|
+
];
|
|
92
|
+
return f.map(n => fl[n]);
|
|
93
|
+
}
|
|
94
|
+
get tags() {
|
|
95
|
+
return this.options.tags;
|
|
96
|
+
}
|
|
97
|
+
get intents() {
|
|
98
|
+
return this.badges.filter(badge => ![null, "VERIFICATION_PENDING_GUILD_LIMIT", "EMBEDDED", "APPLICATION_COMMAND_BADGE"].includes(badge));
|
|
99
|
+
}
|
|
100
|
+
get cannotVerify() {
|
|
101
|
+
return this.badges.has("VERIFICATION_PENDING_GUILD_LIMIT");
|
|
102
|
+
}
|
|
103
|
+
get canVerify() {
|
|
104
|
+
return !this.cannotVerify;
|
|
105
|
+
}
|
|
106
|
+
get isEmbedded() {
|
|
107
|
+
return this.badges.has("EMBEDDED");
|
|
108
|
+
}
|
|
109
|
+
get supportsSlash() {
|
|
110
|
+
return this.badges.has("APPLICATION_COMMAND_BADGE");
|
|
111
|
+
}
|
|
112
|
+
};
|
package/Bot.js
CHANGED
|
@@ -5,19 +5,28 @@ if (typeof EventEmitter !== "undefined") {} else {
|
|
|
5
5
|
var { EventEmitter } = events;
|
|
6
6
|
}
|
|
7
7
|
module.exports = class extends EventEmitter {
|
|
8
|
-
constructor(options) {
|
|
8
|
+
constructor(options, client) {
|
|
9
9
|
super();
|
|
10
10
|
this.options = Object.assign({
|
|
11
11
|
"token": "",
|
|
12
|
-
"intents": 98045
|
|
12
|
+
"intents": 98045,
|
|
13
|
+
"apiv": 10,
|
|
14
|
+
"slashListener": !0
|
|
13
15
|
}, options || {});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
16
|
+
if (client) {
|
|
17
|
+
this.client = client;
|
|
18
|
+
} else {
|
|
19
|
+
this.client = new Discord.Client({
|
|
20
|
+
"intents": new Discord.IntentsBitField(this.options.intents),
|
|
21
|
+
"rest": {
|
|
22
|
+
"version": this.options.apiv
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
17
26
|
this.commands = new Map();
|
|
18
27
|
this.client.on("ready", () => {
|
|
19
28
|
var cmds = [];
|
|
20
|
-
for (var cmd of this.
|
|
29
|
+
for (var cmd of this.slashCommands.values()) {
|
|
21
30
|
var cmdo = new Discord.SlashCommandBuilder();
|
|
22
31
|
cmdo.setName(cmd.name).setDescription(cmd.description).setDMPermission(cmd.dm);
|
|
23
32
|
for (var opt of cmd.options) {
|
|
@@ -104,7 +113,9 @@ module.exports = class extends EventEmitter {
|
|
|
104
113
|
}
|
|
105
114
|
cmds.push(cmdo);
|
|
106
115
|
}
|
|
107
|
-
this.
|
|
116
|
+
if (this.options.slashListener) {
|
|
117
|
+
this.client.application.commands.set(cmds);
|
|
118
|
+
}
|
|
108
119
|
this.emit("running");
|
|
109
120
|
});
|
|
110
121
|
this.client.on("interactionCreate", interaction => {
|
|
@@ -113,12 +124,13 @@ module.exports = class extends EventEmitter {
|
|
|
113
124
|
if (interaction.member) {
|
|
114
125
|
interaction.member.user = new User(interaction.member.user);
|
|
115
126
|
}
|
|
116
|
-
var command = this.
|
|
127
|
+
var command = this.slashCommands.get(interaction.commandName);
|
|
117
128
|
if (command) {
|
|
118
129
|
try {
|
|
119
130
|
command.execute({
|
|
120
131
|
Discord,
|
|
121
132
|
interaction,
|
|
133
|
+
"cmd": command.name,
|
|
122
134
|
"bot": this
|
|
123
135
|
});
|
|
124
136
|
} catch(e) {
|
|
@@ -132,13 +144,29 @@ module.exports = class extends EventEmitter {
|
|
|
132
144
|
if (message.member) {
|
|
133
145
|
message.member.user = new User(message.member.user);
|
|
134
146
|
}
|
|
147
|
+
var args = message.content.split(" ");
|
|
148
|
+
var cmd = args.shift();
|
|
149
|
+
var command = this.commands.get(cmd);
|
|
150
|
+
if (command) {
|
|
151
|
+
try {
|
|
152
|
+
command.execute({
|
|
153
|
+
Discord,
|
|
154
|
+
message,
|
|
155
|
+
cmd,
|
|
156
|
+
args,
|
|
157
|
+
"bot": this
|
|
158
|
+
});
|
|
159
|
+
} catch(e) {
|
|
160
|
+
console.error(e);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
135
163
|
this.emit("message", message);
|
|
136
164
|
});
|
|
137
165
|
this.client.on("guildCreate", guild => {
|
|
138
166
|
this.emit("botAdd", guild);
|
|
139
167
|
});
|
|
140
|
-
this.client.on("
|
|
141
|
-
this.emit("
|
|
168
|
+
this.client.on("guildDelete", guild => {
|
|
169
|
+
this.emit("botDelete", guild);
|
|
142
170
|
});
|
|
143
171
|
}
|
|
144
172
|
slashCommand(basic, options, executor) {
|
|
@@ -150,12 +178,18 @@ module.exports = class extends EventEmitter {
|
|
|
150
178
|
options = [];
|
|
151
179
|
}
|
|
152
180
|
basic.name = basic.name.substring(1);
|
|
153
|
-
this.
|
|
181
|
+
this.slashCommands.set(basic.name, Object.assign(basic, {
|
|
154
182
|
"options": options,
|
|
155
183
|
"execute": executor
|
|
156
184
|
}));
|
|
157
185
|
return this;
|
|
158
186
|
}
|
|
187
|
+
command(basic, executor) {
|
|
188
|
+
this.commands.set(basic.name, Object.assign(basic, {
|
|
189
|
+
"execute": executor
|
|
190
|
+
}));
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
159
193
|
run() {
|
|
160
194
|
this.client.login(this.options.token);
|
|
161
195
|
return this;
|
package/User.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var Application = require("./Application");
|
|
1
2
|
module.exports = class {
|
|
2
3
|
constructor(options) {
|
|
3
4
|
this.options = Object.assign({
|
|
5
|
+
"client": null,
|
|
4
6
|
"id": "",
|
|
5
7
|
"username": "",
|
|
6
8
|
"avatar": "",
|
|
@@ -18,6 +20,11 @@ module.exports = class {
|
|
|
18
20
|
"bot": !1,
|
|
19
21
|
"system": !1
|
|
20
22
|
}, options || {});
|
|
23
|
+
if (this.isBot) {
|
|
24
|
+
request.get(`https://discord.com/api/v${this.options.client.rest.version}/oauth2/applications/${this.id}/rpc`).then(application => {
|
|
25
|
+
this.application = new Application(application);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
29
|
get id() {
|
|
23
30
|
return this.options.id;
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var mod = {};
|
|
2
|
-
["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Flags", "Bot"].forEach(part => {
|
|
2
|
+
["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Flags", "Bot", "Application"].forEach(part => {
|
|
3
3
|
mod[part] = require(`./${part}`);
|
|
4
4
|
});
|
|
5
5
|
module.exports = mod;
|
package/index.test.js
CHANGED
|
@@ -19,9 +19,13 @@ test("array remove", () => {
|
|
|
19
19
|
expect(arr.remove(1)).toBe("b");
|
|
20
20
|
expect(arr).toMatchObject(["a", "c"]);
|
|
21
21
|
});
|
|
22
|
+
test("array has", () => {
|
|
23
|
+
var arr = ["a", "b", "c"];
|
|
24
|
+
expect(arr.has("b")).toBeTruthy();
|
|
25
|
+
});
|
|
22
26
|
test("base64 encode", () => {
|
|
23
27
|
expect(cattojs.Base64.encode("Test.")).toBe("VGVzdC4=");
|
|
24
28
|
});
|
|
25
29
|
test("base64 decode", () => {
|
|
26
30
|
expect(cattojs.Base64.decode("VGVzdC4=")).toBe("Test.");
|
|
27
|
-
});
|
|
31
|
+
});
|
package/package.json
CHANGED