diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f306e66 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-eossystem: pip + directory: / + schedule: + interval: daliy \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..9a2f740 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,34 @@ +name: build CI + +on: + push: + branches: master + workflow_dispatch: + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: [windows,macos,ubuntu] + runs-on: ${{matrix.os}}-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.8 + - name: Install dependencies(for linux) + if: ${{runner.os == 'Linux'}} + run: | + sudo apt-get update + sudo apt-get install python-tk + - name: Install dependencies + run: pip install -r requirements.txt + - name: Build + run: pyinstaller -F -w --hidden-import=PIL._tkinter_finder --additional-hooks-dir=hooks main.py -n vcbot-bili + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: build-${{matrix.os}} + path: ./dist/vcbot-bili \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fdf499 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__pycache__ +.env +build +dist +*.spec \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f4ff49d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python 调试程序: 当前文件", + "type": "debugpy", + "request": "launch", + "program": "main.py", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d9578f5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ + + The MIT License (MIT) + Copyright (c) 2024 luyanci + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/hooks/hook-bilibili_api.py b/hooks/hook-bilibili_api.py new file mode 100644 index 0000000..47b5baf --- /dev/null +++ b/hooks/hook-bilibili_api.py @@ -0,0 +1,3 @@ +from PyInstaller.utils.hooks import collect_data_files + +datas = collect_data_files("bilibili_api") \ No newline at end of file diff --git a/lib/live.py b/lib/live.py new file mode 100644 index 0000000..01fcc81 --- /dev/null +++ b/lib/live.py @@ -0,0 +1,9 @@ +from bilibili_api import Credential,live,Danmaku,sync +from bilibili_api.live import LiveDanmaku,LiveRoom + +def set(room:int,credential:Credential): + global LiveDanma + LiveDanma = LiveDanmaku(room_display_id=room,credential=credential) + global liveroom + liveroom = LiveRoom(room_display_id=room,credential=credential) + return diff --git a/lib/user.py b/lib/user.py new file mode 100644 index 0000000..4919b18 --- /dev/null +++ b/lib/user.py @@ -0,0 +1,13 @@ +import tkinter as tk +from bilibili_api import Credential,login,user +from dotenv import load_dotenv + +def user_login(): + a = login.login_with_qrcode(tk.Tk()) + return a + +async def user_info(uid:int,Credential: Credential): + u = user.User(uid=uid,credential=Credential) + info = await u.get_user_info() + return info + diff --git a/main.py b/main.py new file mode 100644 index 0000000..3e95646 --- /dev/null +++ b/main.py @@ -0,0 +1,48 @@ +import os +import sys +import json +from lib import user,live +from bilibili_api import sync +from dotenv import load_dotenv +roomid = "roomid" +def login(): + global c + c = user.user_login() + try: + c.raise_for_no_sessdata() + c.raise_for_no_bili_jct() + print() + except: + print("error!") + +def main(): + @live.LiveDanma.on('VERIFICATION_SUCCESSFUL') + async def on_successful(event): + await live.liveroom.send_danmaku(danmaku=live.Danmaku(text=roomcfg["connected"])) + print(event) + + @live.LiveDanma.on('DANMU_MSG') + async def on_danmaku(event): + # 收到弹幕. + Uid=event["data"]["info"][2][0] + name=await user.user_info(uid=Uid,Credential=c) + print(name["name"],event["data"]["info"][1]) + + + @live.LiveDanma.on('SEND_GIFT') + async def on_gift(event): + # 收到礼物 + print(json.dumps(event,ensure_ascii=False)) + + sync(live.LiveDanma.connect()) + +if __name__ == "__main__" : + load_dotenv(dotenv_path="./.env") + room=os.environ[roomid] + global roomcfg + roomcfg = json.load(open(f"./{room}.json")) + print(roomcfg) + login() + live.set(room=room,credential=c) + main() + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4ebe648 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +bilibili_api_python==16.2.0 +python-dotenv==1.0.1 +pyinstaller==6.7.0