catto.js 0.0.7 → 0.0.8
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/Bitfield.js +27 -0
- package/Bot.js +169 -0
- package/Flags.js +6 -0
- package/index.js +1 -1
- package/package.json +2 -1
package/Bitfield.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = class {
|
|
2
|
+
constructor(value, size, exclude) {
|
|
3
|
+
this.value = value || 0;
|
|
4
|
+
this.size = size || 32;
|
|
5
|
+
this.exclude = exclude || [];
|
|
6
|
+
}
|
|
7
|
+
has(bit) {
|
|
8
|
+
return (this.value & (1 << bit)) !== 0;
|
|
9
|
+
}
|
|
10
|
+
add(bit) {
|
|
11
|
+
this.value |= (1 << bit);
|
|
12
|
+
}
|
|
13
|
+
remove(bit) {
|
|
14
|
+
this.value &= ~(1 << bit);
|
|
15
|
+
}
|
|
16
|
+
all() {
|
|
17
|
+
var bits = [];
|
|
18
|
+
var i = 0;
|
|
19
|
+
while (i < this.size) {
|
|
20
|
+
if (!this.exclude.includes(i) && this.has(i)) {
|
|
21
|
+
bits.push(i);
|
|
22
|
+
}
|
|
23
|
+
i++;
|
|
24
|
+
}
|
|
25
|
+
return bits;
|
|
26
|
+
}
|
|
27
|
+
};
|
package/Bot.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var events = require("events");
|
|
2
|
+
var Discord = require("discord.js");
|
|
3
|
+
var User = require("./User");
|
|
4
|
+
if (typeof EventEmitter !== "undefined") {} else {
|
|
5
|
+
var { EventEmitter } = events;
|
|
6
|
+
}
|
|
7
|
+
module.exports = class extends EventEmitter {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super();
|
|
10
|
+
this.options = Object.assign({
|
|
11
|
+
"token": "",
|
|
12
|
+
"intents": 98045
|
|
13
|
+
}, options || {});
|
|
14
|
+
this.client = new Discord.Client({
|
|
15
|
+
"intents": new Discord.IntentsBitField(this.options.intents)
|
|
16
|
+
});
|
|
17
|
+
this.commands = new Map();
|
|
18
|
+
this.client.on("ready", () => {
|
|
19
|
+
var cmds = [];
|
|
20
|
+
for (var cmd of this.commands.values()) {
|
|
21
|
+
var cmdo = new Discord.SlashCommandBuilder();
|
|
22
|
+
cmdo.setName(cmd.name).setDescription(cmd.description).setDMPermission(cmd.dm);
|
|
23
|
+
for (var opt of cmd.options) {
|
|
24
|
+
switch(opt.type) {
|
|
25
|
+
case "string":
|
|
26
|
+
var option = new Discord.SlashCommandStringOption();
|
|
27
|
+
option.setName(opt.name);
|
|
28
|
+
option.setDescription(opt.description);
|
|
29
|
+
option.setRequired(opt.required);
|
|
30
|
+
if (opt.choices) {
|
|
31
|
+
option.setChoices(...opt.choices);
|
|
32
|
+
}
|
|
33
|
+
cmdo.addStringOption(option);
|
|
34
|
+
break;
|
|
35
|
+
case "integer":
|
|
36
|
+
var option = new Discord.SlashCommandIntegerOption();
|
|
37
|
+
option.setName(opt.name);
|
|
38
|
+
option.setDescription(opt.description);
|
|
39
|
+
option.setRequired(opt.required);
|
|
40
|
+
option.setMinValue(opt.min);
|
|
41
|
+
option.setMaxValue(opt.max);
|
|
42
|
+
if (opt.choices) {
|
|
43
|
+
option.setChoices(...opt.choices);
|
|
44
|
+
}
|
|
45
|
+
cmdo.addIntegerOption(option);
|
|
46
|
+
break;
|
|
47
|
+
case "bool":
|
|
48
|
+
var option = new Discord.SlashCommandBooleanOption();
|
|
49
|
+
option.setName(opt.name);
|
|
50
|
+
option.setDescription(opt.description);
|
|
51
|
+
option.setRequired(opt.required);
|
|
52
|
+
cmdo.addBooleanOption(option);
|
|
53
|
+
break;
|
|
54
|
+
case "user":
|
|
55
|
+
var option = new Discord.SlashCommandUserOption();
|
|
56
|
+
option.setName(opt.name);
|
|
57
|
+
option.setDescription(opt.description);
|
|
58
|
+
option.setRequired(opt.req);
|
|
59
|
+
cmdo.addUserOption(option);
|
|
60
|
+
break;
|
|
61
|
+
case "channel":
|
|
62
|
+
var option = new Discord.SlashCommandChannelOption();
|
|
63
|
+
option.setName(opt.name);
|
|
64
|
+
option.setDescription(opt.description);
|
|
65
|
+
option.setRequired(opt.required);
|
|
66
|
+
cmdo.addChannelOption(option);
|
|
67
|
+
break;
|
|
68
|
+
case "role":
|
|
69
|
+
var option = new Discord.SlashCommandRoleOption();
|
|
70
|
+
option.setName(opt.name);
|
|
71
|
+
option.setDescription(opt.description);
|
|
72
|
+
option.setRequired(opt.required);
|
|
73
|
+
cmdo.addRoleOption(option);
|
|
74
|
+
break;
|
|
75
|
+
case "file":
|
|
76
|
+
var option = new Discord.SlashCommandAttachmentOption();
|
|
77
|
+
option.setName(opt.name);
|
|
78
|
+
option.setDescription(opt.description);
|
|
79
|
+
option.setRequired(opt.required);
|
|
80
|
+
cmdo.addAttachmentOption(option);
|
|
81
|
+
break;
|
|
82
|
+
case "number":
|
|
83
|
+
var option = new Discord.SlashCommandNumberOption();
|
|
84
|
+
option.setName(opt.name);
|
|
85
|
+
option.setDescription(opt.description);
|
|
86
|
+
option.setRequired(opt.required);
|
|
87
|
+
option.setMinValue(opt.min);
|
|
88
|
+
option.setMaxValue(opt.max);
|
|
89
|
+
if (opt.choices) {
|
|
90
|
+
option.setChoices(...opt.choices);
|
|
91
|
+
}
|
|
92
|
+
cmdo.addNumberOption(option);
|
|
93
|
+
break;
|
|
94
|
+
case "mentionable":
|
|
95
|
+
var option = new Discord.SlashCommandMentionableOption();
|
|
96
|
+
option.setName(opt.name);
|
|
97
|
+
option.setDescription(opt.description);
|
|
98
|
+
option.setRequired(opt.required);
|
|
99
|
+
cmdo.addMentionableOption(option);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
cmds.push(cmdo);
|
|
106
|
+
}
|
|
107
|
+
this.client.application.commands.set(cmds);
|
|
108
|
+
this.emit("running");
|
|
109
|
+
});
|
|
110
|
+
this.client.on("interactionCreate", interaction => {
|
|
111
|
+
if (interaction.isChatInputCommand()) {
|
|
112
|
+
interaction.user = new User(interaction.user);
|
|
113
|
+
if (interaction.member) {
|
|
114
|
+
interaction.member.user = new User(interaction.member.user);
|
|
115
|
+
}
|
|
116
|
+
var command = this.commands.get(interaction.commandName);
|
|
117
|
+
if (command) {
|
|
118
|
+
try {
|
|
119
|
+
command.execute({
|
|
120
|
+
Discord,
|
|
121
|
+
interaction,
|
|
122
|
+
"bot": this
|
|
123
|
+
});
|
|
124
|
+
} catch(e) {
|
|
125
|
+
console.error(e);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.client.on("messageCreate", message => {
|
|
131
|
+
message.author = new User(message.author);
|
|
132
|
+
if (message.member) {
|
|
133
|
+
message.member.user = new User(message.member.user);
|
|
134
|
+
}
|
|
135
|
+
this.emit("message", message);
|
|
136
|
+
});
|
|
137
|
+
this.client.on("guildCreate", guild => {
|
|
138
|
+
this.emit("botAdd", guild);
|
|
139
|
+
});
|
|
140
|
+
this.client.on("guildRemove", guild => {
|
|
141
|
+
this.emit("botRemove", guild);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
slashCommand(basic, options, executor) {
|
|
145
|
+
if (!basic.name.startsWith("/")) {
|
|
146
|
+
throw new Error("Slash command starts with /.");
|
|
147
|
+
}
|
|
148
|
+
if (typeof options === "function") {
|
|
149
|
+
executor = options;
|
|
150
|
+
options = [];
|
|
151
|
+
}
|
|
152
|
+
basic.name = basic.name.substring(1);
|
|
153
|
+
this.commands.set(basic.name, Object.assign(basic, {
|
|
154
|
+
"options": options,
|
|
155
|
+
"execute": executor
|
|
156
|
+
}));
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
run() {
|
|
160
|
+
this.client.login(this.options.token);
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
stop() {
|
|
164
|
+
this.client.destroy().then(() => {
|
|
165
|
+
this.emit("stopped");
|
|
166
|
+
});
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
};
|
package/Flags.js
ADDED
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var mod = {};
|
|
2
|
-
["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User"].forEach(part => {
|
|
2
|
+
["random", "Server", "HTML", "request", "AuthClient", "utils", "GitHub", "Base64", "User", "Bitfield", "Flags", "Bot"].forEach(part => {
|
|
3
3
|
mod[part] = require(`./${part}`);
|
|
4
4
|
});
|
|
5
5
|
module.exports = mod;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catto.js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Universal module for everything.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"body-parser": "^1.20.1",
|
|
43
|
+
"discord.js": "^14.7.1",
|
|
43
44
|
"ejs": "^3.1.8",
|
|
44
45
|
"express": "^4.18.2",
|
|
45
46
|
"express-session": "^1.17.3",
|