Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands command #195

Merged
merged 10 commits into from
Apr 23, 2024
8 changes: 6 additions & 2 deletions src/commands-message/general/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { slashCommandsIds } from "@utils/cache";
import type { MessageCommand } from "@type/commands";
import type { Message } from "@lilybird/transformers";

export default {
name: "config",
description: "Changes the config files of the user",
details: `score_embeds: Use this argument to change the size of your embeds.
mode: Change your default osu! mode. This will make it so when you use osu-related commands, it will default to your mode.
embed_type: Hanami has an amazing feature where you can pick the embeds of other bots. Give it a try!`,
usage: `/config score_embeds: Maximized
/config mode: osu`,
cooldown: 1000,
run: async ({ message }: { message: Message }) => {
run: async ({ message }) => {
await message.reply(`This command has been deprecated. Use ${slashCommandsIds.get("config")}instead.`);
}
} satisfies MessageCommand;
6 changes: 3 additions & 3 deletions src/commands-message/general/invite.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { MessageCommand } from "@type/commands";
import type { Message } from "@lilybird/transformers";

export default {
name: "invite",
description: "Get an invite link of the bot.",
description: "Gives you an invite link of the bot.",
usage: "/invite",
cooldown: 1000,
run: async ({ message }: { message: Message }) => {
run: async ({ message }) => {
const links = {
invite: "https://discord.com/oauth2/authorize?client_id=995999045157916763&permissions=265216&scope=bot",
vote: "https://top.gg/bot/995999045157916763"
Expand Down
6 changes: 3 additions & 3 deletions src/commands-message/general/ping.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { client } from "@utils/initalize";
import type { MessageCommand } from "@type/commands";
import type { Message } from "@lilybird/transformers";

export default {
name: "ping",
description: "pong!!",
description: "pings the bot and sees if it's alive!",
usage: "/ping",
cooldown: 1000,
run: async ({ message }: { message: Message }) => {
run: async ({ message }) => {
const newMessage = await message.reply({
content: "🏓..."
});
Expand Down
10 changes: 7 additions & 3 deletions src/commands-message/general/prefix.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { slashCommandsIds } from "@utils/cache";
import type { MessageCommand } from "@type/commands";
import type { Message } from "@lilybird/transformers";

export default {
name: "prefix",
description: "pong!!",
description: "Changes/removes/lists the prefixes in your server",
details: `add: Add a prefix to your server. (max 10)
remove: Removes a prefix from your server.
list: Lists the currently set prefixes in your server.`,
usage: `/prefix add: >
/prefix list`,
cooldown: 1000,
run: async ({ message }: { message: Message }) => {
run: async ({ message }) => {
await message.reply(`This command has been deprecated. Use ${slashCommandsIds.get("prefix")} instead.`);
}
} satisfies MessageCommand;
5 changes: 3 additions & 2 deletions src/commands-message/general/vote.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { MessageCommand } from "@type/commands";
import type { Message } from "@lilybird/transformers";

export default {
name: "vote",
description: "Vote for the bot.",
details: "Help me out by voting for my bot in top.gg!",
usage: "/vote",
cooldown: 1000,
run: async ({ message }: { message: Message }) => {
run: async ({ message }) => {
const voteLink = "https://top.gg/bot/995999045157916763";

await message.reply({
Expand Down
13 changes: 13 additions & 0 deletions src/commands-message/help/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { commandBuilder } from "@builders/simple/command";
import type { MessageCommand } from "@type/commands";

export default {
name: "command",
description: "Get info about commands.",
details: "use `name: commandname` to gain information on a specific command.",
usage: "/command",
cooldown: 1000,
run: async ({ message, args }) => {
await message.reply({ embeds: commandBuilder(args[0]) });
}
} satisfies MessageCommand;
4 changes: 2 additions & 2 deletions src/commands-message/help/help.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { helpBuilder } from "@builders/index";
import type { MessageCommand } from "@type/commands";
import type { Message } from "@lilybird/transformers";

export default {
name: "help",
description: "Get info about the bot.",
usage: "/help",
cooldown: 1000,
run: async ({ message }: { message: Message }) => {
run: async ({ message }) => {
await message.reply({ embeds: helpBuilder() });
}
} satisfies MessageCommand;
1 change: 1 addition & 0 deletions src/commands-message/osu/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { MessageCommand } from "@type/commands";
export default {
name: "avatar",
description: "Display the profile of a user.",
usage: "/avatar",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
1 change: 1 addition & 0 deletions src/commands-message/osu/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
name: "background",
aliases: ["bg", "background"],
description: "Display background of a beatmap.",
usage: "/background",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
1 change: 1 addition & 0 deletions src/commands-message/osu/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { MessageCommand } from "@type/commands";
export default {
name: "banner",
description: "Display the banner of a user.",
usage: "/banner",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
1 change: 1 addition & 0 deletions src/commands-message/osu/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default {
name: "compare",
aliases: Object.keys(modeAliases),
description: "Display play(s) of a user on a beatmap.",
usage: "/compare",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
2 changes: 2 additions & 0 deletions src/commands-message/osu/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default {
name: "leaderboard",
aliases: Object.keys(modeAliases),
description: "Display the leaderboard of a beatmap.",
details: "Only `leaderboard` and `lb` aliases are used for global commands. The rest of the aliases are for Turkish leaderboards.",
usage: "/leaderboard",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
1 change: 1 addition & 0 deletions src/commands-message/osu/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { MessageCommand } from "@type/commands";
export default {
name: "link",
description: "Link your osu! account",
usage: "/link",
cooldown: 1000,
run: async ({ message }: { message: Message }) => {
await message.reply(`This command has been deprecated. Use ${slashCommandsIds.get("link")} instead.`);
Expand Down
1 change: 1 addition & 0 deletions src/commands-message/osu/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
name: "beatmap",
aliases: ["beatmap", "map", "m"],
description: "Display statistics of a beatmap.",
usage: "/map",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
2 changes: 2 additions & 0 deletions src/commands-message/osu/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default {
name: "profile",
aliases: ["osu", "mania", "taiko", "fruits"],
description: "Display statistics of a user.",
details: "You can specify the mode by using the `mod` flag in slash commands.",
usage: "/osu",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
21 changes: 14 additions & 7 deletions src/commands-message/osu/recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ const modeAliases: Record<string, { mode: Mode, includeFails: boolean }> = {
recentpasscatch: { mode: Mode.FRUITS, includeFails: false }
};

export default {
name: "recent",
aliases: Object.keys(modeAliases),
description: "Display recent play(s) of a user.",
details: `The aliases are split between includes fails, and not includes fails.
\`r\`, \`rs\`, \rt\`, \`rm\`, \`rc\`, \`recent\`, \`recenttaiko\`, \`recentmania\` and \`recentcatch\` include fails, the rest do not.
You can use the \`passes\` argument in slash commands to specify passes.`,
usage: `/recent
/recent mods: DT
/recent passes:true`,
cooldown: 1000,
run
} satisfies MessageCommand;

async function run({ message, args, commandName, index = 0, channel }: { message: Message, args: Array<string>, commandName: string, index: number | undefined, channel: GuildTextChannel }): Promise<void> {
const { mode, includeFails } = modeAliases[commandName];
const { user, mods } = parseOsuArguments(message, args, mode);
Expand Down Expand Up @@ -102,10 +116,3 @@ async function run({ message, args, commandName, index = 0, channel }: { message
mesageDataForButtons.set(sentMessage.id, embedOptions);
}

export default {
name: "recent",
aliases: Object.keys(modeAliases),
description: "Display recent play(s) of a user.",
cooldown: 1000,
run
} satisfies MessageCommand;
3 changes: 3 additions & 0 deletions src/commands-message/osu/recentbest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default {
name: "recentbest",
aliases: Object.keys(modeAliases),
description: "Display a list of best recent play(s) of a user.",
usage: `/recentbest
/recentbest mods: DT
/recentbest passes:true`,
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
6 changes: 6 additions & 0 deletions src/commands-message/osu/recentlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export default {
name: "recentlist",
aliases: Object.keys(modeAliases),
description: "Display a list of recent play(s) of a user.",
details: `The aliases are split between includes fails, and not includes fails.
\`rl\`, \`rlt\`, \rlt\`, \`rlm\`, \`rlc\`, \`recentlist\`, \`recentlisttaiko\`, \`recentlistmania\` and \`recentlistcatch\` include fails, the rest do not.
You can use the \`passes\` argument in slash commands to specify passes.`,
usage: `/recentlist
/recentlist mods: DT
/recentlist passes: true`,
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
1 change: 1 addition & 0 deletions src/commands-message/osu/simulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
name: "simulate",
aliases: ["simulate", "sim", "s"],
description: "Display statistics of a beatmap.",
usage: "/simulate acc: 97 bpm: 230 combo: 900 misses: 7",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
17 changes: 10 additions & 7 deletions src/commands-message/osu/top.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ const modeAliases: Record<string, { mode: Mode }> = {
tctb: { mode: Mode.FRUITS }
};

export default {
name: "top",
aliases: Object.keys(modeAliases),
description: "Display top play(s) of a user.",
usage: `/top
/top mode: fruits`,
cooldown: 1000,
run
} satisfies MessageCommand;

async function run({ message, args, commandName, index, channel }: { message: Message, args: Array<string>, commandName: string, index: number | undefined, channel: GuildTextChannel }): Promise<void> {
const { mode } = modeAliases[commandName];
const { user, mods, flags } = parseOsuArguments(message, args, mode);
Expand Down Expand Up @@ -105,10 +115,3 @@ async function run({ message, args, commandName, index, channel }: { message: Me
mesageDataForButtons.set(sentMessage.id, embedOptions);
}

export default {
name: "top",
aliases: Object.keys(modeAliases),
description: "Display top play(s) of a user.",
cooldown: 1000,
run
} satisfies MessageCommand;
1 change: 1 addition & 0 deletions src/commands-message/osu/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { MessageCommand } from "@type/commands";
export default {
name: "unlink",
description: "Unlink your account from the bot.",
usage: "/unlink",
cooldown: 1000,
run: async ({ message }: { message: Message }) => {
await message.reply(`This command has been deprecated. Use ${slashCommandsIds.get("unlink")} instead.`);
Expand Down
2 changes: 2 additions & 0 deletions src/commands-message/owner/owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { MessageCommand } from "@type/commands";
export default {
name: "owner",
description: "Owner commands.",
details: "no you don't.",
usage: "haha no",
cooldown: 1000,
run
} satisfies MessageCommand;
Expand Down
24 changes: 24 additions & 0 deletions src/commands/help/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { commandBuilder } from "@builders/simple/command";
import { ApplicationCommandOptionType } from "lilybird";
import type { SlashCommand } from "@type/commands";

export default {
data: {
name: "command",
description: "Get information about commands.",
options: [
{
name: "name",
description: "Name of the command you want to get information on.",
type: ApplicationCommandOptionType.STRING
}
]
},
run: async (interaction) => {
await interaction.deferReply();

await interaction.editReply({
embeds: commandBuilder(interaction.data.getString("name"))
});
}
} satisfies SlashCommand;
79 changes: 79 additions & 0 deletions src/embed-builders/simple/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Tables } from "@type/database";
import { getRowCount } from "@utils/database";
import { commandAliases, messageCommands } from "@utils/initalize";
import type { EmbedStructure } from "lilybird";

export function commandBuilder(command: string | undefined): Array<EmbedStructure> {
if (typeof command === "undefined")
return displayAllCommands();

return displayCommandInfo(command);
}

function displayCommandInfo(name: string): Array<EmbedStructure> {
const cmd = messageCommands.get(name) ?? messageCommands.get(commandAliases.get(name) ?? "");
if (typeof cmd === "undefined") {
return [
{
title: "Uh oh.",
description: `Unfortunately, the command \`${name}\` doesn't exist.`
}
];
}

const { default: command } = cmd;

const cooldownSecond = command.cooldown / 1000;
return [
{
title: `${command.name}`,
description: command.description,
fields: [
{
name: "Cooldown",
value: `${cooldownSecond} second${cooldownSecond > 1 ? "s" : ""}`
},
{
name: "Aliases",
value: command.aliases?.join(", ") ?? "`no aliases`",
inline: true
},
{
name: "Usage",
value: command.usage,
inline: false
},
{
name: "Details",
value: command.details ?? "`no details`"
}
]
}
];
}

function displayAllCommands(): Array<EmbedStructure> {
const usedPrefixCommands = getRowCount(Tables.COMMAND);
const usedApplicationCommands = getRowCount(Tables.COMMAND_SLASH);

return [
{
title: "Commands",
description: `**Used prefix commands:** ${usedPrefixCommands}\n**Used application commands:** ${usedApplicationCommands}`,
fields: [
{
name: "Statistics",
value: `**Joined servers:** \`${joinedServers}\`\n**Users linked:** \`${linkedUers}\`\n**Maps in database:** ${downloadedMaps}`
},
{
name: "Commands",
value: `**Used prefix commands:** ${usedPrefixCommands}\n**Used application commands:** ${usedApplicationCommands}`
},
{
name: "Links",
value: `[Official Website](${hanamiWebsite}) | [Invite Link](${inviteLink}) | [top.gg Link](${voteLink})`
}
]
}
];
}
Loading
Loading