Skip to content

Commit

Permalink
fix(onebot.v11): notice event for member
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 5, 2024
1 parent 597cc25 commit b67af18
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
10 changes: 6 additions & 4 deletions avilla/onebot/v11/perform/event/notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
ModifyDetail,
SceneCreated,
SceneDestroyed,
MemberCreated,
MemberDestroyed,
)
from avilla.core.selector import Selector
from avilla.onebot.v11.capability import OneBot11Capability
Expand Down Expand Up @@ -94,7 +96,7 @@ async def member_leave(self, raw_event: dict):
endpoint = group.member(str(raw_event["user_id"]))
operator = group.member(str(raw_event["operator_id"]))
context = Context(account, operator, endpoint, group, group.member(str(self_id)))
return SceneDestroyed(context, True, True)
return MemberDestroyed(context, True, True)

@m.entity(OneBot11Capability.event_callback, raw_event="notice.group_decrease.kick")
async def member_kick(self, raw_event: dict):
Expand All @@ -107,7 +109,7 @@ async def member_kick(self, raw_event: dict):
endpoint = group.member(str(raw_event["user_id"]))
operator = group.member(str(raw_event["operator_id"]))
context = Context(account, operator, endpoint, group, group.member(str(self_id)))
return SceneDestroyed(context, False, True)
return MemberDestroyed(context, False, True)

@m.entity(OneBot11Capability.event_callback, raw_event="notice.group_decrease.kick_me")
async def member_kick_me(self, raw_event: dict):
Expand Down Expand Up @@ -139,7 +141,7 @@ async def member_increase_approve(self, raw_event: dict):
group,
group.member(str(self_id)),
)
return SceneCreated(context)
return MemberCreated(context)

@m.entity(OneBot11Capability.event_callback, raw_event="notice.group_increase.invite")
async def member_increase_invite(self, raw_event: dict):
Expand All @@ -152,7 +154,7 @@ async def member_increase_invite(self, raw_event: dict):
endpoint = group.member(str(raw_event["user_id"]))
operator = group.member(str(raw_event["operator_id"]))
context = Context(account, operator, endpoint, group, group.member(str(self_id)), mediums=[group])
return SceneCreated(context)
return MemberCreated(context)

@m.entity(OneBot11Capability.event_callback, raw_event="notice.group_ban.ban")
async def member_muted(self, raw_event: dict):
Expand Down
32 changes: 32 additions & 0 deletions avilla/onebot/v11/perform/query/friend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

from datetime import timedelta
from typing import TYPE_CHECKING, Callable, cast

from graia.amnesia.builtins.memcache import MemcacheService

from avilla.core.builtins.capability import CoreCapability
from avilla.core.ryanvk.collector.account import AccountCollector
from avilla.core.selector import Selector

if TYPE_CHECKING:
from avilla.onebot.v11.account import OneBot11Account # noqa
from avilla.onebot.v11.protocol import OneBot11Protocol # noqa


class ElizabethFriendQueryPerform((m := AccountCollector["OneBot11Protocol", "OneBot11Account"]())._):
m.namespace = "avilla.protocol/onebot11::query"
m.identify = "friend"

@CoreCapability.query.collect(m, "land.friend")
async def query_friend(self, predicate: Callable[[str, str], bool] | str, previous: None):
cache = self.protocol.avilla.launch_manager.get_component(MemcacheService).cache
result = await self.account.connection.call("get_friend_list", {})
result = cast(list, result)
for i in result:
user_id = str(i["user_id"])
await cache.set(
f"onebot11/account({self.account.route['account']}).friend({user_id})", i, timedelta(minutes=5)
)
if callable(predicate) and predicate("friend", user_id) or user_id == predicate:
yield Selector().land(self.account.route["land"]).friend(user_id)
2 changes: 2 additions & 0 deletions avilla/onebot/v11/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _import_performs():
from avilla.onebot.v11.perform.message import serialize # noqa: F401
from avilla.onebot.v11.perform.query import group # noqa: F401
from avilla.onebot.v11.perform.query import file # noqa: F401
from avilla.onebot.v11.perform.query import friend # noqa: F401


_import_performs()
Expand All @@ -69,6 +70,7 @@ class OneBot11Protocol(BaseProtocol):
ref("avilla.protocol/onebot11::message", "serialize"),
ref("avilla.protocol/onebot11::query", "file"),
ref("avilla.protocol/onebot11::query", "group"),
ref("avilla.protocol/onebot11::query", "friend"),
),
}

Expand Down

0 comments on commit b67af18

Please sign in to comment.