Giter Site home page Giter Site logo

discordcf / discordcf Goto Github PK

View Code? Open in Web Editor NEW
62.0 62.0 10.0 430 KB

Build blazingly fast Discord bots on top of Cloudflare Workers for free! :rocket:

Home Page: https://beta-discordcf-org.pages.dev

License: Apache License 2.0

TypeScript 94.35% JavaScript 5.22% Shell 0.43%
bot cloudflare cloudflare-workers discord typescript

discordcf's Introduction

discord.cf · Github License Github Build Discord Server Repo size

Build blazing fast Discord bots on top of Cloudflare Workers for free! 🚀

Learn how to use discord.cf.

Contributing

Contribution is pretty simple. There are many ways of contributing to it:

  1. Use the module to build your own bots.
  2. In Github Issues, report any defect or feature that it's not supported.
  3. If there's an open issue, create a pull request with your solution.
  4. Spread the word about this little library.

License

Licensed under the Apache License 2.0.

Maintainers

These repo is brought to you by these people! Join us on Discord!

alvgaona Inrixia gzalo

discordcf's People

Contributors

alvgaona avatar inrixia avatar irazasyed avatar scscodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

discordcf's Issues

[Workings] Massive Refactor and additional calls/objects

Been busy with getting the code refactored in a way that makes it easier for use and to help solve the issue of a large types file. (new ./applications folder with files breaking down the types by category). Also been busy with getting more types/interfaces and objects that implements, and handles more of the discord api when information is received. Will work on getting more done.

Question

Can I use this also with javascript?

Provide better error reporting when attempting to setup

Summary

Currently if a error is encountered when attempting to setup a command the only info returned is that setup failed on that command as seen here:
https://github.com/alvgaona/cloudflare-discord-bot/blob/7adf8bc5219d5d4109b708e17924b7132c054a7b/src/setup.ts#L91-L99

Intended Outcome

Provide information from error encountered so its actually possible to debug issues.

How will it work?

Just add the error.message & error.stack to the result. Ideally return a json object with these as fields.

Code of Conduct

  • I agree to follow this project's Code of Conduct

DX: Improve documentation

Summary

There have been some questions on how to set up the bots and we need to improve documentation on that matter.

Intended Outcome

The site is being built but we should also consider adding a FAQ section as well as explaining how the flow to install your bot in a given server.

How will it work?

  • The README file shall have a FAQ section.
  • A section explaining exactly how to set up a bot.
  • A separate README under test explaining how testing is done in discordcf.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Support for deferring a response?

Discord expects a response within 3 seconds, otherwise it fails fails the interaction.

Some other packages support deferring the response while processing is going on, and immediately sends a preliminary response to stop Discord from failing the interaction.

Does this package support such a feature? I could not find it in the source or documentation.

Use discord-api-types as a dependency

Summary

We should not maintain the Discord objects that represent the Discord API. Instead, we should use discord-api-types.

Intended Outcome

The outcome should be:

  • Adapt our core files to use the discord-api-types types, interfaces, and whatnot.
  • Remove the types.ts file.

How will it work?

We should add in the project's dependency tree the latest version of discord-api-types.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Unable to resolve package

Description

When trying to do wrangler publish, I get this error:

✘ [ERROR] Could not resolve "cloudflare-discord-bot"

    src/Discord/index.js:6:7:
      6 │ } from "cloudflare-discord-bot"
        ╵        ~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "cloudflare-discord-bot" as external to exclude it from
  the bundle, which will remove this error.

This is not the case with @glenstack/cf-workers-discord-bot package.

Reproducibility

  • Using the readme example.
  • Using wrangler beta.
  • Worker module type.
  • wrangler publish

Version

0.0.1 (latest)

What browsers are you seeing the problem on?

Chrome

Log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Documentation

Summary

Documentation on functions similar to other Discord Libraries.

Intended Outcome

Docs in production which can be used to find functions or how certain functions work.

