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 6a00fcb commit 6fa7c61
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
21 changes: 16 additions & 5 deletions lib/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,34 @@ def get_danmaku_content(event:str):
uid=event["data"]["info"][2][0]
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

def get_danmaku_ongift(event:str):
def get_danmaku_on_gift(event:str):
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}")
content_name=contents.replace(" {user} ",f"{name}")
contented=content_name.replace(" {gift} ",f"{giftname}")
except:
print(contented)
raise

return contented
return contented

def get_danmaku_on_wuser(event:str):
info = event['data']['data']
name= info['uinfo']['base']['name']
try:
contents=str(main.config.roomcfg["chat"]["global"]["events"]['welcome'])
content_name=contents.replace(" {user} ",f"{name}")
except:
print(content_name)
raise

return content_name
22 changes: 15 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,32 @@ async def on_danmaku(event):

@live.LiveDanma.on('WELCOME')
async def welcome(event):
# 老爷进入直播间
print(json.dumps(event,ensure_ascii=False))
# 老爷进入直播间,todo
info=json.dumps(event,ensure_ascii=False)
with open(file="./welcome.json",mode="w",encoding="utf-8") as log:
log.write(info)

@live.LiveDanma.on('INTERACT_WORD')
async def on_welcome(event):
# 用户进入直播间
text=content.get_danmaku_on_wuser(event=event)
try:
await live.liveroom.send_danmaku(danmaku=live.Danmaku(text=text))
except:
print("\n")
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))

# 房管进入直播间,todo
info=json.dumps(event,ensure_ascii=False)
with open(file="./welcome-guard.json",mode="w",encoding="utf-8") as log:
log.write(info)
@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)
text = content.get_danmaku_on_gift(event=event)
try:
await live.liveroom.send_danmaku(danmaku=live.Danmaku(text=text))
except:
Expand Down

0 comments on commit 6fa7c61

Please sign in to comment.