Coder Social home page Coder Social logo

louis70109 / twitch-bot Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 2.0 10.4 MB

🤖 基於 Bottender 建立查詢 Twtich 直播的 LINE bot

Home Page: https://line.me/R/ti/p/%40eae1476b

License: MIT License

JavaScript 25.94% TypeScript 68.52% Dockerfile 0.53% Shell 0.84% EJS 4.18%
twitch line facebook bottender bot

twitch-bot's Introduction

為什麼要用 Twitch Bot 👾

使用電腦看的時候我們可以用 Ad Block 這類的擴充工具來擋廣告,但使用手機的 APP 安裝外掛就很麻煩,

此時有朋友在 LINE 裡面傳 Twitch 直播給我看,意外的發現在 APP 上開網頁看直播是不會廣告襲擊!!

因此這隻 Twitch Bot 就誕生啦 🎉,目前支援 LINE Bot,可以透過指令綁定帳號查詢追隨最多人看的遊戲查詢特定遊戲以及綁定推播功能。

加入好友

QRcode

掃描 QR code 或是點選我!!

加入好友

截圖

指令使用

  • 綁定帳號: 綁定 TWITCH_ACCOUNT
    • ex: 綁定 relaxing234
  • 查詢追隨: follow / 追隨
    • 前置動作: 須先綁定帳號才可查詢
  • 最多人看的遊戲: top / 遊戲
  • 連結 LINE Notify: 點選我

更多介紹參考 我的文章

Developer setup

主要工具

試玩

Clone 圖奇獸 下來!

git clone https://github.com/louis70109/Twitch-Bot.git

使用環境變數: .env

.env.sample 改成 .env 並把對應的 key 放入。

cp .env.sample .env

LINE

Bot 的金鑰

  • Secret key

  • Access token

Notify

參考我文章的這部分

Twitch

TWITCH_ACCESS_TOKEN: OAuth key 在這邊申請

申請完後將 oauth: 後的 key 透過官方文件的 Validating requests 指令放入 access token 中取得 Client_id,如下:

curl -H "Authorization: OAuth <access token>" https://id.twitch.tv/oauth2/validate

本專案的 TWITCH_CLIENT_ID 的環境變數就是這個回傳值中的 client_id

啟動

Normal

  • 先用 yarn installnpm install 來安裝相依套件
  • 開啟另一個視窗執行 tsc -w,它會幫忙編譯並且即時監聽
  • 啟動服務方法:
    1. npx bottender dev: 執行程式,或是加上 --console 讓你可以在終端機上直接測試 Bot 的行為。
    2. npm run dev: 則是有完整的 LINE API 使用功能(NotifyLIFF),需要前端顯示的則需要透過這個指令啟動 server。

使用 npx bottender dev 時會幫你建立 LINE 的 webhook URL 了。

若是使用 express 來啟動的話(預設 5000 port) 則是需要額外開個視窗啟動 ngrok 來幫忙建立一個暫時的 https 網址喔!!

npx ngrok http 5000

然後將 LINE webhook url 複製到你的機器人開發者頁面中。

也可以使用 Docker

若要試玩 Docker 的話可以使用以下指令

docker-compose up -d # 啟動服務於背景
docker ps            # 查看服務狀態

開啟另一個視窗執行ngrok將 port 導出去

npx ngrok http 5000

再將網址複製到對應的平台設定上即可!

在 container 裡也是讀取.env,要記得設定檔案。


👾👾👾 現在你可以好好的去試玩 Twitch Bot 了 🎉🎉🎉

LICENSE

MIT

twitch-bot's People

Contributors

chentsulin avatar dependabot[bot] avatar imgbotapp avatar louis70109 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

chentsulin tailin

twitch-bot's Issues

增加 LINE Notify 推播

按下 follow 之後出現的直撥要能出現推播的按鈕

未綁定 notify

  • flex message 綁定推播 的按鈕為綠色
  • 按下去後出現 LIFF page 供使用者註冊 Notify

已綁定

flex message 綁定直播文字會變成 紅色取消推播

  • 需增加 express 來產生 notify 註冊頁面

腳本

推播用

  • 設定 Heroku 每三十分鐘搜尋一次
  • 只要推播過後當天就不再推播(更新資料庫)

刷新資料庫

  • 每天半夜刷新推播紀錄

Twitch id and token can not use

[HTTPStatusCodeError: Encountered HTTP status code 401: Unauthorized

Body:
{
"error": "Unauthorized",
"status": 401,
"message": "Client ID and OAuth token do not match"
}] {
_statusCode: 401,
_body: {
error: 'Unauthorized',
status: 401,
message: 'Client ID and OAuth token do not match'
}
}

style: 改善寫法

  • 用到 mongo 的變數要加入$字號
  • 參數重複的地方可以參考
const {
  CLIENT_ID,
  CLIENT_SECRET
} = process.env;
  • __tests__ 放進 src/

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.