mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
🚨 移除noqa: E501
💄 auto fix by pre-commit hooks
This commit is contained in:
@@ -16,7 +16,7 @@ __help__plugin__name__ = "nonebot_bison"
|
||||
__usage__ = (
|
||||
"本bot可以提供b站、微博等社交媒体的消息订阅,详情请查看本bot文档,"
|
||||
f"或者{'at本bot' if plugin_config.bison_to_me else '' }发送“添加订阅”订阅第一个帐号,"
|
||||
f"发送“查询订阅”或“删除订阅”管理订阅"
|
||||
"发送“查询订阅”或“删除订阅”管理订阅"
|
||||
)
|
||||
|
||||
__supported_adapters__ = nonebot_plugin_saa.__plugin_meta__.supported_adapters
|
||||
|
||||
@@ -57,9 +57,7 @@ def init_fastapi():
|
||||
port = driver.config.port
|
||||
if host in ["0.0.0.0", "127.0.0.1"]:
|
||||
host = "localhost"
|
||||
logger.opt(colors=True).info(
|
||||
f"Nonebot Bison frontend will be running at: " f"<b><u>http://{host}:{port}/bison</u></b>"
|
||||
)
|
||||
logger.opt(colors=True).info(f"Nonebot Bison frontend will be running at: <b><u>http://{host}:{port}/bison</u></b>")
|
||||
logger.opt(colors=True).info("该页面不能被直接访问,请私聊bot <b><u>后台管理</u></b> 以获取可访问地址")
|
||||
|
||||
|
||||
@@ -72,7 +70,7 @@ def register_get_token_handler():
|
||||
await get_token.finish(f"请访问: {plugin_config.bison_outer_url}auth/{token}")
|
||||
|
||||
get_token.__help__name__ = "获取后台管理地址" # type: ignore
|
||||
get_token.__help__info__ = "获取管理bot后台的地址,该地址会" "在一段时间过后过期,请不要泄漏该地址" # type: ignore
|
||||
get_token.__help__info__ = "获取管理bot后台的地址,该地址会在一段时间过后过期,请不要泄漏该地址" # type: ignore
|
||||
|
||||
|
||||
def check_driver_is_fastapi() -> bool:
|
||||
|
||||
@@ -52,9 +52,7 @@ class DBConfig:
|
||||
if not db_user:
|
||||
db_user = User(user_target=user.dict())
|
||||
session.add(db_user)
|
||||
db_target_stmt = (
|
||||
select(Target).where(Target.platform_name == platform_name).where(Target.target == target)
|
||||
)
|
||||
db_target_stmt = select(Target).where(Target.platform_name == platform_name).where(Target.target == target)
|
||||
db_target: Target | None = await session.scalar(db_target_stmt)
|
||||
if not db_target:
|
||||
db_target = Target(target=target, platform_name=platform_name, target_name=target_name)
|
||||
|
||||
@@ -32,7 +32,8 @@ async def data_migrate():
|
||||
if key in user_sub_set:
|
||||
# a user subscribe a target twice
|
||||
logger.error(
|
||||
f"用户 {user['user_type']}-{user['user']} 订阅了 {platform_name}-{target_name} 两次,随机采用了一个订阅" # noqa: E501
|
||||
f"用户 {user['user_type']}-{user['user']} 订阅了 {platform_name}-{target_name} 两次,"
|
||||
"随机采用了一个订阅",
|
||||
)
|
||||
continue
|
||||
user_sub_set.add(key)
|
||||
|
||||
@@ -113,9 +113,13 @@ class AkVersion(StatusChange):
|
||||
def compare_status(self, _, old_status, new_status):
|
||||
res = []
|
||||
if old_status.get("preAnnounceType") == 2 and new_status.get("preAnnounceType") == 0:
|
||||
res.append(Post("arknights", text="登录界面维护公告上线(大概是开始维护了)", target_name="明日方舟更新信息")) # noqa: E501
|
||||
res.append(
|
||||
Post("arknights", text="登录界面维护公告上线(大概是开始维护了)", target_name="明日方舟更新信息")
|
||||
)
|
||||
elif old_status.get("preAnnounceType") == 0 and new_status.get("preAnnounceType") == 2:
|
||||
res.append(Post("arknights", text="登录界面维护公告下线(大概是开服了,冲!)", target_name="明日方舟更新信息")) # noqa: E501
|
||||
res.append(
|
||||
Post("arknights", text="登录界面维护公告下线(大概是开服了,冲!)", target_name="明日方舟更新信息")
|
||||
)
|
||||
if old_status.get("clientVersion") != new_status.get("clientVersion"):
|
||||
res.append(Post("arknights", text="游戏本体更新(大更新)", target_name="明日方舟更新信息"))
|
||||
if old_status.get("resVersion") != new_status.get("resVersion"):
|
||||
|
||||
@@ -54,7 +54,7 @@ class Bilibili(NewMessage):
|
||||
2: "专栏文章",
|
||||
3: "视频",
|
||||
4: "纯文字",
|
||||
5: "转发"
|
||||
5: "转发",
|
||||
# 5: "短视频"
|
||||
}
|
||||
platform_name = "bilibili"
|
||||
|
||||
@@ -82,9 +82,7 @@ class Platform(metaclass=PlatformABCMeta, base=True):
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def fetch_new_post(
|
||||
self, target: Target, users: list[UserSubInfo]
|
||||
) -> list[tuple[PlatformTarget, list[Post]]]:
|
||||
async def fetch_new_post(self, target: Target, users: list[UserSubInfo]) -> list[tuple[PlatformTarget, list[Post]]]:
|
||||
...
|
||||
|
||||
async def do_fetch_new_post(
|
||||
@@ -300,9 +298,7 @@ class NewMessage(MessageProcess, abstract=True):
|
||||
self.set_stored_data(target, store)
|
||||
return res
|
||||
|
||||
async def fetch_new_post(
|
||||
self, target: Target, users: list[UserSubInfo]
|
||||
) -> list[tuple[PlatformTarget, list[Post]]]:
|
||||
async def fetch_new_post(self, target: Target, users: list[UserSubInfo]) -> list[tuple[PlatformTarget, list[Post]]]:
|
||||
post_list = await self.get_sub_list(target)
|
||||
new_posts = await self.filter_common_with_diff(target, post_list)
|
||||
if not new_posts:
|
||||
@@ -339,9 +335,7 @@ class StatusChange(Platform, abstract=True):
|
||||
async def parse(self, raw_post: RawPost) -> Post:
|
||||
...
|
||||
|
||||
async def fetch_new_post(
|
||||
self, target: Target, users: list[UserSubInfo]
|
||||
) -> list[tuple[PlatformTarget, list[Post]]]:
|
||||
async def fetch_new_post(self, target: Target, users: list[UserSubInfo]) -> list[tuple[PlatformTarget, list[Post]]]:
|
||||
try:
|
||||
new_status = await self.get_status(target)
|
||||
except self.FetchError as err:
|
||||
@@ -367,9 +361,7 @@ class StatusChange(Platform, abstract=True):
|
||||
class SimplePost(MessageProcess, abstract=True):
|
||||
"Fetch a list of messages, dispatch it to different users"
|
||||
|
||||
async def fetch_new_post(
|
||||
self, target: Target, users: list[UserSubInfo]
|
||||
) -> list[tuple[PlatformTarget, list[Post]]]:
|
||||
async def fetch_new_post(self, target: Target, users: list[UserSubInfo]) -> list[tuple[PlatformTarget, list[Post]]]:
|
||||
new_posts = await self.get_sub_list(target)
|
||||
if not new_posts:
|
||||
return []
|
||||
|
||||
@@ -112,8 +112,10 @@ class Weibo(NewMessage):
|
||||
|
||||
async def parse(self, raw_post: RawPost) -> Post:
|
||||
header = {
|
||||
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,"
|
||||
"*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
|
||||
"accept": (
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,"
|
||||
"*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
|
||||
),
|
||||
"accept-language": "zh-CN,zh;q=0.9",
|
||||
"authority": "m.weibo.cn",
|
||||
"cache-control": "max-age=0",
|
||||
@@ -121,9 +123,11 @@ class Weibo(NewMessage):
|
||||
"sec-fetch-mode": "same-origin",
|
||||
"sec-fetch-site": "same-origin",
|
||||
"upgrade-insecure-requests": "1",
|
||||
"user-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 "
|
||||
"Mobile Safari/537.36",
|
||||
"user-agent": (
|
||||
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 "
|
||||
"Mobile Safari/537.36"
|
||||
),
|
||||
}
|
||||
info = raw_post["mblog"]
|
||||
retweeted = False
|
||||
|
||||
@@ -16,9 +16,7 @@ class PlugConfig(BaseSettings):
|
||||
bison_resend_times: int = 0
|
||||
bison_proxy: str | None
|
||||
bison_ua: str = (
|
||||
"Mozilla/5.0 (X11; Linux x86_64) "
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/51.0.2704.103 Safari/537.36"
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
|
||||
)
|
||||
bison_show_network_warning: bool = True
|
||||
|
||||
|
||||
@@ -69,9 +69,7 @@ class Scheduler:
|
||||
if not (schedulable := await self.get_next_schedulable()):
|
||||
return
|
||||
logger.trace(f"scheduler {self.name} fetching next target: [{schedulable.platform_name}]{schedulable.target}")
|
||||
send_userinfo_list = await config.get_platform_target_subscribers(
|
||||
schedulable.platform_name, schedulable.target
|
||||
)
|
||||
send_userinfo_list = await config.get_platform_target_subscribers(schedulable.platform_name, schedulable.target)
|
||||
|
||||
client = await self.scheduler_config_obj.get_client(schedulable.target)
|
||||
context.register_to_client(client)
|
||||
|
||||
@@ -91,7 +91,7 @@ def do_add_sub(add_sub: type[Matcher]):
|
||||
else:
|
||||
await add_sub.send(
|
||||
f"即将订阅的用户为:{state['platform']} {state['name']} {state['id']}\n如有错误请输入“取消”重新订阅"
|
||||
) # noqa: E501
|
||||
)
|
||||
|
||||
@add_sub.handle()
|
||||
async def prepare_get_categories(matcher: Matcher, state: T_State):
|
||||
@@ -120,7 +120,9 @@ def do_add_sub(add_sub: type[Matcher]):
|
||||
matcher.set_arg("raw_tags", None) # type: ignore
|
||||
state["tags"] = []
|
||||
return
|
||||
state["_prompt"] = "请输入要订阅/屏蔽的标签(不含#号)\n" "多个标签请使用空格隔开\n" '订阅所有标签输入"全部标签"\n' '具体规则回复"详情"' # noqa: E501
|
||||
state["_prompt"] = (
|
||||
'请输入要订阅/屏蔽的标签(不含#号)\n多个标签请使用空格隔开\n订阅所有标签输入"全部标签"\n具体规则回复"详情"'
|
||||
)
|
||||
|
||||
@add_sub.got("raw_tags", MessageTemplate("{_prompt}"), [handle_cancel])
|
||||
async def parser_tags(state: T_State, raw_tags: Message = Arg()):
|
||||
|
||||
@@ -33,9 +33,7 @@ class ProcessContext:
|
||||
res = []
|
||||
for req in self.reqs:
|
||||
if self._should_print_content(req):
|
||||
log_content = (
|
||||
f"{req.request.url} {req.request.headers} | [{req.status_code}] {req.headers} {req.text}"
|
||||
)
|
||||
log_content = f"{req.request.url} {req.request.headers} | [{req.status_code}] {req.headers} {req.text}"
|
||||
else:
|
||||
log_content = (
|
||||
f"{req.request.url} {req.request.headers} | [{req.status_code}] {req.headers} "
|
||||
|
||||
Reference in New Issue
Block a user