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
23 changes: 0 additions & 23 deletions examples/basic_client/commands/ping.cjs

This file was deleted.

102 changes: 102 additions & 0 deletions examples/basic_client/commands/report.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const {
Command,
ApplicationCommandBuilder,
MessageCommandParser,
sanitizeDiscordText,
} = require("../../../dist/index.cjs");

const safeReply = (content) => ({
content,
allowedMentions: { parse: [] },
});

module.exports = new Command({
data: new ApplicationCommandBuilder()
.autoSet("report")
.addSubcommand((sub) =>
sub
.autoSet("summary")
.addUserOption((opt) => opt.autoSet("member"))
.addNumberOption((num) => num.autoSet("days"))
)
.addSubcommandGroup((group) =>
group.autoSet("admin").addSubcommand((sub) => sub.autoSet("reset"))
),
onInteraction: (ctx) => {
const group = ctx.interaction.options.getSubcommandGroup(false);
const subcommand = ctx.interaction.options.getSubcommand(false);

if (group === "admin" && subcommand === "reset") {
return ctx.interaction.reply(safeReply(ctx.t("test:report_admin_reset")));
}

if (subcommand === "summary") {
const member = ctx.interaction.options.getUser("member", false);
const days = ctx.interaction.options.getNumber("days", false) ?? 7;
return ctx.interaction.reply(
safeReply(
ctx.t("test:report_summary", {
member: sanitizeDiscordText(
member?.username ?? ctx.interaction.user.username
),
days,
})
)
);
}

return ctx.interaction.reply(safeReply(ctx.t("test:report_ready")));
},
onMessage: (ctx) => {
const parser = new MessageCommandParser(ctx);
const first = ctx.args[0];
if (!first) {
return ctx.message.reply(safeReply(ctx.t("test:report_prefix")));
}

const summaryMatch = parser.matchesArg(
0,
"command:report.subcommand.summary.alias",
["summary"],
{ useFuzzy: true, maxDistance: 1 }
);
const adminMatch = parser.matchesArg(
0,
"command:report.group.admin.alias",
["admin"],
{ useFuzzy: true, maxDistance: 1 }
);
const resetMatch = parser.matchesArg(
1,
"command:report.group.admin.subcommand.reset.alias",
["reset"],
{ useFuzzy: true, maxDistance: 1 }
);

if (summaryMatch) {
const days = parser.parseIntegerOption({
key: "command:report.subcommand.summary.number.days.alias",
fallbackAliases: ["days"],
defaultValue: 7,
startIndex: 0,
useFuzzy: true,
maxDistance: 1,
});

return ctx.message.reply(
safeReply(
ctx.t("test:report_summary", {
member: sanitizeDiscordText(ctx.message.author.username),
days,
})
)
);
}

if (adminMatch && resetMatch) {
return ctx.message.reply(safeReply(ctx.t("test:report_admin_reset")));
}

return ctx.message.reply(safeReply(ctx.t("test:report_prefix")));
},
});
5 changes: 3 additions & 2 deletions examples/basic_client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const __dirname = path.dirname(__filename);

