catto.js 0.1.9 → 0.2.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 CHANGED
@@ -1,4 +1,26 @@
1
+ /**
2
+ * A class representing an application's information.
3
+ * @class
4
+ */
1
5
  module.exports = class {
6
+ /**
7
+ * Creates an instance of Application.
8
+ * @param {Object} [options={}] - An object containing information about the application.
9
+ * @property {String} options.id - The ID of the application.
10
+ * @property {String} options.name - The name of the application.
11
+ * @property {String} options.icon - The hash for the application's icon.
12
+ * @property {String} options.description - A description of the application.
13
+ * @property {String} options.cover_image - The hash for the application's cover image.
14
+ * @property {String} options.guild_id - The ID of the server the application is connected to.
15
+ * @property {Boolean} options.bot_public - A flag indicating whether the bot is public.
16
+ * @property {Boolean} options.bot_require_code_grant - A flag indicating whether the bot requires code grant.
17
+ * @property {String} options.terms_of_service_url - The URL for the application's terms of service.
18
+ * @property {String} options.privacy_policy_url - The URL for the application's privacy policy.
19
+ * @property {Object} options.install_params - Installation parameters for the application.
20
+ * @property {String} options.verify_key - A verify key for the application.
21
+ * @property {Number} options.flags - A number representing the application's flags.
22
+ * @property {Array} options.tags - An array of tags for the application.
23
+ */
2
24
  constructor(options) {
3
25
  this.options = Object.assign({
4
26
  "id": "",
@@ -17,42 +39,94 @@ module.exports = class {
17
39
  "tags": []
18
40
  }, options || {});
19
41
  }
42
+ /**
43
+ * Gets the ID of the application.
44
+ * @returns {String} - The ID of the application.
45
+ */
20
46
  get id() {
21
47
  return this.options.id;
22
48
  }
49
+ /**
50
+ * Gets the name of the application.
51
+ * @returns {String} - The name of the application.
52
+ */
23
53
  get name() {
24
54
  return this.options.name;
25
55
  }
56
+ /**
57
+ * Gets the hash for the application's icon.
58
+ * @returns {String} - The hash for the application's icon.
59
+ */
26
60
  get iconHash() {
27
61
  return this.options.icon;
28
62
  }
63
+ /**
64
+ * Gets the description of the application.
65
+ * @returns {String} - A description of the application.
66
+ */
29
67
  get description() {
30
68
  return this.options.description;
31
69
  }
32
- get coverImageHas() {
70
+ /**
71
+ * Gets the hash for the application's cover image.
72
+ * @returns {String} - The hash for the application's cover image.
73
+ */
74
+ get coverImageHash() {
33
75
  return this.options.cover_image;
34
76
  }
77
+ /**
78
+ * Gets the ID of the server the application is connected to.
79
+ * @returns {String} - The ID of the server the application is connected to.
80
+ */
35
81
  get server() {
36
82
  return this.options.guild_id;
37
83
  }
84
+ /**
85
+ * Gets a flag indicating whether the bot is public.
86
+ * @returns {Boolean} - A flag indicating whether the bot is public.
87
+ */
38
88
  get isPublic() {
39
89
  return this.options.bot_public;
40
90
  }
91
+ /**
92
+ * Gets a flag indicating whether the bot requires code grant.
93
+ * @returns {Boolean} - A flag indicating whether the bot requires code grant.
94
+ */
41
95
  get requireCodeGrant() {
42
96
  return this.options.bot_require_code_grant;
43
97
  }
98
+ /**
99
+ * Getter method to return the URL for the Terms of Service for this bot application.
100
+ * @returns {string} URL for the Terms of Service.
101
+ */
44
102
  get TOS() {
45
103
  return this.options.terms_of_service_url;
46
104
  }
105
+ /**
106
+ * Getter method to return the URL for the Privacy Policy for this bot application.
107
+ * @returns {string} URL for the Privacy Policy.
108
+ */
47
109
  get privacyPolicy() {
48
110
  return this.options.privacy_policy_url;
49
111
  }
112
+ /**
113
+ * Getter method to return the installation parameters for this bot application.
114
+ * @returns {object} Installation parameters.
115
+ */
50
116
  get installParams() {
51
117
  return this.options.install_params;
52
118
  }
119
+ /**
120
+ * Getter method to return the verification key for this bot application.
121
+ * @returns {string} Verification key.
122
+ */
53
123
  get verifyKey() {
54
124
  return this.options.verify_key;
55
125
  }
126
+ /**
127
+ * Getter method to return an array of badges for this bot application.
128
+ * @returns {Array} Array of badges.
129
+ */
56
130
  get badges() {
57
131
  var i = 24;
58
132
  var p = this.options.flags;
@@ -91,21 +165,45 @@ module.exports = class {
91
165
  ];
92
166
  return f.map(n => fl[n]).filter(n => n);
93
167
  }
168
+ /**
169
+ * Getter method to return an array of tags for this bot application.
170
+ * @returns {Array} Array of tags.
171
+ */
94
172
  get tags() {
95
173
  return this.options.tags;
96
174
  }
175
+ /**
176
+ * Getter method to return an array of intents for this bot application.
177
+ * @returns {Array} Array of intents.
178
+ */
97
179
  get intents() {
98
180
  return this.badges.filter(badge => ![null, "VERIFICATION_PENDING_GUILD_LIMIT", "EMBEDDED", "APPLICATION_COMMAND_BADGE"].includes(badge));
99
181
  }
182
+ /**
183
+ * Gets a boolean indicating if the application cannot be verified.
184
+ * @returns {boolean} A boolean indicating if the application cannot be verified.
185
+ */
100
186
  get cannotVerify() {
101
187
  return this.badges.has("VERIFICATION_PENDING_GUILD_LIMIT");
102
188
  }
189
+ /**
190
+ * Gets a boolean indicating if the application can be verified.
191
+ * @returns {boolean} A boolean indicating if the application can be verified.
192
+ */
103
193
  get canVerify() {
104
194
  return !this.cannotVerify;
105
195
  }
196
+ /**
197
+ * Gets a boolean indicating if the application is embedded.
198
+ * @returns {boolean} A boolean indicating if the application is embedded.
199
+ */
106
200
  get isEmbedded() {
107
201
  return this.badges.has("EMBEDDED");
108
202
  }
203
+ /**
204
+ * Gets a boolean indicating if the application supports the slash command.
205
+ * @returns {boolean} A boolean indicating if the application supports the slash command.
206
+ */
109
207
  get supportsSlash() {
110
208
  return this.badges.has("APPLICATION_COMMAND_BADGE");
111
209
  }
package/Base64.js CHANGED
@@ -1,8 +1,22 @@
1
+ /**
2
+ * Encodes a string to base64.
3
+ * @function
4
+ * @param {string} text - The text to be encoded.
5
+ * @returns {string} - The encoded text in base64.
6
+ */
7
+ function encode(text) {
8
+ return Buffer.from(text, "utf-8").toString("base64")
9
+ }
10
+ /**
11
+ * Decodes a base64 string.
12
+ * @function
13
+ * @param {string} text - The text to be decoded.
14
+ * @returns {string} - The decoded text.
15
+ */
16
+ function decode(text) {
17
+ return Buffer.from(text, "base64").toString("utf-8")
18
+ }
1
19
  module.exports = {
2
- "encode": text => {
3
- return Buffer.from(text, "utf-8").toString("base64")
4
- },
5
- "decode": text => {
6
- return Buffer.from(text, "base64").toString("utf-8")
7
- }
8
- };
20
+ encode,
21
+ decode
22
+ };
package/Bot.js CHANGED
@@ -67,7 +67,7 @@ module.exports = class extends EventEmitter {
67
67
  var option = new Discord.SlashCommandUserOption();
68
68
  option.setName(opt.name);
69
69
  option.setDescription(opt.description);
70
- option.setRequired(opt.req);
70
+ option.setRequired(opt.required);
71
71
  cmdo.addUserOption(option);
72
72
  break;
73
73
  case "channel":
@@ -139,8 +139,10 @@ module.exports = class extends EventEmitter {
139
139
  "bot": this
140
140
  });
141
141
  } catch(e) {
142
- console.error(e);
142
+ console.log(e);
143
143
  }
144
+ } else {
145
+ interaction.reply({}).catch(() => {});
144
146
  }
