Git Product home page Git Product logo

discordcr's Introduction

docs

discordcr

(The "cr" stands for "creative name".)

discordcr is a minimalist Discord API library for Crystal, designed to be a complement to discordrb for users who want more control and performance and who care less about ease-of-use.

discordcr isn't designed for beginners to the Discord API - while experience with making bots isn't required, it's certainly recommended. If you feel overwhelmed by the complex documentation, try discordrb first and then check back.

Unlike many other libs which handle a lot of stuff, like caching or resolving, themselves automatically, discordcr requires the user to do such things manually. It also doesn't provide any advanced abstractions for REST calls; the methods perform the HTTP request with the given data but nothing else. This means that the user has full control over them, but also full responsibility. discordcr does not support user accounts; it may work but likely doesn't.

Installation

Add this to your application's shard.yml:

dependencies:
  discordcr:
    github: meew0/discordcr

Usage

An example bot can be found here. More examples will come in the future.

A short overview of library structure: the Client class includes the REST module, which handles the REST parts of Discord's API; the Client itself handles the gateway, i. e. the interactive parts such as receiving messages. It is possible to use only the REST parts by never calling the #run method on a Client, which is what does the actual gateway connection.

The example linked above has an example of an event (on_message_create) that is called through the gateway, and of a REST call (client.create_message). Other gateway events and REST calls work much in the same way - see the documentation for what specific events and REST calls do.

Caching is done using a separate Cache class that needs to be added into clients manually:

client = Discord::Client.new # ...
cache = Discord::Cache.new(client)
client.cache = cache

Resolution requests for objects can now be done on the cache object instead of directly over REST, this ensures that if an object is needed more than once there will still only be one request to Discord. (There may even be no request at all, if the requested data has already been obtained over the gateway.) An example of how to use the cache once it has been instantiated:

# Get the username of the user with ID 66237334693085184
user = cache.resolve_user(66237334693085184_u64)
user = cache.resolve_user(66237334693085184_u64) # won't do a request to Discord
puts user.username

Apart from this, API documentation is also available, at https://meew0.github.io/discordcr/doc/v0.1.0/.

Contributing

  1. Fork it (https://github.com/meew0/discordcr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • meew0 - creator, maintainer
  • RX14 - Crystal expert, maintainer

discordcr's People

Contributors

meew0 avatar rx14 avatar z64 avatar andrewzah avatar zatherz avatar greenbigfrog avatar ivan2002 avatar

Watchers

snapcase avatar James Cloos avatar  avatar

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.