diff --git a/lib/content.py b/lib/content.py index 33bc56b..4745494 100644 --- a/lib/content.py +++ b/lib/content.py @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/main.py b/main.py index ccfc36a..469324c 100644 --- a/main.py +++ b/main.py @@ -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: