Coder Social home page Coder Social logo

abkwreu / kotoba Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mistval/kotoba

0.0 0.0 0.0 353.11 MB

A Discord bot for helping with learning Japanese.

License: MIT License

JavaScript 98.85% Dockerfile 0.19% Shell 0.28% HTML 0.33% CSS 0.35%

kotoba's Introduction

Discord Bots

Kotoba

Kotoba is a project with several semi-independent pieces. Those are:

In addition to the three main projects there are a few other directories:

  • /common - Common code that is intended to be shared between node processes and browser.
  • /node-common - Common code that is intended to be shared between node processes but not browser.
  • /nginx - An nginx configuration for proxying HTTP requests to the frontend and API.
  • /backup - Tools for backing up user data to Google Cloud Storage.
  • /worker - A worker process for doing some heavy lifting for other processes whose event loops should not be blocked.
  • /cloud_functions - The code for HTTP endpoints that can be deployed as cloud functions and which some bot commands rely on.
  • /resources - Dictionaries, fonts, images, and other non-code assets.

Configuration

After cloning the repo (recommend cloning with --depth=1), fill out config/config_sample.js and rename it to config.js. Most of the configuration is optional, but some features may not work right, or not at all, if they are not configured.

Developing

Node v14 is recommended

Discord bot

After following the Configuration instructions above:

Install MongoDB and start it on port 27017 (the default port). You can install it using the instructions for your operating system here. Or, use Docker: docker run -p 27017:27017 mongo. Then:

cd ./bot
npm ci
npm run buildresources # this takes a few minutes
npm start

The bot will start and come online. The npm run buildresources command generally only needs to be run once (unless you change quiz data or such).

KotobaWeb

Install MongoDB and start it on port 27017 (the default port). You can install it using the instructions for your operating system here. Then:

cd ./api
npm ci
npm run buildall
npm start

cd ../kotobaweb
npm ci
npm start

The API will start on port 80 and the React dev server will start on port 3001.

Worker process

The worker process handles some heavy lifting so that the event loop doesn't have to block in the bot or API. The bot and API communicate with it via HTTP. It doesn't do much at the moment, and most features work without it, so you can probably ignore it until you're working with a feature that requires it and you notice that HTTP requests to it are failing.

cd ./worker
npm ci
npm start

Self-hosting the bot

While it is possible to self-host Kotoba, there are some caveats and some of the setup is not straightforward. Before continuing, first consider why you want to self-host. Could you PR your desired features to this repo instead, so they can be added to public Kotoba? I encourage you to take that route if you can. Otherwise, read on.

After following the Configuration instructions higher up in this readme:

sudo apt install docker docker-compose
sudo docker-compose up kotoba-bot kotoba-worker mongo_readwrite

The bot will take some time to build and should then come online. Most things will work. However there is additional setup required for certain features:

Furigana and Hispadic commands

These commands call out to HTTP endpoints that you need to host yourself one way or another. This is done mainly to reduce RAM usage on the main bot server. I use Google Cloud Platform to host these, they have a very generous free tier. The code you need to deploy is in the cloud_functions directory in this repo.

For the furigana command:

  1. Create a new cloud function in the GCP console.
  2. Set the name to something unguessable.
  3. Set the trigger to HTTP.
  4. Check off "Allow unauthenticated invocations".
  5. Set the runtime to Node.js (version probably doesn't matter)
  6. Use the inline editor and paste in the index.js and package.json code.
  7. Set the "function to execute" to getFurigana.
  8. Set maximum function instances to 1.
  9. Deploy the function, get the URL of the HTTP endpoint, and add it to config/config.js.

For the hispadic command:

  1. Create a new cloud function in the GCP console.
  2. Set the name to something unguessable.
  3. Set the trigger to HTTP.
  4. Check off "Allow unauthenticated invocations".
  5. Set the runtime to Node.js (version probably doesn't matter)
  6. Zip the index.js, hispadic.js, and package.json files in cloud_functions/hispadic, and use the "Zip upload" option to upload it to cloud storage (it's too big for the inline editor)
  7. Set the "function to execute" to search.
  8. Set maximum function instances to 1.
  9. Deploy the function, get the URL of the HTTP endpoint, and add it to config/config.js.

Fonts

Most of the fonts in public Kotoba are not in this repo, due to their license conditions. But you can add whatever fonts you want. Just put them in resources/fonts and write meta.json files to describe them. Follow the example of the fonts that are already there.

Other missing functionality

Some quiz decks are not in this repo, and some commands or other functionality also may not be, due to distribution and copyright concerns. If you self-host Kotoba, you will have to survive without some things.

Help

Support

Third party links

Data from the following third parties has been used in Kotoba.

Jisho.org Princeton University Japanese WordNet KanjiVG Forvo Merriam-Webster Oxford Dictionaries Japanese Wiktionary EDICT ENAMDICT Kanjimaji Google Translate YouTube Jonathan Waller's site

In addition various people have contributed quiz data and are credited in the relevant quiz descriptions.

kotoba's People

Contributors

mistval avatar alkhwarizm avatar dependabot[bot] avatar winteryfox avatar ernespa avatar ibluedust avatar ras9929 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.