How will it work?

Software such as WikiJS or Docasasaurus, etc.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Typo on import

Description

index.ts imports helloHanlder instead of helloHandler

Reproducibility

Install this per README instructions

Version

0.0.1 (latest)

What browsers are you seeing the problem on?

Microsoft Edge

Log output

none, it cannot compile

Code of Conduct

  • I agree to follow this project's Code of Conduct

Expose router base path in `createApplicationCommandHandler`

Summary

I'd like to be able to use this framework in a function in Cloudflare Pages, or potentially host multiple bots on the same worker. This requires adjusting the base path in the bot router, which currently isn't possible.

Intended Outcome

createApplicationCommandHandler should have an optional argument allowing the user to specify the base path, such as the path of their Cloudflare function.

(This could be an optional field in Application, an argument directly to createApplicationCommandHandler, whichever.)

How will it work?

The itty router should be called with e.g. const router = Router({ base: basePath }); inside createApplicationCommandHandler (and not be module-scoped).

Code of Conduct

  • I agree to follow this project's Code of Conduct

Provide access to the environment variable in InteractionHandler

Summary

Currently a InteractionHandler function only gets passed the interaction object.

Ideally it would also be possible to access the environment variables by supporting passing in the env as a optional arg to applicationCommandHandler alongside the request as when using modules env variables are no longer global re https://blog.cloudflare.com/workers-javascript-modules/

Intended Outcome

Be able to access env variables as a argument provided to InteractionHandlers

How will it work?

This would look something like this (simplified example):

export default {
	fetch: async (req: Request, env: EnvInterface) => applicationCommandHandler(req, env),
};

And this for a InteractionHandler:

const helloHandler: InteractionHandler = async (interaction, env: EnvInterface) => {}

The EnvInterface type is a defined type that is used by both pieces of code.

Code of Conduct

  • I agree to follow this project's Code of Conduct

A way to effectively test the whole library

Summary

At the time of the writing, we don't have a good way to run integration tests or any other kind of tests in this project. We should focus on finding a good way to test out all the code layers.

Intended Outcome

I believe we should look for adding:

  • Unit test support
  • Integration/E2E testing.

How will it work?

We need further investigation. Will update the description.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Support Message Components

Summary

Discord release not long ago the possibility to add components to the messages. For more information, take a look at the Discord Developer Portal - Message Components.

This framework should certainly allow easy development of message components as it does for application commands.

Intended Outcome

The message components should be handled the same way as the application commands do.

How will it work?

The Application type and the createApplicationCommandHandler should support components in them.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Embeds

Is there a way to make them?

npm installs without any files

Description

I'm not sure if is because I don't have ssh access or it just needs the dist folder to be committed to work.
After forking and committing the dist folder everything works like charms, thanks!

Screen Shot 2022-02-17 at 10 05 52

Reproducibility

No response

Version

0.0.1 (latest)

What browsers are you seeing the problem on?

No response

Log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

JS Guide

Summary

A JS guide for this

Intended Outcome

Will be useful

How will it work?

The example TS code will be also in JS

Code of Conduct

  • I agree to follow this project's Code of Conduct

Documentation on README doesn't match NPM package

Description

After installing this module with the install command, I tried using the example provided in the README, but it didn't work here:
type ApplicationCommandHandler
I get a typescript error saying: '"cloudflare-discord-bot"' has no exported member named 'ApplicationCommandHandler'. Did you mean 'createApplicationCommandHandler'?

I am using version 0.0.4

Reproducibility

No response

Version

0.0.1 (latest)

What browsers are you seeing the problem on?

No response

Log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Discord API Resources

Discord API Resources Tracker

At the moment this framework supports only a few Discord API resources such as Interactions and a few others.
The purpose of this issue is to track all of those to see what's been implemented, and left to implement.

Motivation

