diff --git a/src/client.ts b/src/client.ts index 6699c7d..ebb6140 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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) => { diff --git a/src/commands/help.ts b/src/commands/help.ts new file mode 100644 index 0000000..cd8835e --- /dev/null +++ b/src/commands/help.ts @@ -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 +};