catto.js 0.0.9 → 0.1.1
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 +37 -6
- 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
|
@@ -9,19 +9,25 @@ module.exports = class extends EventEmitter {
|
|
|
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
16
|
if (client) {
|
|
15
17
|
this.client = client;
|
|
16
18
|
} else {
|
|
17
19
|
this.client = new Discord.Client({
|
|
18
|
-
"intents": new Discord.IntentsBitField(this.options.intents)
|
|
20
|
+
"intents": new Discord.IntentsBitField(this.options.intents),
|
|
21
|
+
"rest": {
|
|
22
|
+
"version": this.options.apiv
|
|
23
|
+
}
|
|
19
24
|
});
|
|
20
25
|
}
|
|
26
|
+
this.slashCommands = new Map();
|
|
21
27
|
this.commands = new Map();
|
|
22
28
|
this.client.on("ready", () => {
|
|
23
29
|
var cmds = [];
|
|
24
|
-
for (var cmd of this.
|
|
30
|
+
for (var cmd of this.slashCommands.values()) {
|
|
25
31
|
var cmdo = new Discord.SlashCommandBuilder();
|
|
26
32
|
cmdo.setName(cmd.name).setDescription(cmd.description).setDMPermission(cmd.dm);
|
|
27
33
|
for (var opt of cmd.options) {
|
|
@@ -108,7 +114,9 @@ module.exports = class extends EventEmitter {
|
|
|
108
114
|
}
|
|
109
115
|
cmds.push(cmdo);
|
|
110
116
|
}
|
|
111
|
-
this.
|
|
117
|
+
if (this.options.slashListener) {
|
|
118
|
+
this.client.application.commands.set(cmds);
|
|
119
|
+
}
|
|
112
120
|
this.emit("running");
|
|
113
121
|
});
|
|
114
122
|
this.client.on("interactionCreate", interaction => {
|
|
@@ -117,12 +125,13 @@ module.exports = class extends EventEmitter {
|
|
|
117
125
|
if (interaction.member) {
|
|
118
126
|
interaction.member.user = new User(interaction.member.user);
|
|
119
127
|
}
|
|
120
|
-
var command = this.
|
|
128
|
+
var command = this.slashCommands.get(interaction.commandName);
|
|
121
129
|
if (command) {
|
|
122
130
|
try {
|
|
123
131
|
command.execute({
|
|
124
132
|
Discord,
|
|
125
133
|
interaction,
|
|
134
|
+
"cmd": command.name,
|
|
126
135
|
"bot": this
|
|
127
136
|
});
|
|
128
137
|
} catch(e) {
|
|
@@ -136,6 +145,22 @@ module.exports = class extends EventEmitter {
|
|
|
136
145
|
if (message.member) {
|
|
137
146
|
message.member.user = new User(message.member.user);
|
|
138
147
|
}
|
|
148
|
+
var args = message.content.split(" ");
|
|
149
|
+
var cmd = args.shift();
|
|
150
|
+
var command = this.commands.get(cmd);
|
|
151
|
+
if (command) {
|
|
152
|
+
try {
|
|
153
|
+
command.execute({
|
|
154
|
+
Discord,
|
|
155
|
+
message,
|
|
156
|
+
cmd,
|
|
157
|
+
args,
|
|
158
|
+
"bot": this
|
|
159
|
+
});
|
|
160
|
+
} catch(e) {
|
|
161
|
+
console.error(e);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
139
164
|
this.emit("message", message);
|
|
140
165
|
});
|
|
141
166
|
this.client.on("guildCreate", guild => {
|
|
@@ -154,12 +179,18 @@ module.exports = class extends EventEmitter {
|
|
|
154
179
|
options = [];
|
|
155
180
|
}
|
|
156
181
|
basic.name = basic.name.substring(1);
|
|
157
|
-
this.
|
|
182
|
+
this.slashCommands.set(basic.name, Object.assign(basic, {
|
|
158
183
|
"options": options,
|
|
159
184
|
"execute": executor
|
|
160
185
|
}));
|
|
161
186
|
return this;
|
|
162
187
|
}
|
|
188
|
+
command(basic, executor) {
|
|
189
|
+
this.commands.set(basic.name, Object.assign(basic, {
|
|
190
|
+
"execute": executor
|
|
191
|
+
}));
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
163
194
|
run() {
|
|
164
195
|
this.client.login(this.options.token);
|
|
165
196
|
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