1 | exports.command = {
|
2 | name: "file",
|
3 | autoload: true,
|
4 | unloadable: false,
|
5 | min_rank: 0,
|
6 | display: "Show a list of files, or a the content of one",
|
7 | help: "There can be a number of files available for you to read. This is the command used to either list or read them.",
|
8 | usage: ".file, .file <filename>",
|
9 |
|
10 | execute: function(socket, command, command_access) {
|
11 |
|
12 | var chalk = require('chalk');
|
13 | command = command.trim();
|
14 | const fs = require('fs');
|
15 | const directory = './files/';
|
16 |
|
17 |
|
18 | if (command.trim() === "") {
|
19 | socket.write(chalk.teal("+-- List of available files: --------+\r\n"));
|
20 | fs.readdirSync(directory).forEach(file => {
|
21 | socket.write(" " + chalk.bold(file) + "\r\n");
|
22 | });
|
23 | socket.write(chalk.teal("+------------------------------------+\r\n"));
|
24 | } else {
|
25 |
|
26 | try {
|
27 | socket.write("\r\n" + fs.readFileSync(directory + command) + "\r\n");
|
28 | } catch(e) {
|
29 | socket.write(chalk.red(":: ") + "That file isn't available.\r\n");
|
30 | }
|
31 | }
|
32 | }
|
33 | }
|