Skip to content

Commit

Permalink
🔖 0.10.0rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Dec 14, 2024
1 parent ef00c1c commit 0998855
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 122 deletions.
2 changes: 1 addition & 1 deletion arclet/entari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
WH = WebhookInfo
filter_ = Filter

__version__ = "0.10.0rc1"
__version__ = "0.10.0rc2"
4 changes: 2 additions & 2 deletions arclet/entari/builtins/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@


@cmd.handle
async def _(content: Match[MessageChain], session: Session):
async def echo_handle(content: Match[MessageChain], session: Session):
if content.available:
return await session.send(content.result)


@cmd.on_execute()
async def _(content: Match[MessageChain]):
async def echo_exec(content: Match[MessageChain]):
if content.available:
return content.result
4 changes: 2 additions & 2 deletions arclet/entari/builtins/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ def generator(_page: int):


@disp.on_execute()
async def _(arp: Arparma):
async def help_exec(arp: Arparma):
return help_cmd_handle(arp)


@disp.handle()
async def _(arp: Arparma, session: Session):
async def help_handle(arp: Arparma, session: Session):
resp = help_cmd_handle(arp, True)
if isinstance(resp, str):
return await session.send(resp)
Expand Down
135 changes: 22 additions & 113 deletions arclet/entari/event/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from typing import Any, ClassVar, Generic, TypeVar

from arclet.letoderea import Contexts, Interface, Param, Provider, Scope, SupplyAuxiliary
from arclet.letoderea import Contexts, Param, Provider
from satori import ArgvInteraction, ButtonInteraction, Channel
from satori import Event as SatoriEvent
from satori import EventType, Guild, Member, Role, User
Expand Down Expand Up @@ -56,67 +56,6 @@ def _remove_notice_me(message: MessageChain, account: Account):
return message


class ReplyMeSupplier(SupplyAuxiliary):

async def __call__(self, scope: Scope, interface: Interface):
if self.id in interface.executed:
return
message: MessageChain = interface.ctx["$message_content"]
account = await interface.query(Account, "account", force_return=True)
reply = await interface.query(Reply, "reply", force_return=True)
if not account:
return
if not reply:
is_reply_me = False
else:
is_reply_me = _is_reply_me(reply, account)
if is_reply_me and message and isinstance(message[0], Text):
message = message.copy()
text = message[0].text.lstrip()
if not text:
message.pop(0)
else:
message[0] = Text(text)
return interface.update(**{"$message_content": message, "is_reply_me": is_reply_me})

@property
def scopes(self) -> set[Scope]:
return {Scope.prepare}

@property
def id(self) -> str:
return "entari.filter/supply_reply_me"


reply_me_supplier = ReplyMeSupplier(priority=3)


class NoticeMeSupplier(SupplyAuxiliary):

async def __call__(self, scope: Scope, interface: Interface):
if self.id in interface.executed:
return
message: MessageChain = interface.ctx["$message_content"]
account = await interface.query(Account, "account", force_return=True)
if not account:
return
is_notice_me = _is_notice_me(message, account)
if is_notice_me:
message = _remove_notice_me(message, account)
return interface.update(**{"$message_content": message, "is_notice_me": is_notice_me})

@property
def scopes(self) -> set[Scope]:
return {Scope.prepare}

@property
def id(self) -> str:
return "entari.filter/supply_notice_me"


notice_me_supplier = NoticeMeSupplier(priority=5)


class Attr(Generic[T]):
def __init__(self, key: str | None = None):
self.key = key
Expand Down Expand Up @@ -362,7 +301,6 @@ class MessageEvent(Event):
quote: Quote | None = None

providers = [MessageContentProvider, ReplyProvider]
auxiliaries = [reply_me_supplier, notice_me_supplier]

def __init__(self, account: Account, origin: SatoriEvent):
super().__init__(account, origin)
Expand All @@ -373,10 +311,25 @@ def __init__(self, account: Account, origin: SatoriEvent):

async def gather(self, context: Contexts):
await super().gather(context)
context["$message_content"] = self.content
reply = None
if self.quote and self.quote.id:
mo = await self.account.protocol.message_get(self.channel.id, self.quote.id)
context["$message_reply"] = Reply(self.quote, mo)
reply = context["$message_reply"] = Reply(self.quote, mo)
if not reply:
is_reply_me = False
else:
is_reply_me = _is_reply_me(reply, self.account)
context["is_reply_me"] = is_reply_me
if is_reply_me and self.content and isinstance(self.content[0], Text):
text = self.content[0].text.lstrip()
if not text:
self.content.pop(0)
else:
self.content[0] = Text(text)
is_notice_me = context["is_notice_me"] = _is_notice_me(self.content, self.account)
if is_notice_me:
self.content = _remove_notice_me(self.content, self.account)
context["$message_content"] = self.content


class MessageCreatedEvent(MessageEvent):
Expand All @@ -391,30 +344,8 @@ class MessageUpdatedEvent(MessageEvent):
type = EventType.MESSAGE_UPDATED


class ReactionEvent(NoticeEvent):
channel: Channel = attr()
user: User = attr()
message: MessageObject = attr()

content: MessageChain
quote: Quote | None = None

providers = [MessageContentProvider, ReplyProvider]
auxiliaries = [reply_me_supplier, notice_me_supplier]

def __init__(self, account: Account, origin: SatoriEvent):
super().__init__(account, origin)
self.content = MessageChain(self.message.message)
if self.content.has(Quote):
self.quote = self.content.get(Quote, 1)[0]
self.content = self.content.exclude(Quote)

async def gather(self, context: Contexts):
await super().gather(context)
context["$message_content"] = self.content
if self.quote and self.quote.id:
mo = await self.account.protocol.message_get(self.channel.id, self.quote.id)
context["$message_reply"] = Reply(self.quote, mo)
class ReactionEvent(NoticeEvent, MessageEvent):
pass


class ReactionAddedEvent(ReactionEvent):
Expand Down Expand Up @@ -455,30 +386,8 @@ async def __call__(self, context: Contexts):
return context.get("argv")


class InteractionCommandMessageEvent(InteractionCommandEvent):
channel: Channel = attr()
user: User = attr()
message: MessageObject = attr()

content: MessageChain
quote: Quote | None = None

providers = [MessageContentProvider, ReplyProvider]
auxiliaries = [reply_me_supplier, notice_me_supplier]

def __init__(self, account: Account, origin: SatoriEvent):
super().__init__(account, origin)
self.content = MessageChain(self.message.message)
if self.content.has(Quote):
self.quote = self.content.get(Quote, 1)[0]
self.content = self.content.exclude(Quote)

async def gather(self, context: Contexts):
await super().gather(context)
context["$message_content"] = self.content
if self.quote and self.quote.id:
mo = await self.account.protocol.message_get(self.channel.id, self.quote.id)
context["$message_reply"] = Reply(self.quote, mo)
class InteractionCommandMessageEvent(InteractionCommandEvent, MessageEvent):
pass


MAPPING: dict[str, type[Event]] = {}
Expand Down
6 changes: 3 additions & 3 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "arclet-entari"
version = "0.10.0rc1"
version = "0.10.0rc2"
description = "Simple IM Framework based on satori-python"
authors = [
{name = "RF-Tar-Railt",email = "[email protected]"},
Expand Down

0 comments on commit 0998855

Please sign in to comment.