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

feat(server): Add Server Context Support #621

Merged
merged 4 commits into from
Jul 15, 2024

Conversation

KitsuneDev
Copy link
Contributor

This is a straightforward solution to #620, implementing a CommandContext.serverContext property that can be defined by the Server.
CommandContext.serverContext is naturally a generic of the default type unknown, leaving the user responsible for determining its type and handling casts accordingly. This fits with the use case of CloudFlare Workers, as its structure changes depending on how bindings are defined.

Consequently, this PR enables using Durable Objects and D1 databases in bots. Through the use of Durable Objects, many things that could only previously be achieved in stateful workflows can now be achieved in serverless.

@KitsuneDev KitsuneDev requested a review from Snazzah as a code owner June 27, 2024 22:31
@KitsuneDev
Copy link
Contributor Author

By the way, I can also work on documenting this if you'd like. This is a super minimal implementation that I came up with in about an hour to allow me to use D1 in a bot of mine.

@Snazzah
Copy link
Owner

Snazzah commented Jun 28, 2024

I like the implementation, I'd also like to extend this implementation towards the other contexts, you'd probably be better to extend from BaseInteractionContext and move the context down the line.

Another thing I'd like to do as a whole cloudflare worker focused update is to automatically get the variables for the discord app ID, token, and public key while responding to a request, since the env can only be fetched on request. Using this will probably be easier to do that later.

src/servers/cfworker.ts Outdated Show resolved Hide resolved
@KitsuneDev
Copy link
Contributor Author

This does look better! I'll keep playing to see if I can find a way to make type inference work better in a subsequent PR

@Snazzah
Copy link
Owner

Snazzah commented Jul 5, 2024

Cool, the only thing to do now is to put server contexts in BaseInteractionContext so things like autocomplete can make use of it.

@Snazzah Snazzah added type: enhancement New feature or request semver: minor PRs that contain new features and will be on the next minor release scope: servers This has to do something with creating/updating servers scope: components This has something to do with components scope: interactions This has something to do with interactions labels Jul 15, 2024
@Snazzah Snazzah changed the title feat: Add Server Context Support feat(server): Add Server Context Support Jul 15, 2024
@Snazzah Snazzah merged commit a8c799b into Snazzah:master Jul 15, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: components This has something to do with components scope: interactions This has something to do with interactions scope: servers This has to do something with creating/updating servers semver: minor PRs that contain new features and will be on the next minor release type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants