thananon / twitch_tools

109 stars 27 forks source link

Twitch Tool repo

Repo to keep my community's twitch gadgetries. Join me at www.twitch.tv/armzi.

Projects:

Contribute

📦 Installation

$ git clone https://github.com/thananon/twitch_tools.git
$ cd twitch_tools
$ npm install

🔨 Usage

Use through docker-compose.yml

Change the configuration to your channel and the database path.

version: "3.9"
services:
  9armbot:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
+      - ./9armbot/botstat.json:/twitch_tools/9armbot/botstat.json
+      - ./9armbot/players.json:/twitch_tools/9armbot/players.json
      - type: bind
+        source: ./9armbot/oauth_token
        target: /twitch_tools/9armbot/oauth_token
        read_only: true
    environment:
    - twitch_api=https://tmi.twitch.tv
+    - tmi_username=9armbot
+    - tmi_channel_name=armzi
+    - admin_username=armzi
$ docker-compose up

Use through NodeJs

Change the configuration to your channel in .env file and copy oauth token to 9armbot/oauth_token.

twitch_api="https://tmi.twitch.tv"
+tmi_username="9armbot"
+tmi_channel_name="armzi"
+admin_username="armzi"
$ npm install
$ npm start

More information about oauth_token here.

v2.0.0 (work in progress)

Development workflow

  1. Create Twitch and/or Discord Application, then get OAuth Token
  2. Open .env, modify names and credentials, then save it as .env.local (This file is Git-ignored)
  3. Initiate database by running npm run db:migrate
  4. Start development server npm run dev-2.0
  5. Run tests with npm run test-2.0
  6. See database with npm run db:studio

Migrate from JSON database (players.json)

See json-to-prisma.ts

Debug Console

$ npm run console

Prisma Studio (View database on browser)

$ npm run db:studio

Updating Database Schema

  1. Planning - Update schema.prisma (Docs)
  2. Generate - Run npm run db:generate, name the schema (eg. "Add is_admin field"), SQL migration file will be created.
  3. Inspect - Verify and/or edit .sql file at prisma/migrations
  4. Migrate - Run npm run db:migrate to apply changes to your database (Note: This action cannot be reversed easily without resetting your schema (Ref).)
  5. Commit - Don't forget to Git-commit the migration files.