help command
This commit is contained in:
parent
161748b993
commit
7c4bd12a14
2 changed files with 36 additions and 1 deletions
|
@ -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
34
src/commands/help.ts
Normal 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
|
||||
};
|
Loading…
Reference in a new issue