1 Star 0 Fork 25

薛定谔的猫/懒人原神AI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
danmu.py 7.96 KB
一键复制 编辑 原始数据 按行查看 历史
老大哥 提交于 2024-07-22 21:42 . 1.78开源
import time
import pyautogui
import requests
from lanrentools import moni
class BiLiBiLiDanMu():
def __init__(self,roomid="22744134"):
'''
简单版弹幕获取
:param roomid:
'''
pyautogui.PAUSE = 0.01
pyautogui.FAILSAFE = False
self.roomid=roomid
self.danmu_olds=[]
self.jishi=0
self.zanting=False
self.headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.42'
}
def get_danmu_new(self):
url="https://api.live.bilibili.com/xlive/web-room/v1/dM/gethistory?roomid="+self.roomid+"&room_type=0"
danmu_new=[]
res=requests.get(url,headers=self.headers)
if res.status_code==200:
for item in res.json()["data"]["room"]:
if item not in self.danmu_olds:
#print(item["dm_type"],item["nickname"],f"({item['uid']})",item["text"])
danmu_new.append(item)
if self.danmu_olds==[]:
self.danmu_olds +=danmu_new
if len(self.danmu_olds) >= 200:
self.danmu_olds = self.danmu_olds[50:]
return []
else:
self.danmu_olds +=danmu_new
if len(self.danmu_olds) >= 200:
self.danmu_olds = self.danmu_olds[50:]
return danmu_new
def zheng_gu(self,danmus):
is_cmd=False
for item in danmus:
if "W" in item["text"] or "w" in item["text"] or "前" == item["text"]or "上" == item["text"]:
is_cmd=True
print(f'弹幕操作:{item["nickname"]} 按下 W 2秒')
pyautogui.keyDown("w")
time.sleep(2)
pyautogui.keyUp("w")
elif "A" in item["text"] or "a" in item["text"] or "左" == item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按下 A 2秒')
pyautogui.keyDown("a")
time.sleep(2)
pyautogui.keyUp("a")
elif "S" in item["text"] or "s" in item["text"] or "后" == item["text"]or "下" == item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按下 S 2秒')
pyautogui.keyDown("s")
time.sleep(2)
pyautogui.keyUp("s")
elif "D" in item["text"] or "d" in item["text"] or "右" == item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按下 D 2秒')
pyautogui.keyDown("d")
time.sleep(2)
pyautogui.keyUp("d")
elif "X" in item["text"] or "x" in item["text"] or "松" == item["text"] or "放" == item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按下 X')
pyautogui.keyDown("x")
time.sleep(0.3)
pyautogui.keyUp("x")
elif "space" in item["text"] or "SPACE" in item["text"] or "Space" in item["text"] or "跳" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按一次 跳')
pyautogui.keyDown("space")
time.sleep(0.2)
pyautogui.keyUp("space")
elif "翅膀" in item["text"] or "风之翼" in item["text"] or "滑行" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 开翅膀')
pyautogui.keyDown('space')
time.sleep(0.2)
pyautogui.keyUp('space')
elif "Q" in item["text"] or "q" in item["text"] or "大招" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 释放大招')
pyautogui.keyDown("q")
time.sleep(0.2)
pyautogui.keyUp("q")
elif "E" in item["text"] or "e" in item["text"] or "战技" in item["text"] :
is_cmd = True
if "长按" in item["text"]:
print(f'弹幕操作:{item["nickname"]} 长按战技')
pyautogui.keyDown("e")
time.sleep(1)
pyautogui.keyUp("e")
else:
print(f'弹幕操作:{item["nickname"]} 释放战技')
pyautogui.keyDown("e")
time.sleep(0.2)
pyautogui.keyUp("e")
elif "1" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 切换角色 1 ')
pyautogui.keyDown("1")
time.sleep(0.2)
pyautogui.keyUp("1")
elif "2" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 切换角色 2 ')
pyautogui.keyDown("2")
time.sleep(0.2)
pyautogui.keyUp("2")
elif "3" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 切换角色 3 ')
pyautogui.keyDown("3")
time.sleep(0.2)
pyautogui.keyUp("3")
elif "4" in item["text"] :
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 切换角色 4 ')
pyautogui.keyDown("4")
time.sleep(0.2)
pyautogui.keyUp("4")
elif "F" == item["text"] or "f" == item["text"] or "捡" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 按F')
pyautogui.keyDown("f")
time.sleep(0.2)
pyautogui.keyUp("f")
elif "k" in item["text"] or "K" in item["text"] or "打" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 平A 3次')
pyautogui.leftClick()
moni.mouse_left_down()
time.sleep(0.1)
moni.mouse_left_up()
time.sleep(0.1)
moni.mouse_left_down()
time.sleep(0.1)
moni.mouse_left_up()
time.sleep(0.1)
moni.mouse_left_down()
time.sleep(0.1)
moni.mouse_left_up()
elif "shift" in item["text"] or "Shift" in item["text"] or "SHIFT" in item["text"] or "跑" in item["text"]or "冲刺" in item["text"]:
is_cmd = True
print(f'弹幕操作:{item["nickname"]} 加速 跑一次')
pyautogui.keyDown("shift")
time.sleep(0.3)
pyautogui.keyUp("shift")
elif "暂停" in item["text"] or "F8" in item["text"] or "f8" in item["text"]:
is_cmd = True
if self.zanting:
self.zanting=False
print(f'弹幕操作:{item["nickname"]} 按F8 继续')
self.jishi = 0
else:
self.zanting=True
print(f'弹幕操作:{item["nickname"]} 按F8 暂停 15秒后恢复')
self.jishi =100
pyautogui.keyDown("F8")
time.sleep(0.1)
pyautogui.keyUp("F8")
time.sleep(0.4)
pyautogui.keyUp("w")
if is_cmd==False:
time.sleep(0.2)
if __name__ == '__main__':
roomid=input("请输入直播间号:")
if len(roomid)<=4:
roomid="22744134"
danmu=BiLiBiLiDanMu(roomid)
while True:
danmu.zheng_gu(danmu.get_danmu_new())
if danmu.zanting:
danmu.jishi-=1
if danmu.jishi <=0:
print("系统操作:自动恢复AI托管")
pyautogui.keyDown("F8")
time.sleep(0.1)
pyautogui.keyUp("F8")
danmu.jishi=0
danmu.zanting=False
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/DkHome/lanren-genshin-impact-ai.git
git@gitee.com:DkHome/lanren-genshin-impact-ai.git
DkHome
lanren-genshin-impact-ai
懒人原神AI
master

搜索帮助