Skip to content

Commit

Permalink
Merge branch 'Teahouse-Studios:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoruaFox authored Mar 2, 2025
2 parents d17a877 + 3288c11 commit 503a6e5
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 358 deletions.
4 changes: 2 additions & 2 deletions core/database/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class CrowdinActivityRecords:
@retry(stop=stop_after_attempt(3))
@auto_rollback_error
def check(txt: str):
query_hash = hashlib.md5(
txt.encode(encoding="UTF-8"), usedforsecurity=False
query_hash = hashlib.sha256(
txt.encode(encoding="UTF-8")
).hexdigest()
query = (
session.query(CrowdinActivityRecordsTable)
Expand Down
12 changes: 8 additions & 4 deletions modules/bilibili/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ async def _(msg: Bot.MessageSession, bid: str, get_detail=False):
query = f"?aid={bid[2:]}"
else:
return await msg.finish(msg.locale.t("bilibili.message.invalid"))
await get_video_info(msg, query, get_detail)
output = await get_video_info(msg, query, get_detail)
await msg.finish(output)


@bili.regex(r"av(\d+)\b", flags=re.I, mode="A", desc="{bilibili.help.regex.av}")
Expand All @@ -40,7 +41,8 @@ async def _(msg: Bot.MessageSession):
for video in matched:
if video:
query = f"?aid={video}"
await get_video_info(msg, query)
output = await get_video_info(msg, query)
await msg.send_message(output)


@bili.regex(r"BV[a-zA-Z0-9]{10}", mode="A", desc="{bilibili.help.regex.bv}")
Expand All @@ -49,7 +51,8 @@ async def _(msg: Bot.MessageSession):
for video in matched:
if video:
query = f"?bvid={video}"
await get_video_info(msg, query)
output = await get_video_info(msg, query)
await msg.send_message(output)


@bili.regex(r"(?:http[s]?://)?(?:bili(?:22|33|2233)\.cn|b23\.tv)/([A-Za-z0-9]{7})(?:/.*?|)",
Expand All @@ -65,7 +68,8 @@ async def _(msg: Bot.MessageSession):
query = await parse_shorturl(f"https://b23.tv/{video}")
if not query:
return
await get_video_info(msg, query)
output = await get_video_info(msg, query)
await msg.send_message(output)


async def parse_shorturl(shorturl):
Expand Down
116 changes: 54 additions & 62 deletions modules/bilibili/bili_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ async def get_video_info(
)
if res["code"] != 0:
if res["code"] == -400:
await msg.finish(msg.locale.t("bilibili.message.invalid"))
else:
await msg.finish(msg.locale.t("bilibili.message.not_found"))
return msg.locale.t("bilibili.message.invalid")
return msg.locale.t("bilibili.message.not_found")
except ValueError as e:
if str(e).startswith("412"):
await msg.finish(
ErrorMessage(
"{bilibili.message.error.rejected}", locale=msg.locale.locale
)
)
else:
raise e
return ErrorMessage("{bilibili.message.error.rejected}", locale=msg.locale.locale)
raise e

view = res["data"]["View"]
stat = view["stat"]
Expand Down Expand Up @@ -59,61 +53,59 @@ async def get_video_info(
fans = msg.locale.num(res["data"]["Card"]["card"]["fans"], 1)

if use_embed:
await msg.send_message(
Embed(
title=f"{title}{pages}",
description=desc,
url=video_url,
author=f"{owner}{msg.locale.t('message.brackets', msg=fans)}",
footer="Bilibili",
image=Image(pic),
thumbnail=Image(avatar),
fields=[
EmbedField(msg.locale.t("bilibili.message.embed.type"), tname),
EmbedField(
msg.locale.t("bilibili.message.embed.view"),
stat_view,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.danmaku"),
stat_danmaku,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.reply"),
stat_reply,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.like"),
stat_like,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.coin"),
stat_coin,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.favorite"),
stat_favorite,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.share"),
stat_share,
inline=True,
),
EmbedField(msg.locale.t("bilibili.message.embed.time"), time),
],
)
return Embed(
title=f"{title}{pages}",
description=desc,
url=video_url,
author=f"{owner}{msg.locale.t('message.brackets', msg=fans)}",
footer="Bilibili",
image=Image(pic),
thumbnail=Image(avatar),
fields=[
EmbedField(msg.locale.t("bilibili.message.embed.type"), tname),
EmbedField(
msg.locale.t("bilibili.message.embed.view"),
stat_view,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.danmaku"),
stat_danmaku,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.reply"),
stat_reply,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.like"),
stat_like,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.coin"),
stat_coin,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.favorite"),
stat_favorite,
inline=True,
),
EmbedField(
msg.locale.t("bilibili.message.embed.share"),
stat_share,
inline=True,
),
EmbedField(msg.locale.t("bilibili.message.embed.time"), time),
],
)
elif not get_detail:

if not get_detail:
output = msg.locale.t(
"bilibili.message", title=title, tname=tname, owner=owner, time=time
)
await msg.send_message([Image(pic), Url(video_url), Plain(output)])
else:
output = msg.locale.t(
"bilibili.message.detail",
Expand All @@ -132,4 +124,4 @@ async def get_video_info(
desc=desc,
time=time,
)
await msg.send_message([Image(pic), Url(video_url), Plain(output)])
return [Image(pic), Url(video_url), Plain(output)]
6 changes: 1 addition & 5 deletions modules/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,9 @@ async def _(msg: Bot.MessageSession, offset: str):
tstr_split = [int(part) for part in offset.split(":")]
hour = tstr_split[0]
minute = tstr_split[1] if len(tstr_split) > 1 else 0
if minute == 0:
offset = f"{'+' if hour >= 0 else '-'}{abs(hour)}"
else:
symbol = offset[0] if offset.startswith(("+", "-")) else "+"
offset = f"{symbol}{abs(hour)}:{abs(minute):02d}"
if hour > 12 or minute >= 60:
raise ValueError
offset = f"{hour:+}" if minute == 0 else f"{hour:+}:{abs(minute):02d}"
except ValueError:
await msg.finish(msg.locale.t("core.message.setup.timeoffset.invalid"))
msg.data.edit_option("timezone_offset", offset)
Expand Down
112 changes: 0 additions & 112 deletions modules/ptt/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions modules/ptt/locales/en_us.json

This file was deleted.

4 changes: 0 additions & 4 deletions modules/ptt/locales/zh_cn.json

This file was deleted.

4 changes: 0 additions & 4 deletions modules/ptt/locales/zh_tw.json

This file was deleted.

Loading

0 comments on commit 503a6e5

Please sign in to comment.