catto.js 0.0.9 → 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 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,24 @@ 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
  }
21
26
  this.commands = new Map();
22
27
  this.client.on("ready", () => {
23
28
  var cmds = [];
24
- for (var cmd of this.commands.values()) {
29
+ for (var cmd of this.slashCommands.values()) {
25
30
  var cmdo = new Discord.SlashCommandBuilder();
26
31
  cmdo.setName(cmd.name).setDescription(cmd.description).setDMPermission(cmd.dm);
27
32
  for (var opt of cmd.options) {
@@ -108,7 +113,9 @@ module.exports = class extends EventEmitter {
108
113
  }
109
114
  cmds.push(cmdo);
110
115
  }
111
- this.client.application.commands.set(cmds);
116
+ if (this.options.slashListener) {
117
+ this.client.application.commands.set(cmds);
118
+ }
112
119
  this.emit("running");
113
120
  });
114
121
  this.client.on("interactionCreate", interaction => {
@@ -117,12 +124,13 @@ module.exports = class extends EventEmitter {
117
124
  if (interaction.member) {
118
125
  interaction.member.user = new User(interaction.member.user);
119
126
  }
120
- var command = this.commands.get(interaction.commandName);
127
+ var command = this.slashCommands.get(interaction.commandName);
121
128
  if (command) {
122
129
  try {
123
130
  command.execute({
124
131
  Discord,
125
132
  interaction,
133
+ "cmd": command.name,
126
134
  "bot": this
127
135
  });
128
136
  } catch(e) {
@@ -136,6 +144,22 @@ module.exports = class extends EventEmitter {
136
144
  if (message.member) {
137
145
  message.member.user = new User(message.member.user);
138
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
+ }
139
163
  this.emit("message", message);
140
164
  });
141
165
  this.client.on("guildCreate", guild => {
@@ -154,12 +178,18 @@ module.exports = class extends EventEmitter {
154
178
  options = [];
155
179
  }
156
180
  basic.name = basic.name.substring(1);
157
- this.commands.set(basic.name, Object.assign(basic, {
181
+ this.slashCommands.set(basic.name, Object.assign(basic, {
158
182
  "options": options,
159
183
  "execute": executor
160
184
  }));
161
185
  return this;
162
186
  }
187
+ command(basic, executor) {
188
+ this.commands.set(basic.name, Object.assign(basic, {
189
+ "execute": executor
190
+ }));
191
+ return this;
192
+ }
163
193
  run() {
164
194
  this.client.login(this.options.token);
165
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -1,3 +1,6 @@
1
1
  Array.prototype.remove = function(index) {
2
2
  return this.splice(index, 1)[0];
3
- };
3
+ };
4
+ Array.prototype.has = function(data) {
5
+ return this.includes(data);
6
+ };