-
Notifications
You must be signed in to change notification settings - Fork 0
feat(builder): add autoSet and localization for commands #60
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
327a6ac
refactor(builder): simplify context handler and locale resolution
vrdons ef19c37
feat(builder): add autoSet and localization for commands
vrdons b72b69b
Delete ping.cjs
vrdons 83b30fc
Potential fix for pull request finding 'Useless assignment to local v…
vrdons e76e151
fix(builder): prevent mixing subcommands with top-level options
vrdons f0c4dfe
refactor(core): improve command resolution for localization
vrdons a7ff59a
fix fmt
vrdons 312ff5a
feat(parser): add MessageCommandParser with fuzzy alias matching
vrdons 14c2455
fix fmt
vrdons 3f24028
refactor(core)!: remove aliases support and optimize command lookup
vrdons 5c04017
refactor: unify user token handling in report command and i18n
vrdons 4cf186b
feat(i18n): add extensible template parser support
vrdons 32e7c71
fix(utils): improve template token parsing in parseThings
vrdons e9ea555
fix(context): restrict template token resolution to allowed set
vrdons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"))); | ||
| } | ||
vrdons marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ctx.message.reply(safeReply(ctx.t("test:report_prefix"))); | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}}." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}}." | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.