-
Notifications
You must be signed in to change notification settings - Fork 0
feat: configuration message #25
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
Open
goestav
wants to merge
38
commits into
main
Choose a base branch
from
feature/configuration-message
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
4814caf
refactor: add structures for configuration message
goestav d0ceedc
refactor: add configuration command
goestav 4071dbb
refactor: add basic settings view
goestav d99c8d1
refactor: support different tables
goestav 28bf0a3
refactor: split command up into subcommands
goestav 5da6eee
refactor: add components and move settings to embed
goestav 48505d5
refactor: remove unused type imports
goestav fa4ede1
refactor: handle text option interactions
goestav 33293a0
refactor: increase formatter line width to 120 characters
goestav dc339a4
refactor: remove unused imports
goestav 2ac43fa
refactor: simplify switch logic for the configuration component
goestav dbc55f4
refactor: add required property to configuration manifest option
goestav eada538
refactor: make not set text more consistent for paragraph text options
goestav f70c89e
refactor: use string select menu for configuration
goestav 523d4ae
refactor: rename interaction-handlers to prompt-user-input
goestav 031cd57
refactor: rename getModalInput to promptModalValue
goestav 51b5761
refactor: remove unused imports
goestav 09e1422
refactor: add find placeholder utility
goestav eb5e4c0
refactor: add placeholder replace utility function
goestav ed74b5e
test: add test for invalid characters inside placeholder name
goestav 3e65150
refactor: update input placeholders for text configuration options
goestav f5f6d6f
refactor: configuration command WIP
goestav 9e2800c
build: bump discord.js dependency
goestav caa6f91
refactor: favor `subtext` from discord.js over custom `smallText` uti…
goestav d42a15a
refactor: track bun lockfile for version control
goestav 1362d16
refactor: fix configuration set logic + improve interaction reply mes…
goestav d71cad1
build: add common-tags dependency
goestav 9f431f2
refactor: handle role configuration options
goestav f610ae4
refactor: improve interaction response message for value reset
goestav 7f46129
refactor: gracefully handle collector timeout
goestav b69a96d
refactor: favor bun's built-in test runner over vitest
goestav 56fcaf0
refactor: rename (guild) config database schema to guild
goestav 62d60bb
refactor: ensure guild exists before running a configuration command
goestav 27268b5
refactor: rename getWhereClause to getConfigurationRowFilter to impro…
goestav 46bf30e
refactor: remove redundant and SQL utility
goestav 8e193c0
refactor: add constant for prompt user input utility
goestav 8407850
refactor: use ephemeral message flag instead of ephemeral boolean
goestav 8af27e9
refactor: fix typescript errors for type imports
goestav 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 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,7 +1,6 @@ | ||
| .DS_Store | ||
|
|
||
| node_modules | ||
| bun.lockb | ||
|
|
||
| .env.* | ||
| !.env.example | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| } | ||
| }, | ||
| "formatter": { | ||
| "indentStyle": "tab" | ||
| "indentStyle": "tab", | ||
| "lineWidth": 120 | ||
| } | ||
| } | ||
Binary file not shown.
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,75 @@ | ||
| import { MessageFlags, PermissionFlagsBits, TextInputStyle } from "discord.js"; | ||
| import { GuildSchema } from "../../schemas/guild.ts"; | ||
| import { createConfigurationManifest } from "../../structures/index.ts"; | ||
| import { ConfigurationMessage } from "../../structures/index.ts"; | ||
| import type { Command } from "djs-fsrouter"; | ||
| import { eq } from "drizzle-orm"; | ||
| import { checkIsValidTextChannel } from "../../utils/index.ts"; | ||
| import { ensureGuild } from "#repository"; | ||
|
|
||
| const manifest = createConfigurationManifest(GuildSchema, [ | ||
| { | ||
| name: "Gateway channel", | ||
| description: "New members will be welcomed here.", | ||
| column: "gatewayChannel", | ||
| type: "channel", | ||
| placeholder: "Select a gateway channel", | ||
| validate: checkIsValidTextChannel, | ||
| }, | ||
| // Join | ||
| { | ||
| name: "Gateway join title", | ||
| description: "Message title when a user joins.", | ||
| column: "gatewayJoinTitle", | ||
| type: "text", | ||
| placeholder: "Welcome [mention]!", | ||
| }, | ||
| { | ||
| name: "Gateway join content", | ||
| description: "Message content when a user joins.", | ||
| column: "gatewayJoinContent", | ||
| type: "text", | ||
| placeholder: "We hope you enjoy your stay!", | ||
| style: TextInputStyle.Paragraph, | ||
| }, | ||
| // Leave | ||
| { | ||
| name: "Gateway leave title", | ||
| description: "Message title when a user leaves.", | ||
| column: "gatewayLeaveTitle", | ||
| type: "text", | ||
| placeholder: "Goodbye [mention]!", | ||
| }, | ||
| { | ||
| name: "Gateway leave content", | ||
| description: "Message content when a user leaves.", | ||
| column: "gatewayLeaveContent", | ||
| type: "text", | ||
| placeholder: "We are sorry to see you go [mention]", | ||
| style: TextInputStyle.Paragraph, | ||
| }, | ||
| ]); | ||
|
|
||
| const ConfigCommand: Command = { | ||
| description: "Configure the gateway", | ||
| defaultMemberPermissions: PermissionFlagsBits.Administrator, | ||
| async run(interaction) { | ||
| if (!interaction.inGuild()) { | ||
| interaction.reply({ | ||
| content: "Run this command in a server to get server info", | ||
| flags: MessageFlags.Ephemeral, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| await ensureGuild(interaction.guildId); | ||
|
|
||
| const configurationMessage = new ConfigurationMessage(manifest, { | ||
| getConfigurationRowFilter: ({ table, interaction }) => eq(table.id, interaction.guildId), | ||
| }); | ||
|
|
||
| await configurationMessage.initialize(interaction); | ||
| }, | ||
| }; | ||
|
|
||
| export default ConfigCommand; |
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,69 @@ | ||
| import { PermissionFlagsBits, type Channel } from "discord.js"; | ||
| import { GuildSchema } from "../../schemas/guild.ts"; | ||
| import { createConfigurationManifest } from "../../structures/index.ts"; | ||
| import { ConfigurationMessage } from "../../structures/index.ts"; | ||
| import { checkIsValidTextChannel } from "../../utils/index.ts"; | ||
| import type { Command } from "djs-fsrouter"; | ||
| import { eq } from "drizzle-orm"; | ||
| import { LogMode } from "../../types/logging.ts"; | ||
| import { ensureGuild } from "#repository"; | ||
|
|
||
| const LogModeValues = Object.keys(LogMode).filter((item) => !Number.isNaN(Number(item))); | ||
|
|
||
| const LogModeSelectOptions = Object.entries(LogMode) | ||
| .filter(([, value]) => typeof value === "number") | ||
| .map(([key, value]) => ({ label: key, value: value.toString() })); | ||
|
|
||
| const manifest = createConfigurationManifest(GuildSchema, [ | ||
| { | ||
| name: "Logging mode", | ||
| description: "Determines what should be logged.", | ||
| column: "loggingMode", | ||
| type: "select", | ||
| placeholder: "Select a logging mode", | ||
| options: LogModeSelectOptions, | ||
| validate(value) { | ||
| if (!LogModeValues.includes(value)) return "The provided logging mode is invalid"; | ||
|
|
||
| return true; | ||
| }, | ||
| toDatabase(value): number { | ||
| return Number.parseInt(value); | ||
| }, | ||
| fromDatabase(value): string { | ||
| return value ? (value as number).toString() : ""; | ||
| }, | ||
| }, | ||
| { | ||
| name: "Logging channel", | ||
| description: "Log messages will be sent here.", | ||
| column: "loggingChannel", | ||
| type: "channel", | ||
| placeholder: "Select a logging channel", | ||
| validate: checkIsValidTextChannel, | ||
| }, | ||
| ]); | ||
|
|
||
| const ConfigCommand: Command = { | ||
| description: "Configure suggestion management", | ||
| defaultMemberPermissions: PermissionFlagsBits.Administrator, | ||
AsyncBanana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async run(interaction) { | ||
| if (!interaction.inGuild()) { | ||
| interaction.reply({ | ||
| content: "Run this command in a server to get server info", | ||
| ephemeral: true, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| await ensureGuild(interaction.guildId); | ||
|
|
||
| const configurationMessage = new ConfigurationMessage(manifest, { | ||
| getConfigurationRowFilter: ({ table, interaction }) => eq(table.id, interaction.guildId), | ||
| }); | ||
|
|
||
| await configurationMessage.initialize(interaction); | ||
| }, | ||
| }; | ||
|
|
||
| export default ConfigCommand; | ||
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,66 @@ | ||
| import { PermissionFlagsBits } from "discord.js"; | ||
| import { GuildSchema } from "../../schemas/guild.ts"; | ||
| import { createConfigurationManifest } from "../../structures/index.ts"; | ||
| import { ConfigurationMessage } from "../../structures/index.ts"; | ||
| import { checkIsValidTextChannel } from "../../utils/index.ts"; | ||
| import type { Command } from "djs-fsrouter"; | ||
| import { eq } from "drizzle-orm"; | ||
| import { ensureGuild } from "#repository"; | ||
|
|
||
| const manifest = createConfigurationManifest(GuildSchema, [ | ||
| { | ||
| name: "Suggestion channel", | ||
| description: "Suggestions will be sent here.", | ||
| column: "suggestionChannel", | ||
| type: "channel", | ||
| placeholder: "Select a suggestion channel", | ||
| validate: checkIsValidTextChannel, | ||
| }, | ||
| { | ||
| name: "Suggestion manager role", | ||
| description: "The role that can approve and reject suggestions.", | ||
| column: "suggestionManagerRole", | ||
| type: "role", | ||
| placeholder: "Select a manager role", | ||
| }, | ||
| { | ||
| name: "Suggestion upvote emoji", | ||
| description: "The emoji for upvoting suggestions.", | ||
| column: "suggestionUpvoteEmoji", | ||
| type: "text", | ||
| label: "Set upvote emoji", | ||
| emoji: "👍", | ||
| }, | ||
| { | ||
| name: "Suggestion downvote emoji", | ||
| description: "The emoji for downvoting suggestions.", | ||
| column: "suggestionDownvoteEmoji", | ||
| type: "text", | ||
| label: "Set downvote emoji", | ||
| emoji: "👎", | ||
| }, | ||
| ]); | ||
|
|
||
| const ConfigCommand: Command = { | ||
| description: "Configure suggestion management", | ||
| defaultMemberPermissions: PermissionFlagsBits.Administrator, | ||
| async run(interaction) { | ||
| if (!interaction.inGuild()) { | ||
| interaction.reply({ | ||
| content: "Run this command in a server to get server info", | ||
| ephemeral: true, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| await ensureGuild(interaction.guildId); | ||
|
|
||
| const configurationMessage = new ConfigurationMessage(manifest, { | ||
| getConfigurationRowFilter: ({ table, interaction }) => eq(table.id, interaction.guildId), | ||
| }); | ||
|
|
||
| await configurationMessage.initialize(interaction); | ||
| }, | ||
| }; | ||
|
|
||
| export default ConfigCommand; |
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
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.
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.