Misc. module updates.
This commit is contained in:
parent
976d3bc6db
commit
b497423ba7
@ -50,6 +50,14 @@ export const commands = [
|
||||
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
|
||||
{
|
||||
data: new SlashCommandBuilder()
|
||||
@ -89,19 +97,20 @@ export const commands = [
|
||||
// Build embed for status
|
||||
// Determine if gitUtils module is loaded
|
||||
const gitLoaded = client.modules?.has('gitUtils');
|
||||
let branch, build, statusBlock;
|
||||
let branch, build, statusRaw, statusBlock;
|
||||
if (gitLoaded) {
|
||||
const git = client.modules.get('gitUtils');
|
||||
try {
|
||||
branch = await git.getBranch();
|
||||
build = await git.getShortHash();
|
||||
const statusRaw = await git.getStatusShort();
|
||||
statusRaw = await git.getStatusShort();
|
||||
// Format status as fenced code block using template literals
|
||||
// Normalize each line with a leading space in a code fence
|
||||
// Prefix raw status output with a single space
|
||||
statusBlock = statusRaw
|
||||
? '```\n ' + statusRaw + '\n```'
|
||||
: '```\n (clean)\n```';
|
||||
// Prefix raw status output with a space, and only if non-empty
|
||||
if (statusRaw) {
|
||||
statusBlock = '```\n ' + statusRaw + '\n```';
|
||||
}
|
||||
} catch {
|
||||
branch = '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) {
|
||||
try {
|
||||
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 = '') {
|
||||
const fence = '```';
|
||||
return lang
|
||||
@ -31,7 +41,12 @@ function formatCodeBlock(content, lang = '') {
|
||||
: `${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) {
|
||||
const chunks = [];
|
||||
for (let i = 0; i < str.length; i += chunkSize) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user