As a framework to build Discord bots using Cloudflare Workers, we'd like to also provide an intuitive API to enhance the developer experience. This means hiding the low-level details that Discord API and Cloudflare Workers bring to the table. Ideally, you should be able to focus on your bot and nothing else than your bot—you'll also need to interact with other Cloudflare and external services if needed, but that's your job.

Resources

It's important to note that if it's not implemented by us, you could still call Discord API directly by just making a request with the proper parameters.

Application Commands

  • Get Global Application Commands.
  • Create Global Application Commands.
  • Edit Global Application Command.
  • Delete Global Application Command.
  • Bulk Override Global Application Commands.
  • Get Guild Application Commands.
  • Create Guild Application Command.
  • Get Guild Application Command.
  • Edit Guild Application Command.
  • Delete Guild Application Command.
  • Bulk Overwrite Guild Application Commands.
  • Get Guild Application Command Permissions.
  • Get Application Command Permissions.
  • Edit Application Command Permissions.
  • Batch Edit Application Command Permissions.

Interactions

Audit Log

  • Get Guild Audit Log.

Auto Moderation

  • List Auto Moderation Rules for Guild.
  • Get Auto Moderation Rule.
  • Create Auto Moderation Rule.
  • Modify Auto Moderation Rule.
  • Delete Auto Moderation Rule.

Channels

  • Get Channel.
  • Modify Channel.
  • Delete/Close Channel.
  • Get Channel Messages.
  • Get Channel Message.
  • Create Message.
  • Crosspost Message.
  • Create Reaction.
  • Delete Own Reaction.
  • Delete User Reaction.
  • Get Reactions.
  • Delete All Reactions.
  • Delete All Reactions for Emoji.
  • Edit Message.
  • Delete Message.
  • Bulk Delete Messages.
  • Edit Channel Permissions.
  • Get Channel Invites.
  • Create Channel Invite.
  • Delete Channel Permission.
  • Follow Announcement Channel.
  • Trigger Typing Indicator.
  • Get Pinned Messages.
  • Pin Message.
  • Unpin Message.
  • Group DM Add Recipient.
  • Group DM Remove Recipient.
  • Start Thread from Message.
  • Start Thread without Message.
  • Start Thread in Forum Channel.
  • Join Thread.
  • Add Thread Member.
  • Leave Thread.
  • Remove Thread Member.
  • Get Thread Member.
  • List Thread Members.
  • List Public Archived Threads.
  • List Private Archived Threads.
  • List Joined Private Archived Threads.

Emoji

  • List Guild Emojis.
  • Get Guild Emoji.
  • Create Guild Emoji.
  • Modify Guild Emoji.
  • Delete Guild Emoji.

Guilds

  • Create Guild.
  • Get Guild.
  • Get Guild Preview.
  • Modify Guild.
  • Delete Guild.
  • Get Guild Channels.
  • Create Guild Channel.
  • Modify Guild Channel Positions.
  • List Active Guild Threads.
  • Get Guild Member.
  • List Guild Members.
  • Search Guild Members.
  • Add Guild Member.
  • Modify Guild Member.
  • Modify Current Member.
  • Modify Current User Nick.
  • Add Guild Member Role.
  • Remove Guild Member Role.
  • Remove Guild Member.
  • Get Guild Bans.
  • Get Guild Ban.
  • Create Guild Ban.
  • Remove Guild Ban.
  • Get Guild Roles.
  • Create Guild Role.
  • Modify Guild Role Positions.
  • Modify Guild Role.
  • Modify Guild MFA Level.
  • Delete Guild Role.
  • Get Guild Prune Count.
  • Begin Guild Prune.
  • Get Guild Voice Regions.
  • Get Guild Invites.
  • Get Guild Integrations.
  • Delete Guild Integration.
  • Get Guild Widget Settings.
  • Modify Guild Widget.
  • Get Guild Widget.
  • Get Guild Vanity URL.
  • Get Guild Widget Image.
  • Get Guild Welcome Screen.
  • Modify Guild Welcome Screen.
  • Modify Current User Voice State.
  • Modify User Voice State.

