GithubHelp home page GithubHelp logo

botto's Introduction

Botto

A very advanced robot

botto

Usage

  1. Clone this repo

  2. cd botto then npm install --no-optional

  3. Edit config.js according to example.config.js in the root directory

  4. Bring up a fresh postgres database with schema.sql. Seed the database with seed.sql, commenting out any modules you do not want (note: you can also !unmount them while botto is running)

  5. Launch your botto with node botto.js

Design

Botto uses 2 types of listeners when responding to events: commands and observers. the _commandHandler and _observerHandler both act as routing layers to call their respective modules. The modules themselves contain the logic for whatever the module is responsible for. This allows us to easily add/remove/hot-swap modules without having to mess with the routing layer since the modules are pulled in dynamically on message events.

Both commands & observers inherit from their parent class. Child modules will do whatever work they need to, and ultimately return a respond() callback with their response. This callback will respond with the supplied value to the designated receiver as determined by the _*Handler (be it a channel, private message, etc). For an better understanding, check out the observerHandler class.

Commands

Commands are explicit commands that start with the !bang syntax and are all listed under the commands directory. Commands must follow the convention of module name == command name. In other words, if your command trigger is !foo [args], your command module must be named foo.js. Every command must extend the base command class.

Note: By convention, all commands must declare a call function like so:

call(bot, opts, respond) {
 // some code
}

Where opts is the options hash created in the handler and respond is a callback to be fired with the string you wish the bot to echo to the receiver. The bot instance itself is passed for use in admin commands and ignored otherwise. This call function should be used to parse the incoming message and delegate to the appropriate helper functions.

Admin Commands

Admin commands act as normal !bang prefixed commands, but only respond to users who are declared as global or channel-specific admins in config.js.

Observers

Observers are triggered when an observable event happens (a keyword or nickname is mentioned, for example). Each observer instance must declare a matching RegEx in its constructor which it will trigger upon matching incoming message events. Each observer must extend the base observer class. Like commands, each observer must also declare a call function:

call(opts, respond) {
 // some code
}

If you need an observer to fire on every message event, for example building a cache of all recent messages, you should use a regex that captures any message sent: /.*/

DB Schema

Enter psql prompt with psql -d botto.

Import the schema (from psql) with \i db/schema.sql. Old tables will be skipped.

botto's People

Contributors

strong-code avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

botto's Issues

Refactor admin commands to use response callback

Currently admin commands take the entire bot instance and implement their own bot.say() method. This means we don't get the response string back in the commandHandler which means we can't log admin command events correctly. Admin commands should instead take a respond callback like normal commands:

call(bot, opts, respond) {
  return respond(...)
}

!reload should be able to reload broken modules

If a module is reloaded with !reload foo but contains e.g. a syntax error, the module is completely dropped from the require cache and cannot be reloaded/mounted/unmounted until the bot is fully restarted.

Create static MessageCache service

Currently things like sed.js observer implement their own msgCache to keep track of previously typed messages they may need to operate on. With the implementation of things like a quote module, it makes sense to break this out into it's own standalone service rather than living inside a specific module.

Requirements:

  • Store all message data (nick, host, chan, message, time) in cache. A fixed-length array of objects should be fine
  • Fixed length for cache determined by config.js or sensible default (100 msgs?)
  • Static class and operations to mimic singleton functionality
  • Same push/shift logic to stay <= max length

TikTok parser

Parser for username and title data for TikTok observer parser

Log search tool hosted on /web

Create a simple webpage hosted from the /web dir that allows a user to search for a string of text (or regex?) and by channel. Payload should be POSTed to webapp, proxied to botto (cache/db polling? webhook?) who can build a simple grep string and respond with results in channel.

Seed script for database

Create 2 seed scripts for db/ dir:

  1. Seed all existing commands/observers to a "default" state of mounted
  2. Some basic seed data for the remaining db tables for use in bringing up and testing a fresh project

Implement caching service using sidekiq + redis

Implement a caching service with a redis deployment that can be used by other commands/observers. Implement sidekiq for !remind command instead of in-memory reminders. If it makes sense, expand scope to include #18 so that Docker (compose or minikube) brings up botto, postgres and sidekiq/redit.

Dockerfile for botto

Pulling from a lightweight image like node:slim or alpine based node image. Also will need to update server and figure out log management.

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.