Giter VIP home page Giter VIP logo

nonebot_plugin_analysis_bilibili's Issues

B站节目单的网址错误触发解析事件

错误如图:
image
这种网址发送之后好像是不用解析的,但是触发解析事件然后报错了。

报错的网址:
https://www.bilibili.com/bangumi/list/sl65767

同样页面用APP分享的卡片消息也会触发错误。

卡片消息内容的日志:

01-05 13:45:50 [SUCCESS] nonebot | OneBot V11 88888888| [message.group.normal]: Message 773710669 from 88888888@[群:888888888] "[CQ:json,data={ "app": "com.tencent.structmsg", "config": { "ctime": 1672894148, "forward": true, "token": "e866b036daeb9efed0c8deb5d6604b9a", "type": "normal" }, "desc": "新闻", "meta": { "news": { "action": "", "android_pkg_name": "", "app_type": 1, "appid": 100951776, "ctime": 1672894148, "desc": "共28部", "jumpUrl": "https:\/\/b23.tv\/eQTVKdB?share_medium=android&share_source=qq&bbid=XUC4F63C0C8A0937E4A93011030F519E9069D&ts=1672894143219", "preview": "https:\/\/pic.ugcimg.cn\/109d1db499f126b0902e8197c6ee4fa1\/jpg1", "source_icon": "https:\/\/open.gtimg.cn\/open\/app_icon\/00\/95\/17\/76\/100951776_100_m.png?t=1672798788", "source_url": "", "tag": "哔哩哔哩", "title": "2023一月新番", "uin": 888888888} }, "prompt": "[ 分享]2023一月新番", "ver": "0.0.0.1", "view": "news" }]"

使用RedProtocol连接nb2的环境下插件发送信息时出错

报错信息:

