Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
luyanci authored and luyanci committed Jun 6, 2024
0 parents commit aab1eaa
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-eossystem: pip
directory: /
schedule:
interval: daliy
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies(for 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__
.env
build
dist
*.spec
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.

3 changes: 3 additions & 0 deletions hooks/hook-bilibili_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from PyInstaller.utils.hooks import collect_data_files

datas = collect_data_files("bilibili_api")
9 changes: 9 additions & 0 deletions lib/live.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions lib/user.py
Original file line number Diff line number Diff line change
@@ -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

43 changes: 43 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
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 connect():
@live.LiveDanma.on('VERIFICATION_SUCCESSFUL')
async def on_successful(event):
await live.liveroom.send_danmaku(danmaku=live.Danmaku("连接成功!"))

@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__" :
login()
load_dotenv(dotenv_path="./.env")
room=os.environ[roomid]
live.set(room=room,credential=c)
connect()

3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bilibili_api_python==16.2.0
python-dotenv==1.0.1
pyinstaller==6.7.0

0 comments on commit aab1eaa

Please sign in to comment.