Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions commands/8ball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const responses = [

const command: CommandSchema = {
name: "8ball",
category: "Fun",
description: "Ask the magic 8-ball a question.",
params: "<question>",
requireElevated: false,
Expand Down
1 change: 1 addition & 0 deletions commands/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { CommandSchema } from "../utils/CommandSchema";

const command: CommandSchema = {
name: "about",
category: "General",
description: "About Capacitor",
requireElevated: false,

Expand Down
1 change: 1 addition & 0 deletions commands/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { generateBalanceCard } from "../utils/leveling";

const command: CommandSchema = {
name: "balance",
category: "Economy",
description: "Show a balance card (or another user's).",
params: "[@user|id]",
requireElevated: false,
Expand Down
1 change: 1 addition & 0 deletions commands/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parseMention } from "../utils/moderation";

const command: CommandSchema = {
name: "ban",
category: "Moderation",
description: "Ban a member from the server.",
params: "<@user|id> [reason...]",
requireElevated: [Permissions.BanMembers],
Expand Down
1 change: 1 addition & 0 deletions commands/bet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getBalance, addBalance, deleteBalance } from "../database";

const command: CommandSchema = {
name: "bet",
category: "Gambling",
description: "Roll a d6 and bet on the outcome. Correct guess pays 5x.",
params: "<amount> <1-6>",
requireElevated: false,
Expand Down
1 change: 1 addition & 0 deletions commands/blackjack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function resolve(k: string, game: BJGame, guildId: string, userId: string,

const command: CommandSchema = {
name: "blackjack",
category: "Gambling",
description: "Play blackjack against the dealer.",
params: "<amount | hit | stand | double>",
requireElevated: false,
Expand Down
1 change: 1 addition & 0 deletions commands/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { CommandSchema } from "../utils/CommandSchema";

const command: CommandSchema = {
name: "coin",
category: "Fun",
description: "Flip a coin.",
requireElevated: false,

Expand Down
1 change: 1 addition & 0 deletions commands/daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { formatDuration } from "../utils/moderation";

const command: CommandSchema = {
name: "daily",
category: "Economy",
description: "Claim your daily coins (150–250, 24h cooldown).",
params: "",
requireElevated: false,
Expand Down
1 change: 1 addition & 0 deletions commands/give.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parseMention } from "../utils/moderation";

const command: CommandSchema = {
name: "give",
category: "Economy",
description: "Give coins to another user.",
params: "<@user|id> <amount>",
requireElevated: false,
Expand Down
60 changes: 42 additions & 18 deletions commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,65 @@
import { EmbedBuilder } from "@fluxerjs/core";
import type { CommandSchema } from "../utils/CommandSchema";
import { Permissions, PERM_BITS } from "../utils/CommandSchema";
import * as commands from "./index";

const allCommands = () => Object.values(commands) as CommandSchema[];

const CATEGORIES: { label: string; names: string[] }[] = [
{ label: "Moderation", names: ["kick", "ban", "unban", "timeout", "untimeout", "warn", "unwarn", "warnings"] },
{ label: "Economy", names: ["balance", "daily", "give"] },
{ label: "Leveling", names: ["rank", "leaderboard"] },
{ label: "Gambling", names: ["bet", "blackjack", "highlow", "roulette", "slots"] },
{ label: "Fun", names: ["8ball", "coin", "roll"] },
{ label: "General", names: ["about", "ping", "help"] },
];
const CATEGORY_ORDER = ["Moderation", "Economy", "Leveling", "Gambling", "Fun", "General"];

const command: CommandSchema = {
name: "help",
category: "General",
description: "List all commands or get info on a specific one.",
params: "[command]",
requireElevated: false,

async run(params, message) {
if (params.length === 0) {
const cmds = allCommands();
let userPerms = 0n;
let botPerms = 0n;
if (message.guildId && message.guild) {
try {
const [member, botMember] = await Promise.all([
message.guild.fetchMember(message.author.id),
message.guild.fetchMember(message.client.user!.id),
]);
userPerms = member.permissions.bitfield;
botPerms = botMember.permissions.bitfield;
} catch {}
}

const hasPerms = (perms: bigint, required: Permissions[]) =>
required.every((p) => {
const bit = PERM_BITS[Permissions[p]];
return bit === undefined || (perms & bit) !== 0n;
});

const canUse = (cmd: CommandSchema) => {
if (cmd.requireElevated === false) return true;
return hasPerms(userPerms, cmd.requireElevated) && hasPerms(botPerms, cmd.requireElevated);
};

const cmds = allCommands().filter(canUse);

const grouped = new Map<string, CommandSchema[]>();
for (const cmd of cmds) {
const cat = cmd.category ?? "Other";
if (!grouped.has(cat)) grouped.set(cat, []);
grouped.get(cat)!.push(cmd);
}

const known = CATEGORY_ORDER.filter((c) => grouped.has(c));
const extra = [...grouped.keys()].filter((c) => !CATEGORY_ORDER.includes(c)).sort();

const embed = new EmbedBuilder()
.setColor(0x2D8A4E)
.setTitle("Capacitor Commands")
.setDescription("Use `c!help <command>` for info on a specific command.");

for (const category of CATEGORIES) {
const lines = category.names
.map((name) => cmds.find((c) => c.name === name))
.filter((c): c is CommandSchema => c !== undefined)
.map((c) => `\`c!${c.name}\` — ${c.description}`);

if (lines.length > 0) {
embed.addFields({ name: category.label, value: lines.join("\n") });
}
for (const cat of [...known, ...extra]) {
const lines = grouped.get(cat)!.map((c) => `\`c!${c.name}\` — ${c.description}`);
embed.addFields({ name: cat, value: lines.join("\n") });
}

await message.reply({ embeds: [embed] });
Expand Down
1 change: 1 addition & 0 deletions commands/highlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { newDeck, cardRank, fmt } from "../utils/cards";

const command: CommandSchema = {
name: "highlow",
category: "Gambling",
description: "Guess if the next card is higher or lower.",
params: "<amount> <high|low>",
requireElevated: false,
Expand Down
5 changes: 4 additions & 1 deletion commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ import blackjack from "./blackjack";
import highlow from "./highlow";
import roulette from "./roulette";
import slots from "./slots";
import optout from "./optout";
import levelchannel from "./levelchannel";
import levelrole from "./levelrole";

export { about, kick, ban, unban, timeout, untimeout, warn, unwarn, warnings, rank, leaderboard, balance, daily, give, eightball, coin, roll, ping, help, bet, blackjack, highlow, roulette, slots };
export { about, kick, ban, unban, timeout, untimeout, warn, unwarn, warnings, rank, leaderboard, balance, daily, give, eightball, coin, roll, ping, help, bet, blackjack, highlow, roulette, slots, optout, levelchannel, levelrole };
1 change: 1 addition & 0 deletions commands/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parseMention } from "../utils/moderation";

const command: CommandSchema = {
name: "kick",
category: "Moderation",
description: "Kick a member from the server.",
params: "<@user|id> [reason...]",
requireElevated: [Permissions.KickMembers],
Expand Down
1 change: 1 addition & 0 deletions commands/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const PAGE_SIZE = 10;

const command: CommandSchema = {
name: "leaderboard",
category: "Leveling",
description: "Show the XP or economy leaderboard for this server.",
params: "",
requireElevated: false,
Expand Down
Loading
Loading