GithubHelp home page GithubHelp logo

kadahlin / rulediscordbot Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 10.47 MB

Modularized discord bot made with Kotlin and Bazel

License: Apache License 2.0

Kotlin 93.94% Dockerfile 0.17% Starlark 5.73% Shell 0.10% Java 0.06%
kotlin bazel discord-bot

rulediscordbot's Introduction

Rule Discord Bot

Summary

A modularized discord bot written in Kotlin. This project aims to demonstrate usage of a few design decisions:

  • Bazel with domain specific macros to increase developer productivity
  • Coroutine wrappers around a reactive library (Discord4j) to facilitate best practices
  • Combining multiple bazel modules into a single distribution unit (Docker) in a CD environment
  • Using shared kotlin models across the fullstack, a server instance and an android client

Bazel workspace and conventions

Each module is implemented with minimal configuration using domain specific macros. The bot_module macro defined in tools/kotlin.bzl applies common kotlin dependencies and compiler options. This reduces boilerplate when creating a new feature (module). Rule modules leverage this macro inside another macro with common dependencies needed for rules, rule_module. Tests are written the same way. The configuration below demonstrates the setup for a typical rule.

load("//tools:kotlin.bzl", "rule_module", "rule_test")

rule_module(
    name = "wellness_rule",
    deps = [
        "//wellness_models"
    ]
)

rule_test(
    name = "test",
    deps = [
        "//wellness_rule",
        "//wellness_models"
    ]
)

This makes it very simple to add new features with minimal overhead.

Domain specific module breakdown

Code sharing across the stack is demonstrated in the module relation diagram below. Each "rule" is a modular piece of logic that the chatbot packages as functionality. In the example of the "wellness" rule we would like to expose an api to configure the rule, in this case to enable or disable for a particular server. A successful or failed configuration should be communicated to the client with a corresponding response message. This is contained in a simple data class.

@Serializable
data class WellnessResponse(val message: String)

Since this is plain Kotlin (minus the serialization mechanism), we would like to reuse this via a lightweight module across our kotlin codebase without a dependency on any server or discord code. The models for this rule are then split into a seperate bazel module. Being isolated from any rule logic, this becomes a lightweight addition to our client configuration app. The diagram below demonstrates the dependency chart for this rule.

Shared code across server and client

Full breakdown of the graph generated by bazel

rulediscordbot's People

Contributors

kadahlin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.