mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-21 20:20:05 +08:00
fix bilibili_sub
This commit is contained in:
@@ -132,7 +132,7 @@ def hello() -> str:
|
|||||||
(
|
(
|
||||||
"哦豁?!",
|
"哦豁?!",
|
||||||
"你好!Ov<",
|
"你好!Ov<",
|
||||||
f"库库库,呼唤{list(get_bot().config.nickname)[0]}做什么呢",
|
f"库库库,呼唤{NICKNAME}做什么呢",
|
||||||
"我在呢!",
|
"我在呢!",
|
||||||
"呼呼,叫俺干嘛",
|
"呼呼,叫俺干嘛",
|
||||||
)
|
)
|
||||||
@@ -170,8 +170,8 @@ async def check_text(text: str, sess: ClientSession) -> str:
|
|||||||
async with sess.get(check_url, timeout=2, params=params) as response:
|
async with sess.get(check_url, timeout=2, params=params) as response:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
if data["code"] == 200:
|
if data["code"] == 200:
|
||||||
if data["conclusion_type"] == 2:
|
if data['data']["conclusion_type"] == 2:
|
||||||
return ''
|
return ''
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"检测违规文本错误...e:{e}")
|
logger.error(f"检测违规文本错误...{type(e)}:{e}")
|
||||||
return text
|
return text
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
|||||||
if sub_type in ["season", "动漫", "番剧"]:
|
if sub_type in ["season", "动漫", "番剧"]:
|
||||||
rst = "*以为您找到以下番剧,请输入Id选择:*\n"
|
rst = "*以为您找到以下番剧,请输入Id选择:*\n"
|
||||||
state["season_data"] = await get_media_id(id_)
|
state["season_data"] = await get_media_id(id_)
|
||||||
print(state["season_data"])
|
|
||||||
if len(state["season_data"]) == 0:
|
if len(state["season_data"]) == 0:
|
||||||
await add_sub.finish(f"未找到番剧:{msg}")
|
await add_sub.finish(f"未找到番剧:{msg}")
|
||||||
for i, x in enumerate(state["season_data"]):
|
for i, x in enumerate(state["season_data"]):
|
||||||
@@ -105,7 +104,6 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
|||||||
await add_sub.send(await add_season_sub(id_, sub_user))
|
await add_sub.send(await add_season_sub(id_, sub_user))
|
||||||
else:
|
else:
|
||||||
await add_sub.finish("参数错误,第一参数必须为:主播/up/番剧!")
|
await add_sub.finish("参数错误,第一参数必须为:主播/up/番剧!")
|
||||||
sub_manager.reload_flag = True
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"(USER {event.user_id}, GROUP "
|
f"(USER {event.user_id}, GROUP "
|
||||||
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
f"{event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
|
||||||
@@ -151,8 +149,8 @@ async def _(bot: Bot, event: MessageEvent, state: T_State):
|
|||||||
f'\t当前集数:{x.season_current_episode}\n' \
|
f'\t当前集数:{x.season_current_episode}\n' \
|
||||||
f'------------------\n'
|
f'------------------\n'
|
||||||
live_rst = '当前订阅的直播:\n' + live_rst if live_rst else live_rst
|
live_rst = '当前订阅的直播:\n' + live_rst if live_rst else live_rst
|
||||||
up_rst = '当前订阅的UP:\n' if up_rst else up_rst
|
up_rst = '当前订阅的UP:\n' + up_rst if up_rst else up_rst
|
||||||
season_rst = '当前订阅的番剧:\n' if season_rst else season_rst
|
season_rst = '当前订阅的番剧:\n' + season_rst if season_rst else season_rst
|
||||||
if not live_rst and not up_rst and not season_rst:
|
if not live_rst and not up_rst and not season_rst:
|
||||||
live_rst = '您目前没有任何订阅...'
|
live_rst = '您目前没有任何订阅...'
|
||||||
await show_sub_info.send(live_rst + up_rst + season_rst)
|
await show_sub_info.send(live_rst + up_rst + season_rst)
|
||||||
|
|||||||
@@ -335,45 +335,52 @@ async def get_user_dynamic(
|
|||||||
|
|
||||||
class SubManager:
|
class SubManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.reload_flag = True
|
|
||||||
self.live_data = []
|
self.live_data = []
|
||||||
self.up_data = []
|
self.up_data = []
|
||||||
self.season_data = []
|
self.season_data = []
|
||||||
self.sub_list = []
|
self.current_index = -1
|
||||||
|
|
||||||
async def reload_sub_data(self):
|
async def reload_sub_data(self):
|
||||||
"""
|
"""
|
||||||
重载数据
|
重载数据
|
||||||
"""
|
"""
|
||||||
if self.reload_flag or not self.sub_list:
|
if not self.live_data or not self.up_data or not self.season_data:
|
||||||
(
|
(
|
||||||
self.live_data,
|
_live_data,
|
||||||
self.up_data,
|
_up_data,
|
||||||
self.season_data,
|
_season_data,
|
||||||
) = await BilibiliSub.get_all_sub_data()
|
) = await BilibiliSub.get_all_sub_data()
|
||||||
for x, i, j in zip(self.live_data, self.up_data, self.season_data):
|
if not self.live_data:
|
||||||
self.sub_list.append(x)
|
self.live_data = _live_data
|
||||||
self.sub_list.append(i)
|
if not self.up_data:
|
||||||
self.sub_list.append(j)
|
self.up_data = _up_data
|
||||||
self.reload_flag = False
|
if not self.season_data:
|
||||||
|
self.season_data = _season_data
|
||||||
def append(self, data: BilibiliSub):
|
|
||||||
"""
|
|
||||||
增加新数据
|
|
||||||
:param data: 数据
|
|
||||||
"""
|
|
||||||
self.sub_list.append(data)
|
|
||||||
|
|
||||||
async def random_sub_data(self) -> Optional[BilibiliSub]:
|
async def random_sub_data(self) -> Optional[BilibiliSub]:
|
||||||
"""
|
"""
|
||||||
随机获取一条数据
|
随机获取一条数据
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if not self.sub_list:
|
sub = None
|
||||||
await self.reload_sub_data()
|
self.current_index += 1
|
||||||
if self.sub_list:
|
if self.current_index == 0:
|
||||||
sub = random.choice(self.sub_list)
|
if self.live_data:
|
||||||
self.sub_list.remove(sub)
|
sub = random.choice(self.live_data)
|
||||||
|
self.live_data.remove(sub)
|
||||||
|
elif self.current_index == 1:
|
||||||
|
if self.up_data:
|
||||||
|
sub = random.choice(self.up_data)
|
||||||
|
self.up_data.remove(sub)
|
||||||
|
elif self.current_index == 2:
|
||||||
|
if self.season_data:
|
||||||
|
sub = random.choice(self.season_data)
|
||||||
|
self.season_data.remove(sub)
|
||||||
|
else:
|
||||||
|
self.current_index = -1
|
||||||
|
if sub:
|
||||||
return sub
|
return sub
|
||||||
return None
|
await self.reload_sub_data()
|
||||||
|
return await self.random_sub_data()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user