Misc. module updates.
This commit is contained in:
parent
976d3bc6db
commit
b497423ba7
@ -50,6 +50,14 @@ export const commands = [
|
|||||||
process.exit(exitCode);
|
process.exit(exitCode);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Slash command `/status` (Administrator only):
|
||||||
|
* Shows this bot client’s status including CPU, memory, environment,
|
||||||
|
* uptime, module list, and entity counts. Optionally displays Git info
|
||||||
|
* (Git Reference and Git Status) when the gitUtils module is loaded.
|
||||||
|
* @param {import('discord.js').CommandInteraction} interaction
|
||||||
|
* @param {import('discord.js').Client} client
|
||||||
|
*/
|
||||||
// /status: admin-only, shows current client info
|
// /status: admin-only, shows current client info
|
||||||
{
|
{
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@ -89,19 +97,20 @@ export const commands = [
|
|||||||
// Build embed for status
|
// Build embed for status
|
||||||
// Determine if gitUtils module is loaded
|
// Determine if gitUtils module is loaded
|
||||||
const gitLoaded = client.modules?.has('gitUtils');
|
const gitLoaded = client.modules?.has('gitUtils');
|
||||||
let branch, build, statusBlock;
|
let branch, build, statusRaw, statusBlock;
|
||||||
if (gitLoaded) {
|
if (gitLoaded) {
|
||||||
const git = client.modules.get('gitUtils');
|
const git = client.modules.get('gitUtils');
|
||||||
try {
|
try {
|
||||||
branch = await git.getBranch();
|
branch = await git.getBranch();
|
||||||
build = await git.getShortHash();
|
build = await git.getShortHash();
|
||||||
const statusRaw = await git.getStatusShort();
|
statusRaw = await git.getStatusShort();
|
||||||
// Format status as fenced code block using template literals
|
// Format status as fenced code block using template literals
|
||||||
// Normalize each line with a leading space in a code fence
|
// Normalize each line with a leading space in a code fence
|
||||||
// Prefix raw status output with a single space
|
// Prefix raw status output with a single space
|
||||||
statusBlock = statusRaw
|
// Prefix raw status output with a space, and only if non-empty
|
||||||
? '```\n ' + statusRaw + '\n```'
|
if (statusRaw) {
|
||||||
: '```\n (clean)\n```';
|
statusBlock = '```\n ' + statusRaw + '\n```';
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
branch = 'error';
|
branch = 'error';
|
||||||
build = 'error';
|
build = 'error';
|
||||||
|
|||||||
@ -11,7 +11,12 @@ class GitError extends Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run `git <args>` and return trimmed output or throw
|
/**
|
||||||
|
* Execute a git command with given arguments and return its output.
|
||||||
|
* @param {string[]} args - Git command arguments (e.g., ['status', '--porcelain']).
|
||||||
|
* @returns {Promise<string>} - Trimmed stdout or stderr from the command.
|
||||||
|
* @throws {GitError} - When the git command exits with an error.
|
||||||
|
*/
|
||||||
async function runGit(args) {
|
async function runGit(args) {
|
||||||
try {
|
try {
|
||||||
const { stdout, stderr } = await execAsync(`git ${args.join(' ')}`);
|
const { stdout, stderr } = await execAsync(`git ${args.join(' ')}`);
|
||||||
@ -23,7 +28,12 @@ async function runGit(args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap content in Markdown code block
|
/**
|
||||||
|
* Wrap content into a Markdown code block, optionally specifying a language.
|
||||||
|
* @param {string} content - The text to wrap in a code block.
|
||||||
|
* @param {string} [lang] - Optional language identifier (e.g., 'js').
|
||||||
|
* @returns {string} - The content wrapped in triple backticks.
|
||||||
|
*/
|
||||||
function formatCodeBlock(content, lang = '') {
|
function formatCodeBlock(content, lang = '') {
|
||||||
const fence = '```';
|
const fence = '```';
|
||||||
return lang
|
return lang
|
||||||
@ -31,7 +41,12 @@ function formatCodeBlock(content, lang = '') {
|
|||||||
: `${fence}\n${content}\n${fence}`;
|
: `${fence}\n${content}\n${fence}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split string into chunks of at most chunkSize
|
/**
|
||||||
|
* Split a large string into smaller chunks for message limits.
|
||||||
|
* @param {string} str - The input string to split.
|
||||||
|
* @param {number} chunkSize - Maximum length of each chunk.
|
||||||
|
* @returns {string[]} - An array of substring chunks.
|
||||||
|
*/
|
||||||
function chunkString(str, chunkSize) {
|
function chunkString(str, chunkSize) {
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
for (let i = 0; i < str.length; i += chunkSize) {
|
for (let i = 0; i < str.length; i += chunkSize) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user