const myinstance = i18next.createInstance({
supportedLngs: ["en-US", "tr"], // Required to be `${Locale}` (LocaleString)
preload: ["en-US", "tr"], // Ensure command localizations are generated from all locales
fallbackLng: "en-US",
defaultNS: "translation",
ns: ["translation", "test", "error"],
ns: ["translation", "test", "error", "command"],
backend: {
loadPath: path.join(__dirname, "locales/{{lng}}/{{ns}}.json"),
},
Expand All @@ -23,6 +24,7 @@ const myinstance = i18next.createInstance({
myinstance.use(backend);

const client = new arox.Client({
autoRegisterCommands: true,
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
Expand All @@ -36,7 +38,6 @@ const client = new arox.Client({
logger: {
level: arox.LogLevel.Debug,
},
autoRegisterCommands: false,
i18n: myinstance,
});

Expand Down
42 changes: 42 additions & 0 deletions examples/basic_client/locales/en-US/command.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"report": {
"name": "report",
"alias": ["report"],
"description": "Generate a report",
"subcommand": {
"summary": {
"name": "summary",
"alias": ["summary", "sum"],
"description": "Show summary data",
"user": {
"member": {
"name": "member",
"alias": ["member", "user"],
"description": "Member to include"
}
},
"number": {
"days": {
"name": "days",
"alias": ["days", "day"],
"description": "Number of days"
}
}
}
},
"group": {
"admin": {
"name": "admin",
"alias": ["admin"],
"description": "Admin group",
"subcommand": {
"reset": {
"name": "reset",
"alias": ["reset"],
"description": "Reset settings"
}
}
}
}
}
}
5 changes: 4 additions & 1 deletion examples/basic_client/locales/en-US/test.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"hello": "Hello {{user}}"
"report_ready": "Report command is ready, {{user.name}}.",
"report_summary": "Summary for {{member}} over {{days}} days was generated by {{user.name}}.",
"report_admin_reset": "Report settings were reset by {{author.name}}.",
"report_prefix": "Use /report summary days:<number> for detailed output, {{user.name}}."
}
42 changes: 42 additions & 0 deletions examples/basic_client/locales/tr/command.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"report": {
"name": "rapor",
"alias": ["rapor"],
"description": "Rapor olusturur",
"subcommand": {
"summary": {
"name": "ozet",
"alias": ["ozet", "özet"],
"description": "Ozet verisini gosterir",
"user": {
"member": {
"name": "uye",
"alias": ["uye", "üye"],
"description": "Dahil edilecek uye"
}
},
"number": {
"days": {
"name": "gun",
"alias": ["gun", "gün", "gunler", "günler"],
"description": "Gun sayisi"
}
}
}
},
"group": {
"admin": {
"name": "yonetim",
"alias": ["yonetim", "yönetim"],
"description": "Yonetim grubu",
"subcommand": {
"reset": {
"name": "sifirla",
"alias": ["sifirla", "sıfırla"],
"description": "Ayarları sıfırlar"
}
}
}
}
}
}
6 changes: 6 additions & 0 deletions examples/basic_client/locales/tr/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"report_ready": "Rapor komutu hazir, {{user.name}}.",
"report_summary": "{{member}} icin {{days}} gunluk ozet {{user.name}} tarafindan olusturuldu.",
"report_admin_reset": "Rapor ayarlari {{author.name}} tarafindan sifirlandi.",
"report_prefix": "Detay icin /report summary days:<sayi> kullan, {{user.name}}."
}
10 changes: 10 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"scripts": {
"prepare": "node scripts/prepareHusky.js",
"test": "echo \"Error: no test specified\" && exit 1",
"check": "oxfmt --check && oxlint --type-aware --type-check",
"check": "oxlint --type-aware --type-check && oxfmt --check",
"format": "oxfmt",
"build:js": "node ./scripts/build.js",
"build:dts": "tsc --emitDeclarationOnly && tsc-alias -p tsconfig.json && node ./scripts/createCjsTypes.js",
Expand All @@ -51,6 +51,7 @@
"@sapphire/timestamp": "^1.0.5",
"colorette": "^2.0.20",
"fast-glob": "^3.3.3",
"fastest-levenshtein": "^1.0.16",
"i18next": "^25.8.0"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion src/events/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export default new EventBuilder(Events.InteractionCreate, false).onExecute(
async function (context, interaction) {
if (!interaction.isChatInputCommand()) return;

const command = context.client.commands.get(interaction.commandName);
const command = context.client.resolveInteractionCommand(
interaction.commandName
);
const ctx = new Context(context.client, { interaction });

if (!command) {
Expand Down
9 changes: 2 additions & 7 deletions src/events/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ export default new EventBuilder(
return;

const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift()?.toLowerCase();
const commandName = args.shift();
if (!commandName) return;

const commandAlias = context.client.aliases.findKey((cmd) =>
cmd.has(commandName)
);
const ctx = new Context(context.client, { message, args });

const command = context.client.commands.get(commandAlias ?? commandName);
const command = context.client.resolveMessageCommand(commandName);

if (!command) {
await message
Expand Down
Loading
Loading