Skip to content

Commit

Permalink
🐛 make is_tome and tome_remove static
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 5, 2024
1 parent e2ecfd8 commit 9ee08f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions arclet/alconna/avilla/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from arclet.alconna.stub import ArgsStub, OptionStub, SubcommandStub
from arclet.alconna.tools import AlconnaFormat
from avilla.core import Context, Message, Notice, Selector
from avilla.core.exceptions import UnknownTarget
from avilla.core.exceptions import UnknownTarget, ActionFailed
from avilla.standard.core.message import MessageReceived
from creart import it
from graia.amnesia.message import MessageChain
Expand Down Expand Up @@ -91,14 +91,16 @@ def from_format(cls, command: str, args: Optional[Dict[str, Any]] = None):

default_send_handler: ClassVar[TConvert] = lambda _, x: MessageChain([Text(x)])

def is_tome(self, message: MessageChain, account: Selector):
@staticmethod
def is_tome(message: MessageChain, account: Selector):
if message.content and isinstance(message[0], Notice):
notice: Notice = message.get_first(Notice)
if notice.target.last_value == account.last_value:
return True
return False

def tome_remove(self, message: MessageChain, account: Selector):
@staticmethod
def tome_remove(message: MessageChain, account: Selector):
message = MessageChain(message.content.copy())
message.content.remove(message.get_first(Notice))
if message.content and isinstance(message.content[0], Text):
Expand All @@ -116,7 +118,7 @@ async def reply_merge(self, message: MessageChain, source: MessageReceived):
if not (origin := reply_cache.get(source_id)):
try:
origin = await source.context.pull(Message, source.message.reply)
except (NotImplementedError, UnknownTarget, RuntimeError):
except (NotImplementedError, UnknownTarget, RuntimeError, ActionFailed):
return message
else:
reply_cache[source_id] = origin
Expand Down
4 changes: 2 additions & 2 deletions arclet/alconna/avilla/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def alcommand(
patterns: Optional[list[str]] = None,
comp_session: Optional[CompConfig] = None,
need_tome: bool = False,
remove_tome: bool = False,
remove_tome: bool = True,
merge_reply: Union[bool, Literal["left", "right"]] = False,
) -> SchemaWrapper:
"""
Expand Down Expand Up @@ -423,7 +423,7 @@ def Command(
patterns: Optional[list[str]] = None,
comp_session: Optional[CompConfig] = None,
need_tome: bool = False,
remove_tome: bool = False,
remove_tome: bool = True,
merge_reply: Union[bool, Literal["left", "right"]] = False,
):
cmd = AvillaCommand(command, help_text, meta)
Expand Down

0 comments on commit 9ee08f8

Please sign in to comment.