catto.js 1.3.9 β 1.4.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/Bot.js +3 -0
- package/Oracle.js +1 -1
- package/README.md +440 -15
- package/Server.js +3 -2
- package/package.json +1 -1
package/Bot.js
CHANGED
|
@@ -359,6 +359,9 @@ module.exports = class extends EventEmitter {
|
|
|
359
359
|
this.client.login(this.options.token);
|
|
360
360
|
return this;
|
|
361
361
|
}
|
|
362
|
+
runAsync() {
|
|
363
|
+
return this.client.login(this.options.token);
|
|
364
|
+
}
|
|
362
365
|
stop() {
|
|
363
366
|
this.client.destroy().then(() => {
|
|
364
367
|
this.emit("stopped");
|
package/Oracle.js
CHANGED
package/README.md
CHANGED
|
@@ -1,23 +1,448 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# πΊ Catto.JS β¨
|
|
2
|
+
## *Most universal, easy and catty JavaScript module*
|
|
3
|
+
|
|
3
4
|

|
|
4
|
-

|
|
5
6
|

|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
**[English]** | [[Π ΡΡΡΠΊΠΈΠΉ]](./README.ru.md)
|
|
9
|
+
|
|
10
|
+
Catto.JS is a module that is designed to help you with making a Discord/Telegram bot, Discord activities, a website using CJS syntax, sanitizing HTML, encoding/decoding Base64, working with Bitfields, generating random, making Oracle/GitHub API requests and just helping you use JavaScript.
|
|
11
|
+
|
|
8
12
|
## Features
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
13
|
+
|
|
14
|
+
- Host a web server just like in [ExpressJS](https://www.npmjs.com/package/express)
|
|
15
|
+
- Easily handle SSL, sessions (just like in [Express-Session](https://www.npmjs.com/package/express-session)) and WebSocket (just like in [Express-WS](https://www.npmjs.com/package/express-ws)) on your web server
|
|
16
|
+
- Make Discord bots/activities just like in [DiscordJS](https://www.npmjs.com/package/discord.js), but easier, more optimized and stable API
|
|
17
|
+
- Make Telegram bots just like [Telegraf](https://www.npmjs.com/package/telegraf), but easier and more Discord-like API
|
|
18
|
+
- Authorize on your website using Discord account
|
|
19
|
+
- Sanitize HTML to make sure you don't get hacked by an XSS
|
|
20
|
+
- Make Telegram web-apps and handle authorization
|
|
21
|
+
- Generate random numbers and booleans
|
|
22
|
+
- Make API requests
|
|
23
|
+
- Automatically handle Oracle API request signing
|
|
24
|
+
- Read and write files to [GitHub](https://github.com/) repository
|
|
25
|
+
- Easily work with BitFields
|
|
26
|
+
- Improve JavaScript experience by adding methods to existing arrays/strings
|
|
27
|
+
- This module is being maintained and updated frequently to make sure you don't have issues/bugs
|
|
28
|
+
- Stable API, very rare deprecations/breaking changes so you can update the module version without changing your code
|
|
29
|
+
- π Cats π
|
|
17
30
|
|
|
18
31
|
## Installation
|
|
32
|
+
|
|
33
|
+
Catto.JS requires [Node.js](https://nodejs.org) to run. Minimal version of NodeJS depends on your use case - Catto.JS can work on very old versions as long as you disable some features.
|
|
34
|
+
|
|
35
|
+
CattoJS requires **v9.11.0+** to run, but other features like Discord bots may request you to use a newer version.
|
|
36
|
+
|
|
37
|
+
Install it in your project from [NPM Registry](https://www.npmjs.com/package/catmagick) using a package manager: [NPM](https://www.npmjs.com), [Yarn](https://yarnpkg.com) or [PNPM](https://pnpm.io).
|
|
38
|
+
|
|
19
39
|
```sh
|
|
20
|
-
|
|
40
|
+
# Install latest stable version from NPM Registry using NPM
|
|
41
|
+
npm install catto.js
|
|
42
|
+
|
|
43
|
+
# Install latest stable version from NPM Registry using Yarn
|
|
44
|
+
yarn add catto.js
|
|
45
|
+
|
|
46
|
+
# Install latest stable version from NPM Registry using PNPM
|
|
47
|
+
pnpm add catto.js
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or install the latest beta version in your project from [GitHub](https://github.com/BoryaGames/catto.js) using a package manager: [NPM](https://www.npmjs.com), [Yarn](https://yarnpkg.com) or [PNPM](https://pnpm.io).
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
# Install latest beta version from GitHub using NPM
|
|
54
|
+
npm install git+https://github.com/BoryaGames/catto.js.git
|
|
55
|
+
|
|
56
|
+
# Install latest beta version from GitHub using Yarn
|
|
57
|
+
yarn add git+https://github.com/BoryaGames/catto.js.git
|
|
58
|
+
|
|
59
|
+
# Install latest beta version from GitHub using PNPM
|
|
60
|
+
pnpm add https://github.com/BoryaGames/catto.js.git
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Getting started
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
// Get started by importing catto.js
|
|
67
|
+
var cattojs = require("catto.js");
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Random
|
|
71
|
+
|
|
72
|
+
These functions are for generating random data.
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
// Get a random floating point number between 1 and 5 inclusive
|
|
76
|
+
var num = cattojs.random.float(1, 5);
|
|
77
|
+
|
|
78
|
+
// Get a random number between 1 and 5 with starting number included (1, 2, 3, 4)
|
|
79
|
+
var num = cattojs.random.int(1, 5);
|
|
80
|
+
|
|
81
|
+
// Get a random number between 1 and 5 inclusive (1, 2, 3, 4, 5)
|
|
82
|
+
var num = cattojs.random.range(1, 5);
|
|
83
|
+
|
|
84
|
+
// Get a random logic value (false, true)
|
|
85
|
+
var num = cattojs.random.bool();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### HTML
|
|
89
|
+
|
|
90
|
+
These functions are for working with HTML text.
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
// This is now safe to show in the browser without getting XSS
|
|
94
|
+
var safe = cattojs.HTML.disable("<script>console.log('hacked');</script>");
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Utilities
|
|
98
|
+
|
|
99
|
+
These functions help you use JavaScript.
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
var arr = ["a", "b", "c"];
|
|
103
|
+
if (arr.has("b")) { // shortcut for .includes()
|
|
104
|
+
arr.remove(1); // remove element by index and return element
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
// You can now use async replaces
|
|
110
|
+
var str = await something.replaceAsync("dog", async () => "cat");
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
// Code will resume execution after bot.loaded will become true value
|
|
115
|
+
await cattojs.utils.waitFor(bot, "loaded");
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Web Server
|
|
119
|
+
|
|
120
|
+
This class allows you to host a web server, let's start with creating one.
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
var server = new cattojs.Server();
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
That's enough to create a web server, but you can add options (but they're all optional).
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
var server = new cattojs.Server({
|
|
130
|
+
"domain": "example.com", // your domain
|
|
131
|
+
"port": 1234, // port, defaults to auto-detect (which works with Pterodactyl too!)
|
|
132
|
+
"ssl": false, // if you want catto.js to host HTTPS, set this to true
|
|
133
|
+
"cert": "mycert.pem", // if you set ssl to true, make sure to give a path to the SSL certificate
|
|
134
|
+
"key": "mykey.pem", // if you set ssl to true, make sure to give a path to the SSL key
|
|
135
|
+
"sslProxy": true, // or if your SSL is already given by a proxy (like CloudFlare), set this to true
|
|
136
|
+
"proxies": 1, // amount of proxies between clients and your web server, set this to correctly determine client's ip, or set to -1 for any amount (unsafe), defaults to 0
|
|
137
|
+
"websocket": true, // enable websocket support, defaults to true
|
|
138
|
+
"secret": "catsAreAwesome123", // a secret password used to encrypt sessions, make sure to set this if you want to use sessions
|
|
139
|
+
"secureCookie": true, // if session cookies should be HTTPS-only
|
|
140
|
+
"cookieAge": 604800, // cookie expiration age in seconds, defaults to 1000 years
|
|
141
|
+
"bodyCompatible": false, // set this to true if some module like express-http-proxy is reading raw body, this will disable body parsing, defaults to false
|
|
142
|
+
"ejs": false, // set this to true to use res.render for EJS, defaults to false
|
|
143
|
+
"cjs": true, // set this to true to use res.render for CJS, defaults to false
|
|
144
|
+
"cjsClient": true, // set this to true to use CJS in the client too, defaults to true if CJS is enabled
|
|
145
|
+
"serverOptions": {}, // this option should only be used for something that catto.js doesn't support
|
|
146
|
+
"expressWsiOptions": {}, // this option should only be used for something that catto.js doesn't support
|
|
147
|
+
"storeOptions": {} // this option should only be used for something that catto.js doesn't support
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Once you made a server, you can add routes just like in [ExpressJS](https://npmjs.com/package/express).
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
server.get("/cats", (req, res) => {
|
|
155
|
+
console.log(req.ip); // log user's ip (requires proxies options to be set)
|
|
156
|
+
|
|
157
|
+
res.end("Meow!");
|
|
158
|
+
}).post("/meow", (req, res) => {
|
|
159
|
+
console.log(req.body.message); // read value from body
|
|
160
|
+
res.header("X-Meow", "accepted"); // custom response header
|
|
161
|
+
res.status(204); // set status code
|
|
162
|
+
res.end();
|
|
163
|
+
}).use(() => {
|
|
164
|
+
// Since this is in the end, it can be used as 404 page
|
|
165
|
+
res.status(404);
|
|
166
|
+
res.end("404 page not found!");
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
And make sure to run the server and optionally listen for `running` event.
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
server.on("running", () => {
|
|
174
|
+
console.log("Site is online!");
|
|
175
|
+
}).run();
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
There's also some extra functions.
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
// Serve static content from a folder
|
|
182
|
+
server.static("public");
|
|
183
|
+
|
|
184
|
+
// Serve static content from a folder on a specific path
|
|
185
|
+
server.static("assets", "/assets");
|
|
186
|
+
|
|
187
|
+
// FA stands for fast answer
|
|
188
|
+
server.get("/ping", cattojs.Server.fa("Pong!"));
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Requests
|
|
192
|
+
|
|
193
|
+
CattoJS automatically adds `fetch()` function even if your NodeJS version doesn't have it, but CattoJS has own functions to do requests.
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
var { response, body } = cattojs.request.get("https://example.com/");
|
|
197
|
+
// Body will automatically be parsed as JSON if possible even without a header
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Oracle API
|
|
201
|
+
|
|
202
|
+
You can make requests to Oracle API using normal fetch.
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
var oci = new cattojs.Oracle({
|
|
206
|
+
"config": "myconfig", // defaults to config
|
|
207
|
+
"profile": "DEFAULT" // defaults to DEFAULT
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Just use as normal fetch
|
|
211
|
+
var response = await oci.fetch("https://iaas.uk-london-1.oraclecloud.com/20160812/...");
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Base64
|
|
215
|
+
|
|
216
|
+
You can encode/decode Base64 data.
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
var test = cattojs.Base64.encode("meow"); // encoded
|
|
220
|
+
|
|
221
|
+
// Decode
|
|
222
|
+
console.log(cattojs.Base64.decode(test)); // > meow
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Discord Bots
|
|
226
|
+
|
|
227
|
+
### Getting started
|
|
228
|
+
|
|
229
|
+
You can create a Discord Bot using the `Bot` class.
|
|
230
|
+
|
|
231
|
+
```javascript
|
|
232
|
+
var bot = new cattojs.Bot({
|
|
233
|
+
"token": "Mz...", // your Discord bot token, required
|
|
234
|
+
"intents": 131071, // intents for your bot, bitfield, defaults to 98045 (all non-priveleged intents)
|
|
235
|
+
"apiv": 10, // Discord API version to use, defaults to 10
|
|
236
|
+
"slashListener": true, // if true, catto.js will overwrite your slash commands with the ones you made using .slashCommand and listen for interactions and respond, set to false if you already made the slash commands yourself, defaults to true
|
|
237
|
+
"buttonListener": true, // if true, catto.js will listen for button interactions and respond, set to false if you handle the buttons yourself
|
|
238
|
+
"publicKey": "123", // your public key, required for web interactions
|
|
239
|
+
"debug": false, // enable debug mode for extra logs
|
|
240
|
+
"mobile": false, // set mobile status
|
|
241
|
+
"sharded": false, // set to true if your bot is using shards
|
|
242
|
+
"partials": false // set to true to receive partials
|
|
243
|
+
});
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
And make sure to run the bot and optionally listen for `running` event to detect when it's online.
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
bot.on("running", () => {
|
|
250
|
+
console.log("Bot is online!");
|
|
251
|
+
}).run();
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Text commands
|
|
255
|
+
|
|
256
|
+
```javascript
|
|
257
|
+
// Make sure to enable message content intent for normal text commands
|
|
258
|
+
bot.command("!test", async ({ Discord, message, cmd, args }) => { // optional variables you can take
|
|
259
|
+
// Message object just like in DiscordJS
|
|
260
|
+
var msg = await message.reply({
|
|
261
|
+
"content": "Meow!"
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Editing message with adding an embed
|
|
265
|
+
// Discord is just DiscordJS object
|
|
266
|
+
var embed = new Discord.EmbedBuilder();
|
|
267
|
+
embed.setDescription("Test!");
|
|
268
|
+
msg.edit({
|
|
269
|
+
"content": "Meow meow!",
|
|
270
|
+
"embeds": [embed]
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Slash commands
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
bot.slashCommand({
|
|
279
|
+
"name": "/test", // command itself, must start with slash, required
|
|
280
|
+
"description": "A command just for testing.", // description, required
|
|
281
|
+
"dm": false, // can this command be in direct messages, optional
|
|
282
|
+
"user": false, // can this command be executed anywhere as user-installed bot, optional
|
|
283
|
+
"servers": ["916772281747931198"], // servers where this command will be, defaults to null (all servers)
|
|
284
|
+
"options": [{ // arguments to the slash command
|
|
285
|
+
"type": "string", // argument type (string, integer, bool, user, channel, role, file, number, mentionable), required
|
|
286
|
+
"name": "cat", // argument name, required
|
|
287
|
+
"description": "Type of a cat", // argument description, required
|
|
288
|
+
"required": true, // if the argument is required
|
|
289
|
+
"min": 2, // minimum length for a string or a minimum value for integer/number
|
|
290
|
+
"max": 15, // maximum length for a string or a maximum value for integer/number
|
|
291
|
+
"choices": [{ // if specified, user will be required to choose one of the choices (works with string, integer, number)
|
|
292
|
+
"name": "Siamese Cat",
|
|
293
|
+
"value": "1304"
|
|
294
|
+
}],
|
|
295
|
+
//"types": [0] // types user can choose (for channel)
|
|
296
|
+
}]
|
|
297
|
+
}, async ({ interaction }) => { // handler
|
|
298
|
+
interaction.reply({
|
|
299
|
+
"content": "Meow!"
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
If you want to reply to an interaction with an ephemeral message, feel free to use `"ephemeral": true` (it's deprecated in DiscordJS, but not in CattoJS!), no need to use new Discord's flags system.
|
|
305
|
+
|
|
306
|
+
### Sharding
|
|
307
|
+
|
|
308
|
+
Sharding from 2500+ servers, Discord will require you to use shards, and CattoJS organizes multiple shards into clusters. For that you need to split your bot in two files - launcher and the bot.
|
|
309
|
+
|
|
310
|
+
```javascript
|
|
311
|
+
// index.js (launcher)
|
|
312
|
+
var cattojs = require("catto.js");
|
|
313
|
+
cattojs.Bot.shard("bot.js", "Mz...", 1, 3); // bot file, token, type (1 - worker, 2 - process, defaults to worker), compression (how many shards can be combined in a single claster, defaults to auto)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
And the `bot.js` file is the same as normal one, but make sure to add `"sharded": true` to your bot's options.
|
|
317
|
+
|
|
318
|
+
### Events
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
bot.on("running", () => {
|
|
322
|
+
// Current shard is online
|
|
323
|
+
}).on("runningFullLast", () => {
|
|
324
|
+
// This event is only emitted on the last cluster once all clusters have loaded, useful if you need to do an action on every shard once bot has fully started
|
|
325
|
+
}).on("message", message => {
|
|
326
|
+
// Bot saw a new message
|
|
327
|
+
}).on("messageDeleted", message => {
|
|
328
|
+
// Message got deleted
|
|
329
|
+
}).on("botAdd", server => {
|
|
330
|
+
// Your bot got added to this server
|
|
331
|
+
}).on("botDeleted", server => {
|
|
332
|
+
// Your bot got deletd from that server
|
|
333
|
+
}).on("stopped", () => {
|
|
334
|
+
// You stopped the bot using bot.stop()
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Miscellaneous
|
|
339
|
+
|
|
340
|
+
```javascript
|
|
341
|
+
console.log(bot.servers); // array of all bot's servers (on current shard)
|
|
342
|
+
console.log(bot.servers.count); // amount of all bot's servers (global)
|
|
343
|
+
|
|
344
|
+
console.log(bot.channels); // array of all bot's channels (on current shard)
|
|
345
|
+
console.log(bot.channels.count); // amount of all bot's channels (on current shard)
|
|
346
|
+
|
|
347
|
+
console.log(bot.cluster); // get current cluster
|
|
348
|
+
|
|
349
|
+
// Set bot's status and activity
|
|
350
|
+
bot.setStatus({
|
|
351
|
+
"status": "idle",
|
|
352
|
+
"activities": [{
|
|
353
|
+
"name": "with a cat"
|
|
354
|
+
}]
|
|
355
|
+
});
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Context menus
|
|
359
|
+
|
|
360
|
+
```javascript
|
|
361
|
+
// User/message context menu, only 3 options exist - name, dm, user (see above for explanations)
|
|
362
|
+
bot.messageContext({
|
|
363
|
+
"name": "Repeat text"
|
|
364
|
+
}, async ({ interaction }) => {
|
|
365
|
+
interaction.reply({
|
|
366
|
+
// Get content from message user clicked on
|
|
367
|
+
"content": interaction.targetMessage.content
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Message builder
|
|
373
|
+
|
|
374
|
+
Message builder allows you to build a message by attaching text/links/embeds/files/buttons step-by-step.
|
|
375
|
+
|
|
376
|
+
```javascript
|
|
377
|
+
var msg = new cattojs.MessageBuilder(bot); // make sure to specify the bot
|
|
378
|
+
msg.text("Meow! Here's a cool link for you: ").link("Click here", "https://example.com").text("\nOr maybe you want a button?").button({
|
|
379
|
+
"url": "https://example.com",
|
|
380
|
+
"text": "Click here"
|
|
381
|
+
}).button({
|
|
382
|
+
"id": `another_link_${Date.now()}`, // ID must be unique and is required for non-link buttons
|
|
383
|
+
"color": "lime", // color of the button (blue, gray, lime, red)
|
|
384
|
+
"emoji": "π",
|
|
385
|
+
"text": "I want another link"
|
|
386
|
+
}, ({ interaction }) => {
|
|
387
|
+
interaction.reply("https://catutils.pro/");
|
|
388
|
+
}).ephemeral();
|
|
389
|
+
|
|
390
|
+
// Send built message
|
|
391
|
+
message.reply(msg.data);
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Patches
|
|
395
|
+
|
|
396
|
+
CattoJS tries to patch all User objects.
|
|
397
|
+
|
|
398
|
+
```javascript
|
|
399
|
+
bot.on("message", message => {
|
|
400
|
+
console.log(message.author); // cattojs.User
|
|
401
|
+
});
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
Here's some features of the `User` class.
|
|
405
|
+
|
|
406
|
+
```javascript
|
|
407
|
+
bot.on("message", async message => {
|
|
408
|
+
console.log(message.author.id); // user's ID
|
|
409
|
+
console.log(message.author.name); // user's username
|
|
410
|
+
console.log(message.author.decoration); // a link to user's avatar decoration
|
|
411
|
+
console.log(message.author.avatar); // a link to user's avatar
|
|
412
|
+
console.log(message.author.banner); // a link to user's banner
|
|
413
|
+
console.log(message.author.badges); // array of user's badges
|
|
414
|
+
console.log(message.author.isBot); // is user a bot
|
|
415
|
+
console.log(message.author.isBotVerified); // is user a verified bot
|
|
416
|
+
console.log(message.author.isSpammer); // is user a spammer
|
|
417
|
+
|
|
418
|
+
// If user is a bot, an application can be requested
|
|
419
|
+
await message.author.requestApplication();
|
|
420
|
+
console.log(message.author.application.description); // bot's description (about me)
|
|
421
|
+
console.log(message.author.application.TOS); // a link to bot's Terms of Service
|
|
422
|
+
console.log(message.author.application.privacyPolicy); // a link to bot's privacy policy
|
|
423
|
+
console.log(message.author.application.supportsSlash); // does bot support slash commands
|
|
424
|
+
});
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### GitHub
|
|
428
|
+
|
|
429
|
+
CattoJS can read and write files to GitHub repository, which also can be used to use GitHub as a database.
|
|
430
|
+
|
|
431
|
+
```javascript
|
|
432
|
+
var gh = new cattojs.GitHub({
|
|
433
|
+
"token": "123", // GitHub API token, required
|
|
434
|
+
"username": "BoryaGames", // your username, required
|
|
435
|
+
"repository": "TestDB", // repository, required
|
|
436
|
+
"message": "cattojs" // commit message to show when catto.js changes a file
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
// Read file (JSON parsed automatically if possible)
|
|
440
|
+
var data = await gh.read("database.json");
|
|
441
|
+
|
|
442
|
+
// Read file in Base64 mode
|
|
443
|
+
var release = await gh.read("release.exe", true);
|
|
444
|
+
|
|
445
|
+
// Change and write the data back (writing requires to read first!)
|
|
446
|
+
data.value = 4;
|
|
447
|
+
await gh.write("database.json", data);
|
|
21
448
|
```
|
|
22
|
-
## Usage
|
|
23
|
-
> Currently unavailable.
|
package/Server.js
CHANGED
|
@@ -166,9 +166,9 @@ class Server extends EventEmitter {
|
|
|
166
166
|
}
|
|
167
167
|
static(folder, pathname) {
|
|
168
168
|
if (pathname) {
|
|
169
|
-
this.app.use(pathname, express.static(path.join(__dirname,"..","..",folder)));
|
|
169
|
+
this.app.use(pathname, express.static(path.join(__dirname, "..", "..", folder)));
|
|
170
170
|
} else {
|
|
171
|
-
this.app.use(express.static(path.join(__dirname,"..","..",folder)));
|
|
171
|
+
this.app.use(express.static(path.join(__dirname, "..", "..", folder)));
|
|
172
172
|
}
|
|
173
173
|
return this;
|
|
174
174
|
}
|
|
@@ -215,3 +215,4 @@ class Server extends EventEmitter {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
module.exports = Server;
|
|
218
|
+
|