11-23 12:08:31 [ERROR] nonebot_plugin_analysis_bilibili | 'MessageSegment' object has no attribute 'upload'
Traceback (most recent call last):
  File "<string>", line 33, in <module>
  File "/usr/local/lib/python3.11/site-packages/nonebot/__init__.py", line 331, in run
    get_driver().run(*args, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/nonebot/drivers/none.py", line 70, in run
    loop.run_until_complete(self._serve())
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1922, in _run_once
    handle._run()
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.11/site-packages/nonebot/message.py", line 476, in check_and_run_matcher
    await _run_matcher(
  File "/usr/local/lib/python3.11/site-packages/nonebot/message.py", line 428, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "/usr/local/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 846, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "/usr/local/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 821, in simple_run
    await handler(
  File "/usr/local/lib/python3.11/site-packages/nonebot/dependencies/__init__.py", line 113, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "/usr/local/lib/python3.11/site-packages/nonebot_plugin_analysis_bilibili/__init__.py", line 138, in handle_analysis
    await send_msg(msg)
  File "/usr/local/lib/python3.11/site-packages/nonebot_plugin_analysis_bilibili/__init__.py", line 97, in send_msg
    await analysis_bili.send(format_msg(msg_list))
  File "/usr/local/lib/python3.11/site-packages/nonebot/internal/matcher/matcher.py", line 554, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/nonebot/adapters/red/bot.py", line 238, in send
    element_data = await message.export(self)
  File "/usr/local/lib/python3.11/site-packages/nonebot/adapters/red/message.py", line 389, in export
    resp = await seg.upload(bot)
AttributeError: 'MessageSegment' object has no attribute 'upload'

您好,关于图片问题想请教一下

那个关于B站封面获取您最下面显示的插件在使用时出现了“视频解析出错--Error”
image
显示错误代码为:'NoneType' object has no attribute 'strftime'
我该如何解决,亦或者作者您何时能使本插件原生支持封面获取

黑名单和群黑名单失效

看了下代码,读取配置时候黑名单是读成str,但是比对user_id、group_id是int。
修改为相同类型,测试可以正常屏蔽。

[Bug]无法解析b23.tv短链

解析BV号AV号链接正常,解析b23.tv短链出现以下报错:

04-15 13:13:44 [ERROR] nonebot | Running Matcher(type='message', module=nonebot_plugin_analysis_bilibili) failed.
Traceback (most recent call last):
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\aiohttp\connector.py", line 980, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\base_events.py", line 1067, in create_connection
    raise exceptions[0]
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\base_events.py", line 1052, in create_connection
    sock = await self._connect_sock(
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\base_events.py", line 963, in _connect_sock
    await self.sock_connect(sock, address)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\proactor_events.py", line 705, in sock_connect
    return await self._proactor.connect(sock, address)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\windows_events.py", line 817, in _poll
    value = callback(transferred, key, ov)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\windows_events.py", line 604, in finish_connect
    ov.getresult()
OSError: [WinError 121] 信号灯超时时间已到

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\ProgramData\Anaconda3\envs\bot\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\ProgramData\Anaconda3\envs\bot\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\ProgramData\Anaconda3\envs\bot\Scripts\nb.exe\__main__.py", line 7, in <module>
    sys.exit(main())
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nb_cli\commands\main.py", line 30, in run
    run_bot(file, app)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nb_cli\handlers\deploy.py", line 25, in run_bot
    nonebot.run(app=f"{module_name}:{app}")
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot\__init__.py", line 273, in run
    get_driver().run(*args, **kwargs)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot\drivers\fastapi.py", line 172, in run
    uvicorn.run(
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\uvicorn\main.py", line 569, in run
    server.run()
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\uvicorn\server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\base_events.py", line 636, in run_until_complete
    self.run_forever()
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\base_events.py", line 603, in run_forever
    self._run_once()
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\base_events.py", line 1899, in _run_once
    handle._run()
  File "D:\ProgramData\Anaconda3\envs\bot\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot\message.py", line 142, in _check_matcher
    await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
> File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot\message.py", line 188, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot\internal\matcher\matcher.py", line 727, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot\internal\matcher\matcher.py", line 702, in simple_run
    await handler(
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot\dependencies\__init__.py", line 108, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot_plugin_analysis_bilibili\__init__.py", line 23, in analysis_main
    text = await b23_extract(text)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\nonebot_plugin_analysis_bilibili\analysis_bilibili.py", line 58, in b23_extract
    async with aiohttp.request("GET", url) as resp:
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\aiohttp\client.py", line 1189, in __aenter__
    self._resp = await self._coro
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\aiohttp\client.py", line 536, in _request
    conn = await self._connector.connect(
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\aiohttp\connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\aiohttp\connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\aiohttp\connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\aiohttp\connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "D:\ProgramData\Anaconda3\envs\bot\lib\site-packages\aiohttp\connector.py", line 988, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host b23.tv:443 ssl:default [信号灯超时时间已到]

[bug]无法响应群信息。

版本:最新版本
cq:1.0.1

出现错误操作:群里发链接解析直接报错

错误内容:05-23 10:33:53 [ERROR] nonebot | Running Matcher(type='message', module=nonebot_plugin_analysis_bilibili) failed.
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot_plugin_analysis_bilibili_init_.py", line 35, in analysis_main
await analysis_bili.send(msg)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 466, in send
return await bot.send(event=event, message=message, **kwargs)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot_plugin_guild_patch_init
.py", line 30, in patched_send
return await original_send(self, event, message, **kwargs)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 220, in send
return await self.class.send_handler(self, event, message, **kwargs)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 174, in send
return await bot.send_msg(**params)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\internal\adapter\bot.py", line 120, in call_api
raise exception
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
result = await self.adapter._call_api(self, api, **data)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\adapters\onebot\v11\adapter.py", line 140, in _call_api
return handle_api_result(await self._result_store.fetch(seq, timeout))
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\adapters\onebot\v11\utils.py", line 58, in handle_api_result
raise ActionFailed(**result)
nonebot.adapters.onebot.v11.exception.ActionFailed: ActionFailed(data=None, echo='6', message='send group message failed: blocked by server', msg='SEND_MSG_API_ERROR', retcode=100, status='failed', wording='send group message failed: blocked by server')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot\bot.py", line 17, in
nonebot.run()
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot_init_.py", line 309, in run
get_driver().run(*args, **kwargs)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\drivers\fastapi.py", line 198, in run
uvicorn.run(
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\uvicorn\main.py", line 569, in run
server.run()
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\uvicorn\server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete
self.run_forever()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever
super().run_forever()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 607, in run_forever
self._run_once()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1919, in _run_once
handle._run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\message.py", line 141, in _check_matcher
await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)

File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\message.py", line 187, in run_matcher
await matcher.run(bot, event, state, stack, dependency_cache)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 753, in run
await self.simple_run(bot, event, state, stack, dependency_cache)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 728, in simple_run
await handler(
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot\dependencies_init
.py", line 108, in call
return await cast(Callable[..., Awaitable[R]], self.call)(**values)
File "C:\Users\Administrator\Desktop\NBBOOT\FistBot.venv\Lib\site-packages\nonebot_plugin_analysis_bilibili_init_.py", line 39, in analysis_main
msg = re.sub(r"简介.*", "", msg)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\re_init_.py", line 185, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object, got 'Message'

【建议】建议使用正则响应器匹配事件

如题
如果解析所有消息的话一是占用性能二是很有可能与某些同样解析所有消息闲聊功能产生未知冲突

另外B站QQ小程序json可能有更新,现在的正则匹配不到了
QQ小程序&amp;#93;哔哩哔哩 -> QQ小程序&#93;哔哩哔哩

解析某些JSON消息时出现错误 Cannot connect to host b23.tv\:443

描述:
解析部分以JSON消息(即[CQ:json,...],包括分享和小程序)构造的分享链接时发生错误

环境:
Windows10 和 Ubuntu Server 20.04.2 LTS
Python 3.9

复现:
使用安卓哔哩哔哩客户端,点击任一视频,然后分享到QQ内,将有概率触发下述错误
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host b23.tv\:443 ssl:default [Name or service not known]
log.txt

分析:
使用json消息段分享视频时,某些视频在构造url时采用以下方式
[CQ:json, ... , "jumpUrl":"https://b23.tv/hW3asF...
而也有某些视频采用如下方式:
[CQ:json, ... , "jumpUrl":"https:\/\/b23.tv\/9hj9Dt...

若仍然使用该正则表达式b23.tv(\\)?/(\w+)|(bili(22|23|33|2233).cn)(\\)?/(\w+),即

b23 = re.compile(r'b23.tv(\\)?/(\w+)|(bili(22|23|33|2233).cn)(\\)?/(\w+)').search(text)

会导致前者能正常解析为https://b23.tv/hW3asF,后者会被解析为https://b23.tv\/9hj9Dt,因此后者会使aiohttp将b23.tv\当作hostname处理,最终会导致找不到主机名引发该错误

可能的解决方式:

b23 = re.compile(r'b23.tv(\\)?/(\w+)|(bili(22|23|33|2233).cn)(\\)?/(\w+)').search(text)
url = f'https://b23.tv/{b23[2]}'

这样可以同时解决https://b23.tv/https:\/\/b23.tv\/的问题

feature: 添加是否使用代理选项

起因是 #15 ,在此之后很长一段时间都有这个问题,虽然我没开代理但可能仍然有设置被动到导致无法联网

然后我找到了 同样的报错的解决方案

我把

async with aiohttp.ClientSession() as session:

修改为

async with aiohttp.ClientSession(trust_env=True) as session:

之后就能正常访问了。

考虑到使用代理的场景不少,我推荐把这个加到配置项去。

Wrong regex result for BVid

analysis_bilibili.py Line 62:

bvid = re.compile(r'BV([a-zA-Z0-9])+', re.I).search(text)

This pattern will match a wrong string like 'Bvid'.
Sample message:

华洛不会飞 投稿了新视频啦
标题:《  哈哈 我先润了  》
Bvid:BV1Zu411o7RB
直链:https://www.bilibili.com/video/BV1Zu411o7RB

This string will cause a wrong result. We know bvid has a 10-digit unique id. So we can change the pattern into

bvid = re.compile(r'BV([a-zA-Z0-9]{10})+', re.I).search(text)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.