Ice9Coffee / HoshinoBot

A qqbot for Princess Connect Re:Dive (and other usage :)
GNU General Public License v3.0
1.41k stars 411 forks source link

修复python新版本re弃用正则表达式内的内联标记的问题 #272

Closed kcn3388 closed 1 year ago

kcn3388 commented 1 year ago

新版本python不再支持正则表达式开头放置内联标记,如:(?i)^scan$ 测试版本:3.11

kcn3388 commented 1 year ago
[2023-04-03 16:04:52,549 nonebot] ERROR: Failed to import and load "hoshino.modules.fgogacha.fgo_manage", error: global flags not at the start of the expression at position 1
[2023-04-03 16:04:52,549 nonebot] ERROR: global flags not at the start of the expression at position 1
Traceback (most recent call last):
  File "C:\Users\kcn3388\git\Hoshino_xcw_private\Hoshino\venv\Lib\site-packages\nonebot\plugin.py", line 419, in _load_plugin
    module = importlib.import_module(module_path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kcn3388\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\kcn3388\git\Hoshino_xcw_private\Hoshino\hoshino\modules\fgogacha\fgo_manage.py", line 138, in <module>
    @sv_manage.on_rex(r"^(?i)fgo_enable_crt(\s.+)?$")
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kcn3388\git\Hoshino_xcw_private\Hoshino\hoshino\service.py", line 285, in on_rex
    rex = re.compile(rex)
          ^^^^^^^^^^^^^^^
  File "C:\Users\kcn3388\AppData\Local\Programs\Python\Python311\Lib\re\__init__.py", line 227, in compile
    return _compile(pattern, flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kcn3388\AppData\Local\Programs\Python\Python311\Lib\re\__init__.py", line 294, in _compile
    p = _compiler.compile(pattern, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kcn3388\AppData\Local\Programs\Python\Python311\Lib\re\_compiler.py", line 743, in compile
    p = _parser.parse(p, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kcn3388\AppData\Local\Programs\Python\Python311\Lib\re\_parser.py", line 980, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kcn3388\AppData\Local\Programs\Python\Python311\Lib\re\_parser.py", line 455, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kcn3388\AppData\Local\Programs\Python\Python311\Lib\re\_parser.py", line 841, in _parse
    raise source.error('global flags not at the start '
re.error: global flags not at the start of the expression at position 1
Ice9Coffee commented 1 year ago

我觉得你应该修改插件中的正则写法,而不是修改框架? 你可以将编译好的正则表达式传入on_rex