Giter Site home page Giter Site logo

discord-reminder-bot's Introduction

Discord Reminder Bot

This project was created in order to:

  1. Remind to read my favorite manga
  2. Check price of cryptocurrency
  3. Check my cryptocurrency wallet (in-development feature)
  4. Check the lowest and highest price (in-development feature)
  5. ???

I haven't had many ideas to make it more useful, please feel free to contact me if you have something to improve the bot.

Technology

  • Discord.js V13
  • NodeJS
  • PostgreSQL
  • Prisma (ORM Framework)
  • Puppeteer
  • CoinMarketCap APIs (free version)
  • Cron Job
  • Heroku server

Discord Bot setup

There is a saying: "Don't reinvent the wheel". This means there are a lot of tutorial out there to set up a Discord bot, I don't need to do it again. When I was doing this project, I followed the tutorials below here to complete the task:

  1. Set up a Discord Bot
  2. Send and receive message

In general, they have several steps:

  1. Create an Application in Discord
  2. Create a Discord Bot in the Application
  3. Grant permissions to the Bot and attach it to a Discord Server
  4. Get the Bot's token to our NodeJS server
  5. Sign in using that token in our server (checkout discord.js file)

Database Overview & Setup

In this project, I use Prisma as the ORM Framework (it can connect to both SQL and NoSQL databases with minimal effort). You can easily see the prisma directory, it stores the migration files and database models that our application needs.

There are some models to cover my need:

  • User (contains Discord Id)
  • Manga (contains interesting manga)
  • MangaChapter
  • Reminder
  • Coin (contains interesting coins)
  • PriceUpdate
  • PriceUpdateConversion

Before migrating the database, you need to create a database and prepare the .env file. Subsequently, we can migrate our database and seed data.

Note: You should edit file seed_manga.js and seed_coins.js in your interest.

yarn install  # install node_modules first

npx prisma migrate dev  # migrate all changes in database

npm run db:seed  # seed data

Code structure

  • prisma: Database models, migrations, seeders
  • src:
    • jobs: Cron and non-cron jobs for fetching data
    • parsers: Parse data from website to gather manga data
    • platforms: Serve as connector to Discord and maybe other communicating platforms
    • services: Handle logic and interact with database

Web Crawling

To check the manga available in different websites, web crawling is used periodically with cron jobs. There are many libraries for crawling, but Axios and Puppeteer are my preferable technology. Axios is famously known for request invoking functionality. On the other hand, Puppeteer serves as a headless browser with Chromium API to overcome CDN.

You can see the code here.

Example:

Cryptocurrency notification

I use CoinMarketCap APIs to get the data every 5 minutes and store it into database, you can check this file src/jobs/cryptocurrency/fetch_coin_price.js. It also sends the price update message to me in Discord if time is appropriate.

Example:

In conclusion

Working on this project is so enjoyable. I will optimize and add more features as long as I am still interested in this idea. Thank you guys for reading.

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.