help command

This commit is contained in:
nin0dev 2024-09-23 20:40:30 -04:00
parent 161748b993
commit 7c4bd12a14
Signed by: nin0
GPG key ID: 3FA8F96ABAE04214
2 changed files with 36 additions and 1 deletions

View file

@ -7,8 +7,9 @@ import { Command } from "./utils/types";
import { forgejoDown } from "./commands/forgejo-down";
import { source } from "./commands/source";
import { sql } from "./commands/sql";
import { help } from "./commands/help";
const commands: Command[] = [forgejoDown, minky, source, sql];
export const commands: Command[] = [forgejoDown, minky, source, sql, help];
export const bot = new Telegraf(config.token);
bot.on(message("text"), async (ctx) => {

34
src/commands/help.ts Normal file
View file

@ -0,0 +1,34 @@
import { Context } from "telegraf";
import { CommandTypes } from "../utils/types";
import { commands } from "../client";
async function handler(ctx: Context, args: string[]) {
if (args.length === 1) {
const cmd = commands.find((c) => c.name === args[0]);
if (!cmd) return await ctx.reply("Command not found");
return await ctx.replyWithMarkdown(
`*${cmd.name}${cmd.aliases.length ? ` (${cmd.aliases.join(", ")})` : ""}*\n${cmd.description}\n${cmd.modOnly ? "_🛡 Mod only_" : ""}${cmd.ownerOnly ? "_👑 Owner only_" : ""}`
);
} else {
const cmds = commands.filter((c) => !c.ownerOnly);
cmds.sort((a, b) => a.name.localeCompare(b.name)); // Sort commands alphabetically by name
return await ctx.replyWithMarkdown(
cmds
.map(
(c) =>
`*${c.name}*${c.aliases.length ? `_ (${c.aliases.join(", ")})_` : ""} - ${c.description}`
)
.join("\n")
);
}
}
export const help = {
name: "help",
aliases: ["h", "?"],
description: "Get bot help",
type: CommandTypes.Info,
modOnly: false,
ownerOnly: false,
handler
};