GraiaProject / Ariadne

一个优雅且完备的 Python QQ 自动化框架,基于 Mirai API HTTP v2。 Powered by Graia Project.
https://graia.cn/ariadne
GNU Affero General Public License v3.0
753 stars 45 forks source link

[Enhancement] ParamMatch and improved Sparkle #57

Closed BlueGlassBlock closed 2 years ago

BlueGlassBlock commented 2 years ago
sp = Twilight(
    Sparkle([FullMatch("lp"), FullMatch("user"), ParamMatch(), FullMatch("set"), ParamMatch()])
).generate(MessageChain.create("lp user perm set 'DENIED -> NOLOGIN'"))
>>> debug(sp.get_match(ParamMatch))
[
        ParamMatch(
            matched=True,
            result=MessageChain(
                [
                    Plain(
                        text='perm',
                    ),
                ],
            ),
            pattern=...
        ),
        ParamMatch(
            matched=True,
            result=MessageChain(
                [
                    Plain(
                        text="'DENIED -> NOLOGIN'",
                    ),
                ],
            ),
            pattern=...
        ),
] (list) len=2
>>> debug(sp[ParamMatch, 0])

ParamMatch(
        matched=True,
        result=MessageChain(
            [
                Plain(
                    text='perm',
                ),
            ],
        ),
        pattern=...
) (ParamMatch)