Coder Social home page Coder Social logo

piterdev / markov-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from knownasbot/markov-bot

0.0 0.0 0.0 177 KB

A Discord bot that uses Markov chains :)

Home Page: https://knwbot.gitbook.io/markov-bot/

License: MIT License

TypeScript 100.00%

markov-bot's Introduction

About

Markov BOT is a Discord bot that uses Markov chains to generate random sentences in the chat.

The bot randomly collects messages written by users and builds a probability tree used in the text generation. Firstly it randomly selects a random word and tries to select the most likely next word.

This project is inspired by nMarkov. After it was offline for a while, my friends said me to remake the bot for our guild. They also suggested making it public and I was surprised the bot grew fast.

I also decided to develop this project to study TypeScript and OOP, then make the project source code available to everyone who wants to host their own instance. The code is not the best, but feel free to contribute and improve it.

Depending on when you are reading this, you still can add the bot on your guild: Top.gg page.

Hosting your own instance

If you want to download the code and run it in your own bot or make changes, it's very simple:

Requirements

  • Node.JS v16+;
  • A Discord bot;
  • A MongoDB database;
  • Hosting service (to make the bot be online 24/7) or any device that supports Node.JS.

Configuring the environment

First, you need to install git and then clone this repository with the command git clone https://github.com/knownasbot/markov-bot or by clicking the Download button.

Go inside the repository folder and install the dependencies with npm install. You need to have Node.JS installed on your computer/server.

Copy the file .env.example and rename it to .env. Open the file in a text editor and fill the variables BOT_TOKEN, DB_URI and CRYPTO_SECRET. Variables with # at the beginning are optional.

You need a 128-bit hex string to make the stored texts secure. You can generate it using any tool, or with Crypto module of NodeJS:

crypto.randomBytes(16).toString("hex");
// It will generate strings like:
// '0c98812d1bc43fd95d073eb183ff2087'
// 'f901e4e08421baa5ac096f62512da563'
// '3b982b6a86ce54c015aa0273814a8e9c'
// ...

Pick the generated hex and put it in the CRYPTO_SECRET variable.

Starting the bot

After configuring the environment, build the bot code to JavaScript with the command npm run build. It will be transpiled to the folder ./dist/.

Start the bot with npm start and have fun!

Docker Setup

First you need to have Docker and Docker-Compose installed in you're pc.

  • You can view the Docker Installation Docs be clicking here.
  • Also the Docker Compose Docs can be viewed by clicking here.

After the Docker Setup you need open a terminal inside Docker Folder where you cloned the repo to build the docker container be using docker build --no-cache -t knownasbot/markov-bot ..

When the process of build is finished you can run the bot docker container by using the following method:

  • docker-compose up -d but require you need to change the .env.example to .env and fill the variables BOT_TOKEN, DB_URI and CRYPTO_SECRET like sayed above.

Contributing

If you want to contribute by improving the code or translating texts to other languages, see the Contributing before doing anything.

You can donate to me at my Buy Me A Coffee page. You can also support the contributors on their profiles or by contacting them.

markov-bot's People

Contributors

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