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

Commit

Permalink
feat:送礼/投喂
Browse files Browse the repository at this point in the history
  • Loading branch information
luyanci committed Jun 7, 2024
1 parent 8199aa3 commit c7ed66f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
18 changes: 16 additions & 2 deletions lib/content.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
from . import user
from bilibili_api import Credential
import main

def get_danmaku_content(event:str):
uid=event["data"]["info"][2][0]
#name= user.user_info(uid=uid,Credential=main.c)
content=event["data"]["info"][1]
print(content)
#print(name["name"],content)
try:
contents=main.config.roomcfg["chat"][f"{uid}"]["command"][content]
except:
print(contents)
return contents
return contents

def get_danmaku_ongift(event:str,credential:Credential):
info = event['data']['data']
uid = info['uid']
giftname=info['giftName']
name= info['sender_uinfo']['base']['name']
try:
contents=str(main.config.roomcfg["chat"]["global"]["events"]['gifts'])
contented=contents.replace(" {user} ",f"{name}")
except:
print(contented)
raise

return contented
26 changes: 25 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ def login():
def main():
@live.LiveDanma.on('VERIFICATION_SUCCESSFUL')
async def on_successful(event):
await live.liveroom.send_danmaku(danmaku=live.Danmaku(text=config.roomcfg["connected"]))
# 连接成功
try:
await live.liveroom.send_danmaku(danmaku=live.Danmaku(text=config.roomcfg["connected"]))
except:
print("connect command not found!")
print(event)

@live.LiveDanma.on('DANMU_MSG')
Expand All @@ -52,15 +56,35 @@ async def on_danmaku(event):
print(json.dumps(event,ensure_ascii=False))
print(name["name"],event["data"]["info"][1])

@live.LiveDanma.on('WELCOME')
async def welcome(event):
# 老爷进入直播间
print(json.dumps(event,ensure_ascii=False))

@live.LiveDanma.on('INTERACT_WORD')
async def on_welcome(event):
# 用户进入直播间
print(json.dumps(event,ensure_ascii=False))

@live.LiveDanma.on('WELCOME_GUARD')
async def on_welcome_guard(event):
# 房管进入直播间
print(json.dumps(event,ensure_ascii=False))

@live.LiveDanma.on('SEND_GIFT')
async def on_gift(event):
# 收到礼物,todo
print(json.dumps(event,ensure_ascii=False))
text = content.get_danmaku_ongift(event=event,credential=c)
try:
await live.liveroom.send_danmaku(danmaku=live.Danmaku(text=text))
except:
print("\n")

sync(live.LiveDanma.connect())

if __name__ == "__main__" :

config.loadroomcfg()
print(config.roomcfg)
login()
Expand Down

0 comments on commit c7ed66f

Please sign in to comment.