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

Introduce add and remove subcommands #15

Merged
merged 3 commits into from
Apr 13, 2024
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
51 changes: 33 additions & 18 deletions app_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,40 @@ import type { AppSchema } from "shorter/deps.ts";
export const appSchema = {
chatInput: {
name: "shorter",
description: "Shorten a URL",
options: {
alias: {
type: discord.ApplicationCommandOptionType.String,
description: "The alias of the shortlink",
required: true,
description: "Manage shortlinks.",
subcommands: {
add: {
description: "Add a shortlink.",
options: {
alias: {
type: discord.ApplicationCommandOptionType.String,
description: "The alias of the shortlink",
required: true,
},
destination: {
type: discord.ApplicationCommandOptionType.String,
description: "The destination of the shortlink",
required: true,
},
force: {
type: discord.ApplicationCommandOptionType.Boolean,
description: "Whether to overwrite an existing shortlink",
},
ttl: {
type: discord.ApplicationCommandOptionType.String,
description: "The time-to-live of the shortlink",
},
},
},
destination: {
type: discord.ApplicationCommandOptionType.String,
description: "The destination of the shortlink",
required: true,
},
force: {
type: discord.ApplicationCommandOptionType.Boolean,
description: "Whether to overwrite an existing shortlink",
},
ttl: {
type: discord.ApplicationCommandOptionType.String,
description: "The time-to-live of the shortlink",
remove: {
description: "Remove a shortlink.",
options: {
alias: {
type: discord.ApplicationCommandOptionType.String,
description: "The alias of the shortlink",
required: true,
},
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"udd": "deno run -r --allow-read=. --allow-write=. --allow-net https://deno.land/x/udd/main.ts deps.ts && deno task lock",
"lock": "deno cache --lock=deno.lock --lock-write deps.ts",
"all": "deno task udd && deno lint && deno fmt",
"start": "deno run -A main.ts",
"start": "deno run -A --unstable-kv main.ts",
"ngrok": "ngrok http 8080"
},
"imports": {
Expand Down
84 changes: 80 additions & 4 deletions deno.lock

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

6 changes: 3 additions & 3 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * as dotenv from "https://deno.land/std@0.208.0/dotenv/mod.ts";
export * as discord from "https://deno.land/x/[email protected].65/v10.ts";
export * as dotenv from "https://deno.land/std@0.222.1/dotenv/mod.ts";
export * as discord from "https://deno.land/x/[email protected].79/v10.ts";
export * from "https://deno.land/x/[email protected]/github/mod.ts";
export type { GitHubAPIClientOptions } from "https://deno.land/x/[email protected]/github/api/mod.ts";
export { Duration } from "https://deno.land/x/[email protected].0/mod.ts";
export { Duration } from "https://deno.land/x/[email protected].1/mod.ts";
export {
type AppSchema,
createApp,
Expand Down
4 changes: 2 additions & 2 deletions docs/HANDBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ on the [ACM CSUF Discord server](https://acmcsuf.com/discord).
- This slash command is only available to members with the `Board` role.
- This slash command is available in all text channels of the
[ACM CSUF Discord server](https://acmcsuf.com/discord).
- Type `/shorter` in any text channel to use the tool.
- Type `/shorter add` in any text channel to add a new shortlink.
- Populate both required fields `alias` and `destination` with your desired
alias string and destination string, respectively.
- Press <kbd>Enter</kbd> to submit the update.
- Wait for the response from the slash command to confirm the update. This may
take around 3 seconds.
- Wait for redeployment to complete. This may take around 30 seconds.
- Wait for redeployment to complete. This may take up to 60 seconds.

---

Expand Down
6 changes: 6 additions & 0 deletions lib/shorter/shorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export async function shorter(options: ShorterOptions): Promise<ShorterResult> {
}

if (isAliasToBeRemoved) {
if (data[options.data.alias] === undefined) {
throw new Error(
`the alias \`${options.data.alias}\` does not exist`,
);
}

delete data[options.data.alias];
} else {
data[options.data.alias] = options.data.destination;
Expand Down
Loading
Loading