145
147
  }
146
148
  if (interaction.isButton()) {
@@ -159,8 +161,10 @@ module.exports = class extends EventEmitter {
159
161
  "bot": this
160
162
  });
161
163
  } catch(e) {
162
- console.error(e);
164
+ console.log(e);
163
165
  }
166
+ } else {
167
+ interaction.reply({}).catch(() => {});
164
168
  }
165
169
  }
166
170
  });
@@ -184,7 +188,7 @@ module.exports = class extends EventEmitter {
184
188
  "bot": this
185
189
  });
186
190
  } catch(e) {
187
- console.error(e);
191
+ console.log(e);
188
192
  }
189
193
  }
190
194
  this.emit("message", message);
package/GitHub.js CHANGED
@@ -1,6 +1,22 @@
1
1
  var request = require("./request");
2
2
  var Base64 = require("./Base64");
3
- module.exports = class {
3
+ /**
4
+ * Class for reading and writing data to a Github repository.
5
+ *
6
+ * @class Github
7
+ */
8
+ class GitHub {
9
+ /**
10
+ * Creates an instance of Github.
11
+ *
12
+ * @constructor
13
+ * @param {object} [options={}] - Options to initialize the instance.
14
+ * @param {string} [options.token=""] - Github API token.
15
+ * @param {string} [options.username=""] - Github username.
16
+ * @param {string} [options.repository=""] - Name of the repository.
17
+ * @param {string} [options.message="cattojs"] - Commit message.
18
+ *
19
+ */
4
20
  constructor(options) {
5
21
  this.options = Object.assign({
6
22
  "token": "",
@@ -9,6 +25,16 @@ module.exports = class {
9
25
  "message": "cattojs"
10
26
  }, options || {});
11
27
  }
28
+ /**
29
+ * Reads data from a file in the Github repository.
30
+ *
31
+ * @param {string} file - Path to the file to be read.
32
+ *
33
+ * @returns {(string|object)} - The content of the file. If the file is a JSON file, returns a parsed object, otherwise returns a string.
34
+ *
35
+ * @async
36
+ * @throws {Error} If there is a problem with the API request.
37
+ */
12
38
  async read(file) {
13
39
  var value = Base64.decode((await request.get({
14
40
  "url": `https://api.github.com/repos/${this.options.username}/${this.options.repository}/contents/${file}`,
@@ -22,6 +48,17 @@ module.exports = class {
22
48
  } catch(e) {}
23
49
  return value;
24
50
  }
51
+ /**
52
+ * Writes data to a file in the Github repository.
53
+ *
54
+ * @param {string} file - Path to the file to be written.
55
+ * @param {(string|object)} value - The data to be written to the file. If it is an object, it will be stringified as a JSON file.
56
+ *
57
+ * @returns {boolean} - Returns true if the write was successful.
58
+ *
59
+ * @async
60
+ * @throws {Error} If there is a problem with the API request.
61
+ */
25
62
  async write(file, value) {
26
63
  if (typeof value === "object") {
27
64
  value = JSON.stringify(value);
@@ -40,4 +77,5 @@ module.exports = class {
40
77
  });
41
78
  return !0;
42
79
  }
43
- };
80
+ }
81
+ module.exports = GitHub;
package/HTML.js CHANGED
@@ -1,5 +1,11 @@
1
+ /**
2
+ * Disables HTML tags in a given string.
3
+ * @param {string} text - The string to disable HTML tags in.
4
+ * @returns {string} - The string with HTML tags disabled.
5
+ */
6
+ function disable(text) {
7
+ return text.split("<").join("&lt;").split(">").join("&gt;");
8
+ }
1
9
  module.exports = {
2
- "disable": text => {
3
- return text.split("<").join("&lt;").split(">").join("&gt;");
4
- }
5
- };
10
+ disable
11
+ };
package/MessageBuilder.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var Discord = require("discord.js");
2
- module.exports = class MessageBuilder {
2
+ class MessageBuilder {
3
3
  constructor(bot) {
4
4
  this.bot = bot;
5
5
  this.data = {};
@@ -101,4 +101,24 @@ module.exports = class MessageBuilder {
101
101
  }
102
102
  return this;
103
103
  }
104
- };
104
+ ephemeral() {
105
+ this.data.ephemeral = !0;
106
+ return this;
107
+ }
108
+ notEphemeral() {
109
+ this.data.ephemeral = !1;
110
+ return this;
111
+ }
112
+ embed(d) {
113
+ if (!this.data.embeds) {
114
+ this.data.embeds = [];
115
+ }
116
+ if (this.data.embeds.length < 10) {
117
+ this.data.embeds.push(d);
118
+ return this;
119
+ } else {
120
+ throw new Error("Message can't have more than 10 embeds.");
121
+ }
122
+ }
123
+ }
124
+ module.exports = MessageBuilder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catto.js",
3
- "version": "0.1.9",
3
+ "version": "0.2.1",
4
4
  "description": "Universal module for everything.",
5
5
  "main": "index.js",
6
6
  "scripts": {