Documentation Index
Fetch the complete documentation index at: https://docs.ethone.cc/llms.txt
Use this file to discover all available pages before exploring further.
OS Namespace
The os namespace provides file system operations.
os.read_file()
Read the contents of a file.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | Path to the file to read |
Returns
string - File contents, or null if failed
Example
ethone.on_command("readfile", "Read file", "readfile <path>", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .readfile <path>");
return;
}
var content = os.read_file(ctx.args[0]);
if (content) {
discord.send_message(ctx.channel.id, "File content:\n" + content.substring(0, 1000));
} else {
discord.send_message(ctx.channel.id, "Failed to read file");
}
});
os.write_file()
Write content to a file (overwrites existing file).
Syntax
os.write_file(path, content)
Parameters
| Parameter | Type | Description |
|---|
path | string | Path to the file to write |
content | string | Content to write to the file |
Returns
boolean - true if successful
Example
ethone.on_command("savelog", "Save log", "savelog <message>", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .savelog <message>");
return;
}
var message = ctx.args.join(" ");
var timestamp = new Date().toISOString();
var log = timestamp + " - " + ctx.author.tag + ": " + message + "\n";
if (os.write_file("log.txt", log)) {
discord.send_message(ctx.channel.id, "Log saved!");
} else {
discord.send_message(ctx.channel.id, "Failed to save log");
}
});
os.append_file()
Append content to a file (creates file if it doesn’t exist).
Syntax
os.append_file(path, content)
Parameters
| Parameter | Type | Description |
|---|
path | string | Path to the file |
content | string | Content to append |
Returns
boolean - true if successful
Example
discord.on_message = function(ctx) {
if (ctx.author.bot) return;
var log = new Date().toISOString() + " - " + ctx.author.tag + ": " + ctx.content + "\n";
os.append_file("chat_log.txt", log);
};
os.delete_file()
Delete a file.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | Path to the file to delete |
Returns
boolean - true if successful
Example
ethone.on_command("deletefile", "Delete file", "deletefile <path>", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .deletefile <path>");
return;
}
if (os.delete_file(ctx.args[0])) {
discord.send_message(ctx.channel.id, "File deleted!");
} else {
discord.send_message(ctx.channel.id, "Failed to delete file");
}
});
os.exists()
Check if a file or directory exists.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | Path to check |
Returns
boolean - true if exists
Example
ethone.on_command("checkfile", "Check if file exists", "checkfile <path>", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .checkfile <path>");
return;
}
var exists = os.exists(ctx.args[0]);
discord.send_message(ctx.channel.id, "File exists: " + exists);
});
os.list_dir()
List contents of a directory.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | Directory path |
Returns
Array of file/directory objects with properties:
name (string) - File/directory name
is_dir (boolean) - Whether it’s a directory
size (number) - File size in bytes
mod_time (number) - Last modified time (Unix timestamp)
Example
ethone.on_command("listdir", "List directory", "listdir [path]", function(ctx) {
var path = ctx.args.length > 0 ? ctx.args[0] : ".";
var files = os.list_dir(path);
if (files.length === 0) {
discord.send_message(ctx.channel.id, "Directory is empty or doesn't exist");
return;
}
var msg = "Files in " + path + ":\n";
for (var i = 0; i < Math.min(files.length, 10); i++) {
var file = files[i];
var type = file.is_dir ? "[Dir]" : "[File]";
msg += type + " " + file.name + " (" + file.size + " bytes)\n";
}
discord.send_message(ctx.channel.id, msg);
});
os.create_dir()
Create a directory (including parent directories if needed).
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | Directory path to create |
Returns
boolean - true if successful
Example
ethone.on_command("mkdir", "Create directory", "mkdir <path>", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .mkdir <path>");
return;
}
if (os.create_dir(ctx.args[0])) {
discord.send_message(ctx.channel.id, "Directory created!");
} else {
discord.send_message(ctx.channel.id, "Failed to create directory");
}
});
os.remove_dir()
Remove a directory and all its contents recursively.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | Directory path to remove |
Returns
boolean - true if successful
Warning
This operation is irreversible and removes all subdirectories and files!
os.get_cwd()
Get the current working directory.
Syntax
Returns
string - Current working directory path
Example
ethone.on_command("cwd", "Show current directory", "cwd", function(ctx) {
var cwd = os.get_cwd();
discord.send_message(ctx.channel.id, "Current directory: " + cwd);
});
os.join_path()
Join path components into a single path.
Syntax
Parameters
| Parameter | Type | Description |
|---|
...paths | string | Path components to join |
Returns
string - Joined path
Example
var dataDir = os.join_path(os.get_cwd(), "data");
var logFile = os.join_path(dataDir, "logs", "app.log");
ethone.log("Log file path: " + logFile);
os.basename()
Get the filename from a path.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | File path |
Returns
string - Filename (last element of path)
Example
var path = "/home/user/documents/file.txt";
var filename = os.basename(path);
os.dirname()
Get the directory from a path.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | File path |
Returns
string - Directory path
Example
var path = "/home/user/documents/file.txt";
var dir = os.dirname(path);
os.file_info()
Get detailed information about a file or directory.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | File/directory path |
Returns
Object with properties:
name (string) - Name
size (number) - Size in bytes
is_dir (boolean) - Whether it’s a directory
mod_time (number) - Last modified time (Unix timestamp)
mode (string) - File permissions (e.g., “-rw-r—r—”)
Returns null if file doesn’t exist.
Example
ethone.on_command("fileinfo", "Get file info", "fileinfo <path>", function(ctx) {
if (ctx.args.length < 1) {
discord.send_message(ctx.channel.id, "Usage: .fileinfo <path>");
return;
}
var info = os.file_info(ctx.args[0]);
if (info) {
var msg = "File: " + info.name + "\n";
msg += "Size: " + info.size + " bytes\n";
msg += "Type: " + (info.is_dir ? "Directory" : "File") + "\n";
msg += "Modified: " + new Date(info.mod_time * 1000).toISOString() + "\n";
msg += "Permissions: " + info.mode;
discord.send_message(ctx.channel.id, msg);
} else {
discord.send_message(ctx.channel.id, "File not found");
}
});
os.abs_path()
Get the absolute path from a relative path.
Syntax
Parameters
| Parameter | Type | Description |
|---|
path | string | Relative or absolute path |
Returns
string - Absolute path
Example
var relPath = "./data/file.txt";
var absPath = os.abs_path(relPath);
ethone.log("Absolute path: " + absPath);
os.rename()
Rename or move a file/directory.
Syntax
os.rename(oldPath, newPath)
Parameters
| Parameter | Type | Description |
|---|
oldPath | string | Current path |
newPath | string | New path |
Returns
boolean - true if successful
Example
ethone.on_command("rename", "Rename file", "rename <old> <new>", function(ctx) {
if (ctx.args.length < 2) {
discord.send_message(ctx.channel.id, "Usage: .rename <old> <new>");
return;
}
if (os.rename(ctx.args[0], ctx.args[1])) {
discord.send_message(ctx.channel.id, "File renamed!");
} else {
discord.send_message(ctx.channel.id, "Failed to rename file");
}
});