Coder Social home page Coder Social logo

discord-bot's Introduction

discord-bot

This is a discord bot that allows you to start a SurrealDB instance associated with a thread or channel and query it.

To run the bot you can either clone it and use

cargo run --release

(note your discord token must be supplied in the environment variables or a .env file)
or use the docker container

docker run -d -e "DISCORD_TOKEN=YOUR_TOKEN_HERE" -e "RUST_LOG=info,surreal_bot=debug" surrealdb/discord-bot

Note RUST_LOG environment variable must be set to an appropriate tracing definition before any output is shown. The recommended default definition is info,surreal_bot=debug, where all dependencies use info and the bot itself is using debug. There's also trace that can be used, for even more verbose output.

Discord commands

User commands

/create

This creates a channel with an associated database instance. By default, all messages in the channel will be sent to the database, unless they are comments.
Optional arguments:

  • premade - choose from premade datasets to load into the instance
  • file - upload a .surql file to import into the database

create_db_thread

This is not a slash command but can be accessed by right-clicking on a message looking under apps and selecting create_db_thread, it will create a thread associated with that message. By default, all messages in the channel will be sent to the database, unless they are comments.

/connect

This creates a database instance and associates it with the channel it is used in.

/load

This command loads data into the instance associated with the channel in which it is used.

/query (/q)

This command queries the database instance associated with the channel. This command is useful when a conversation is happening in a channel with an associated instance, the channel can be configured with /configure_channel so normal messages aren't sent to the database. It also means that the up arrow behaves in a useful manner for rapidly iterating on queries.

/configure_channel

This command allows you to override the configuration for a channel.

  • pretty - whether to use pretty printing
  • json - whether to format output as JSON (SurrealQL is the alternative)
  • require_query - whether the /query command is required, if it's false

Admin commands

/configure

This command is used to initially configure the bot and must be used before any other functionality will work.
It takes the following (mandatory) arguments

  • active - the category for active channels
  • archive - the category for archived channels
  • ttl - the duration (in seconds) after which a channel will be archived
  • timeout - how long a query will be executed before timing out
  • pretty - whether to use pretty printing
  • json - whether to format output as JSON (SurrealQL is the alternative)

/config_update

This command takes the same arguments as the /configure command but optionally, and will update the config for the server with those options.

/clean

This command runs the clean_channel function on the channel in which it is run, dropping the associated database instance, notifying the channel and archiving it.

/clean_all

This command runs clean_channel on all current database instances. PLEASE NOTE: this applies even across servers, and should only be used immediately before shutting the bot down.

discord-bot's People

Contributors

alyti avatar kearfy avatar raphaeldarley avatar tobiemh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

discord-bot's Issues

`/faq` command with a repository of common answers

While #8 is more about how to use the bot itself, this one more focused on guiding people on working with SurrealDB.
Though I am not sure duplicating docs on some of the stuff even if some of the answers can only be found in unreleased docs, is a good idea at all.

show correct surrealdb version used

New embeds show surrealdb version in use, but it's incorrect as it's using DB.version() to retrieve it and depends on the crate releases.

Solutions:

  1. Somehow (build.rs? include_str!(Cargo.toml)?) store the dependency list, parse it for surrealdb version, right now it's a git path, handle that somehow??
  2. Maybe surrealdb crate has another way to true version.
  3. There's probably a cleaner solution for this, need to research.

handle cleanup during graceful shutdown

I added graceful shutdown handler in main, but it doesn't handle exporting all connections right now.
It would be nice to try export them before exiting.

commands to playtest auth schemes

I want to have slash commands that one can use to test out various scope configurations, signup/signin, tokens/authorize.
So one can easily setup a scope, permissions on a table, signup with a command and then run queries under that scope.

`rewrite query` button

Follow-up from #7, lets add another button to query result action row, this button should be labeled Rewrite Query or something similar, name to be decided.

Functionally it should:

  • read the message it was interacted on
  • retrieve the content of the 2* embeds on it
  • open a new big_query modal using the values found the embeds

feature: reconnect command

command that looks at the last database export in a channel and connects a database instance and loads that export

Use embeds and message components for nicer UX

As mentioned in #3, should use embeds for configs, and I am also adding message components for editing them.

I tried to do this yesterday and it was kinda messy, after doing #6 I've gotten used to the codebase a bit so I'll probably try to tackle it again after it's merged (so I have a sane starting point)

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.