Skip to content

Commit

Permalink
✏️ version 0.18.1
Browse files Browse the repository at this point in the history
fix typo
  • Loading branch information
RF-Tar-Railt committed Aug 25, 2023
1 parent dc8ad73 commit 68fd028
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 366 deletions.
330 changes: 1 addition & 329 deletions pdm.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ dev = [
"nonemoji ~=0.1",
"pre-commit ~=3.1",
"nonebot-adapter-villa>=0.6.5",
"nonebot-adapter-kaiheila>=0.0.6",
"nonebot-adapter-discord>=0.1.0b1",
]
[tool.pdm.build]
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
from .consts import ALCONNA_EXEC_RESULT as ALCONNA_EXEC_RESULT
from .rule import set_output_converter as set_output_converter

__version__ = "0.18.0"
__version__ = "0.18.1"

_meta_source = {
"name": "Alconna 插件",
Expand Down
12 changes: 4 additions & 8 deletions src/nonebot_plugin_alconna/adapters/console.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from nonebot.adapters.console.message import Message
from nonebot.adapters.console.message import Emoji as _Emoji
from arclet.alconna import argv_config, set_default_argv_type
from nonebot.adapters.console.message import Markup as _Markup
from nonebot.adapters.console.message import Markdown as _Markdown
from nonebot.adapters.console.message import BaseMessage, MessageSegment
from nonebot.adapters.console.message import Message, BaseMessage, MessageSegment

from nonebot_plugin_alconna.argv import MessageArgv
from nonebot_plugin_alconna.typings import SegmentPattern
Expand All @@ -22,8 +18,8 @@ class ConsoleMessageArgv(MessageArgv):
converter=lambda x: Message(x),
)

Emoji = SegmentPattern("emoji", _Emoji, MessageSegment.emoji)
Markup = SegmentPattern("markup", _Markup, MessageSegment.markup)
Markdown = SegmentPattern("markdown", _Markdown, MessageSegment.markdown)
Emoji = SegmentPattern("emoji", MessageSegment, MessageSegment.emoji)
Markup = SegmentPattern("markup", MessageSegment, MessageSegment.markup)
Markdown = SegmentPattern("markdown", MessageSegment, MessageSegment.markdown)

Text = str
6 changes: 3 additions & 3 deletions src/nonebot_plugin_alconna/adapters/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
from nonebot_plugin_alconna.adapters import Image as UniImg


class QQGuildMessageArgv(MessageArgv):
class DiscordMessageArgv(MessageArgv):
...


set_default_argv_type(QQGuildMessageArgv)
set_default_argv_type(DiscordMessageArgv)
argv_config(
QQGuildMessageArgv,
DiscordMessageArgv,
filter_out=[],
checker=lambda x: isinstance(x, BaseMessage),
to_text=lambda x: x if x.__class__ is str else str(x) if x.is_text() else None,
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/adapters/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MinecraftMessageArgv(MessageArgv):
MinecraftMessageArgv,
filter_out=[],
checker=lambda x: isinstance(x, BaseMessage),
to_text=lambda x: x if x.__class__ is str else str(x) if x.type == "text" else None,
to_text=lambda x: x if x.__class__ is str else str(x) if x.is_text() else None,
converter=lambda x: Message(x),
)

Expand Down
28 changes: 17 additions & 11 deletions src/nonebot_plugin_alconna/adapters/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@
BaseMessage,
UnCombinFile,
MessageSegment,
BaseMessageSegment,
)

from nonebot_plugin_alconna.argv import MessageArgv
from nonebot_plugin_alconna.typings import SegmentPattern, TextSegmentPattern


def is_text(x: MessageSegment):
return x.type in {
"text",
"bot_command",
"bold",
"italic",
"underline",
"strikethrough",
"spoiler",
"code",
}
def is_text(x: BaseMessageSegment):
return (
x.type
in {
"text",
"bot_command",
"bold",
"italic",
"underline",
"strikethrough",
"spoiler",
"code",
}
if isinstance(x, MessageSegment)
else x.is_text()
)


styles = {
Expand Down
4 changes: 2 additions & 2 deletions src/nonebot_plugin_alconna/matcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from datetime import datetime, timedelta
from typing import Any, Callable, Iterable, Protocol
from typing import Any, Callable, ClassVar, Iterable, Protocol

import nepattern.main
from nonebot.rule import Rule
Expand Down Expand Up @@ -69,7 +69,7 @@ def _validate(target: Arg[Any], arg: MessageSegment):


class AlconnaMatcher(Matcher):
command: Alconna
command: ClassVar[Alconna]

@classmethod
def shortcut(cls, key: str, args: ShortcutArgs | None = None, delete: bool = False):
Expand Down
23 changes: 13 additions & 10 deletions src/test/dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from nonebot.adapters.discord.commands import CommandOption
from arclet.alconna import Args, Option, Alconna, CommandMeta

from nonebot_plugin_alconna import on_alconna
from nonebot_plugin_alconna.adapters.discord import MentionUser, translate

matcher = translate(
matcher = on_alconna(
Alconna(
"permission",
Option("add", Args["plugin#插件名", str]["priority#优先级;?", int]),
Expand All @@ -17,32 +18,34 @@
)
)

slash_matcher = translate(matcher.command)

@matcher.handle_sub_command("add")

@slash_matcher.handle_sub_command("add")
async def handle_user_add(
plugin: CommandOption[str], priority: CommandOption[Optional[int]]
):
await matcher.send_deferred_response()
await slash_matcher.send_deferred_response()
await asyncio.sleep(2)
await matcher.edit_response(f"你添加了插件 {plugin},优先级 {priority}")
await slash_matcher.edit_response(f"你添加了插件 {plugin},优先级 {priority}")
await asyncio.sleep(2)
fm = await matcher.send_followup_msg(
fm = await slash_matcher.send_followup_msg(
f"你添加了插件 {plugin},优先级 {priority} (新消息)",
)
await asyncio.sleep(2)
await matcher.edit_followup_msg(
await slash_matcher.edit_followup_msg(
fm.id,
f"你添加了插件 {plugin},优先级 {priority} (新消息修改后)",
)


@matcher.handle_sub_command("remove")
@slash_matcher.handle_sub_command("remove")
async def handle_user_remove(
plugin: CommandOption[str], time: CommandOption[Optional[float]]
):
await matcher.send(f"你移除了插件 {plugin},时长 {time}")
await slash_matcher.send(f"你移除了插件 {plugin},时长 {time}")


@matcher.handle_sub_command("ban")
@slash_matcher.handle_sub_command("ban")
async def handle_admin_ban(user: CommandOption[User]):
await matcher.finish(f"你禁用了用户 {user.username}")
await slash_matcher.finish(f"你禁用了用户 {user.username}")

0 comments on commit 68fd028

Please sign in to comment.