GithubHelp home page GithubHelp logo

dragory / knub Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 12.0 2.06 MB

TypeScript framework for creating Discord bots

Home Page: https://knub.zeppelin.gg

TypeScript 100.00%
discord discord-api typescript

knub's People

Contributors

almeidx avatar axisiscool avatar darkview avatar dragory avatar lilybergonzat avatar metal0 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

Watchers

 avatar  avatar  avatar  avatar

knub's Issues

License Question

Hi,

I'm wanting to use Knub in a Discord bot I'm working for my server, we intend for the bot to eventually become open source under the GNU General Public License, however I'm noticing some conflicts on the repository vs the Node Repositories.

The GitHub repository has no explicit license, inferring that is is all rights reserved and we need to discuss a private license, however, the Node Package Manager says the project is licensed under MIT, in which case all I would need to do is state that the project uses libraries which are licensed under MIT (or relicense my project)

Please let me know what's going on and if we need to discuss something privately.

New manifest-based, more functional plugin syntax support

Problems with the current monolithic plugin classes:

  • Messy to compose
    • Mixins would require extra fiddling with types, especially if the mixins call each other
    • Splitting plugin functionality to non-class functions would require manually passing several plugin functions (with context!) as arguments to each function
  • Statically analyzing e.g. commands is mostly an afterthought and only works when using the decorators that add static data to the class
  • One of the original goals of Knub was that you wouldn't necessarily need to use the Plugin base class that is provided but could load any class you wanted. This is still true, but it's clearly not a well-supported workflow, and a lot of Knub functionality is only present in the base Plugin class.
  • No clearly defined way to interact between plugins and define public interfaces. Public class methods on the plugin class are currently the most idiomatic way to do this, but there are several public methods in the base plugin class that shouldn't be called by other plugins (but need to be called by the plugin loader, so need to be public) and plugins might have other reasons to keep their methods public but not usable by other plugins.

Proposed solution:

  • New manifest-based plugin syntax:
    export default {
      id: 'foo-bar',
    
      commands: [
        MyCommand,
        OtherCommand,
        ThirdCommand,
      ],
    
      public: {
        somePublicFn,
        secondPublicFn,
      },
    
      load({ events, config, state }) {
        // The plugin load() function is called with an object that
        // includes functions and objects for the functionality
        // previously included in the base plugin class.
        // 
        // This object is also passed to the command handlers and
        // public functions defined above.
      }
    }
  • Lifecycle hooks (e.g. load()) and command handlers are both called with an object that includes plugin functionality previously included in the base class, such as event handling, config loading, etc.
  • Passing around this object (or parts of it) makes composing plugins out of multiple functions easy
  • Since commands are specified in the manifest, they are easy to analyze for e.g. documentation pages
  • A clearly defined public interface that other plugins can use. These functions also get the object mentioned above passed to them (the calling plugin is not responsible for passing that).
  • A minimal plugin would only contain an id and e.g. a load function or a command, so there's very little overhead/boilerplate to create a plugin

Rough overview of new plugin loading

  • For each guild, create:
    • An event manager
      • = an event emitter that re-emits discord events that match the guild
  • For each plugin, create:
    • A config loader
      • Can be used to load configs with overrides matching specific criteria
    • A plugin event manager
      • A wrapper around the guild's event manager that automatically removes listeners when the plugin is unloaded
    • A plugin command manager
      • A wrapper around knub-command-manager
      • Contains the functionality for running registered commands from a message
    • A cooldown manager
    • A lock manager
    • A state manager
  • To load a plugin:
    • To load a traditional class-based plugin:

      • Pass the above to the plugin's constructor
      • Maintains backwards compatibility (except for the constructor) by using the passed loaders/managers through class methods
    • To load a function-based plugin:

      • Pass the above to the plugin's load() function as an object argument
      • The load() function returns the unload function

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.