Guild Scheduled Event

  • List Scheduled Events for Guild.
  • Create Guild Scheduled Event.
  • Get Guild Scheduled Event.
  • Modify Guild Scheduled Event.
  • Delete Guild Scheduled Event.
  • Get Guild Scheduled Event Users.

Guild Template

  • Get Guild Template.
  • Create Guild from Guild Template.
  • Get Guild Templates.
  • Create Guild Template.
  • Sync Guild Template.
  • Modify Guild Template.
  • Delete Guild Template.

Invite

  • Get Invite.
  • Delete Invite.

Stage Instance

  • Create Stage Instance.
  • Get Stage Instance.
  • Modify Stage Instance.
  • Delete Stage Instance.

Sticker

  • Get Sticker.
  • List Nitro Sticker Packs.
  • List Guild Stickers.
  • Get Guild Sticker.
  • Create Guild Sticker.
  • Modify Guild Sticker.
  • Delete Guild Sticker.

User

  • Get Current User.
  • Get User.
  • Modify Current User.
  • Get Current User Guilds.
  • Get Current User Guild Member.
  • Leave Guild.
  • Create DM.
  • Create Group DM.
  • Get User Connections.

Voice

  • List Voice Regions

Webhook

  • Create Webhook.
  • Get Channel Webhooks.
  • Get Guild Webhooks.
  • Get Webhook.
  • Get Webhook with Token.
  • Modify Webhook.
  • Modify Webhook with Token.
  • Delete Webhook.
  • Delete Webhook with Token.
  • Execute Webhook.
  • Execute Slack-Compatible Webhook.
  • Execute GitHub-Compatible Webhook.
  • Get Webhook Message.
  • Edit Webhook Message.
  • Delete Webhook Message.

Update npm package

Description

It's not updated

Reproducibility

Go on https://www.npmjs.com/package/cloudflare-discord-bot and see, it says 7 bmonths ago also if you made a commit 10 days ago on github

Version

0.0.1 (latest)

What browsers are you seeing the problem on?

No response

Log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Use Github Actions to generate deployments

Summary

Having test bots to create E2E smoke tests is a good idea. For that, we need to deploy some bots.

Reference: https://github.com/marketplace/actions/deploy-to-cloudflare-workers-with-wrangler

Intended Outcome

A Github Actions workflow shall be created, which will create a Cloudflare worker in the discordcf account.

How will it work?

We should have the following use cases:

  • Whenever a push event is registered in the main branch, the Worker will be published to the test environment.
  • Whenever a pull request opens up, a new Worker is published to the test environment.
  • Whenever a pull request gets closed, the previously deployed worker shall be erased. The Worker shall somehow be related to the PR number.
  • A manual workflow shall be set up to update any of these environments.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Switch to using discord-api-types

Summary

Currently all the types used in this project are manfully written and need to be maintained by this project.
There is a npm library with TS support for discord api types called discord-api-types. This contains both typescript definitions and actual values and is updated inline with the discord api.

Note the currently this projects types are outdated.

Intended Outcome

Ideally this project should switch to using this library for types.

How will it work?

Just swap existing types with those from the library.
I would be happy to work on a PR to implemented the requested changes.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Don't use 301 redirects

Description

https://github.com/alvgaona/cloudflare-discord-bot/blob/7adf8bc5219d5d4109b708e17924b7132c054a7b/src/authorize.ts#L13-L16
301 redirects are permanent and browsers will hard cache them to the point of not even touching the origin when encountering that url again. This means that if the bot client id changes its impossible for clients to get the new id without manually clearing browser data (and even then that sometimes wont work).

Instead you should use 302

Reproducibility

Create a bot, publish the worker and go to its base url, change the bot's client id/recreate it, go to its base url and get the wrong client id.

Version

0.0.1 (latest)

What browsers are you seeing the problem on?

Chrome

Log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.