Skip to content

Commit

Permalink
chore(qqapi): bump version a14
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 15, 2023
1 parent 3da2e2c commit 355756b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .mina/qqapi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ raw_dependencies = [

[project]
name = "avilla-qqapi"
version = "1.0.0a13"
version = "1.0.0a14"
authors = [
{name = "RF-Tar-Railt", email = "[email protected]"}
]
Expand Down
4 changes: 2 additions & 2 deletions avilla/qqapi/capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ async def serialize(self, message: MessageChain):
res["content"] = content
return res

async def handle_event(self, event: dict):
maybe_event = await self.event_callback(event)
async def handle_event(self, etype: str, event: dict):
maybe_event = await self.event_callback(etype, event)

if maybe_event is not None:
self.avilla.broadcast.postEvent(maybe_event)
2 changes: 1 addition & 1 deletion avilla/qqapi/connection/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def event_parse_task(_data: Payload):
if event is not None:
if isinstance(event, MessageAudited):
audit_result.add_result(event)
await self.protocol.post_event(event)
await self.protocol.post_event(event) # type: ignore
return
logger.warning(f"received unsupported event {event_type.lower()}: {_data.data}")
return
Expand Down
4 changes: 2 additions & 2 deletions avilla/qqapi/perform/action/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ async def set_name(self, target: Selector, route: ..., name: str):
raise PermissionError(permission_error_message(f"set_name@{target.path}", "read", ["manage"]))

@MuteAllCapability.mute_all.collect(m, target="land.guild.channel")
async def channel_mute_all(self, target: Selector, route: ...):
async def channel_mute_all(self, target: Selector):
await self.account.connection.call_http(
"patch", f"channels/{target.pattern['channel']}", {"speak_permission": 2}
)

@MuteAllCapability.unmute_all.collect(m, target="land.guild.channel")
async def channel_unmute_all(self, target: Selector, route: ...):
async def channel_unmute_all(self, target: Selector):
await self.account.connection.call_http(
"patch", f"channels/{target.pattern['channel']}", {"speak_permission": 1}
)
8 changes: 4 additions & 4 deletions avilla/qqapi/perform/action/guild_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ async def get_mute_info(self, target: Selector, route: ...) -> MuteInfo:

@MuteCapability.mute.collect(m, target="land.guild.channel.member")
async def mute(self, target: Selector, duration: timedelta) -> None:
if not (await self.get_privilege(target)).effective:
self_info = await self.get_privilege_summary(target.into(f"~.member{self.account.route['account']}"))
if not (await self.get_privilege(target, Privilege)).effective:
self_info = await self.get_privilege_summary(target.into(f"~.member{self.account.route['account']}"), Summary)
raise PermissionError(permission_error_message(f"set_permission@{target.path}", self_info.name, ["manage"]))
await self.account.connection.call_http(
"put",
Expand All @@ -101,8 +101,8 @@ async def mute(self, target: Selector, duration: timedelta) -> None:

@MuteCapability.unmute.collect(m, target="land.guild.channel.member")
async def unmute(self, target: Selector) -> None:
if not (await self.get_privilege(target)).effective:
self_info = await self.get_privilege_summary(target.into(f"~.member{self.account.route['account']}"))
if not (await self.get_privilege(target, Privilege)).effective:
self_info = await self.get_privilege_summary(target.into(f"~.member{self.account.route['account']}"), Summary)
raise PermissionError(permission_error_message(f"set_permission@{target.path}", self_info.name, ["manage"]))
await self.account.connection.call_http(
"put",
Expand Down
2 changes: 1 addition & 1 deletion avilla/qqapi/perform/action/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def get_group_message(self, target: Selector, route: ...) -> Message:
)
if result is None:
raise RuntimeError(f"Failed to get message from {target.pattern['channel']}: {target}")
event = await self.account.staff.ext({"connection": self.account.connection}).parse_event(
event = await QQAPICapability(self.account.staff.ext({"connection": self.account.connection})).event_callback(
"message_create", result
)
if TYPE_CHECKING:
Expand Down
14 changes: 7 additions & 7 deletions avilla/qqapi/perform/action/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ async def get_role(self, target: Selector, route: ...) -> Role:
@m.pull("land.guild.role", Summary)
async def get_role_summary(self, target: Selector, route: ...) -> Summary:
return Summary(
(await self.get_role(target)).name,
(await self.get_role(target, Role)).name,
"name of role",
)

@m.pull("land.guild.role", Role >> Summary)
async def get_role_summary1(self, target: Selector, route: ...) -> Summary:
return (await self.get_role_summary(target)).infers(Role >> Summary)
return (await self.get_role_summary(target, Summary)).infers(Role >> Summary)

@m.pull("land.guild.role", Count)
async def get_role_count(self, target: Selector, route: ...) -> Count:
Expand All @@ -56,7 +56,7 @@ async def get_role_count(self, target: Selector, route: ...) -> Count:

@m.pull("land.guild.role", Role >> Count)
async def get_role_count1(self, target: Selector, route: ...) -> Count:
return (await self.get_role_count(target)).infers(Role >> Count)
return (await self.get_role_count(target, Count)).infers(Role >> Count)

@m.pull("land.guild.role", Privilege)
async def get_privilege(self, target: Selector, route: ...) -> Privilege:
Expand All @@ -78,7 +78,7 @@ async def get_privilege(self, target: Selector, route: ...) -> Privilege:

@m.pull("land.guild.role", Role >> Privilege)
async def get_privilege1(self, target: Selector, route: ...) -> Privilege:
return (await self.get_privilege(target)).infers(Role >> Privilege)
return (await self.get_privilege(target, Privilege)).infers(Role >> Privilege)

@m.pull("land.guild.role", Privilege >> Summary)
async def get_privilege_summary(self, target: Selector, route: ...) -> Summary:
Expand All @@ -96,7 +96,7 @@ async def get_privilege_summary(self, target: Selector, route: ...) -> Summary:

@m.pull("land.guild.role", Role >> Privilege >> Summary)
async def get_privilege_summary1(self, target: Selector, route: ...) -> Summary:
return (await self.get_privilege_summary(target)).infers(Role >> Privilege >> Summary)
return (await self.get_privilege_summary(target, Summary)).infers(Role >> Privilege >> Summary)

@m.pull("land.guild.role", MuteInfo)
async def get_mute_info(self, target: Selector, route: ...) -> MuteInfo:
Expand All @@ -114,7 +114,7 @@ async def get_mute_info(self, target: Selector, route: ...) -> MuteInfo:

@MuteCapability.mute.collect(m, target="land.guild.role")
async def mute(self, target: Selector, duration: timedelta) -> None:
if not (await self.get_privilege(target)).effective:
if not (await self.get_privilege(target, Privilege)).effective:
raise PermissionError(permission_error_message(f"set_permission@{target.path}", "read", ["manage"]))
await self.account.connection.call_http(
"put",
Expand All @@ -124,7 +124,7 @@ async def mute(self, target: Selector, duration: timedelta) -> None:

@MuteCapability.unmute.collect(m, target="land.guild.role")
async def unmute(self, target: Selector) -> None:
if not (await self.get_privilege(target)).effective:
if not (await self.get_privilege(target, Privilege)).effective:
raise PermissionError(permission_error_message(f"set_permission@{target.path}", "read", ["manage"]))
await self.account.connection.call_http(
"put",
Expand Down
2 changes: 1 addition & 1 deletion avilla/qqapi/perform/message/deserialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def mention(self, raw_element: dict) -> Notice:
return Notice(Selector().land("qqguild").member(raw_element["user_id"]))

@m.entity(QQAPICapability.deserialize_element, raw_element="mention_channel")
async def mention(self, raw_element: dict) -> Notice:
async def mention_channel(self, raw_element: dict) -> Notice:
if self.context:
return Notice(
Selector().land("qqguild").guild(self.context.scene["guild"]).channel(raw_element["channel_id"])
Expand Down
4 changes: 2 additions & 2 deletions avilla/qqapi/perform/message/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ async def markdown(self, element: Markdown):
"key": slot[0],
"value": slot[1],
}
if (slot := element.params.popitem())
if element.params and (slot := element.params.popitem())
else None,
}

@m.entity(QQAPICapability.serialize_element, element=Keyboard)
async def keyboard(self, element: Keyboard):
content = {"rows": []}
for row in element.content:
for row in element.content or []:
buttons = {"buttons": []}
for button in row:
raw = asdict(button)
Expand Down
18 changes: 9 additions & 9 deletions avilla/qqapi/perform/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class QQAPIQueryPerform((m := AccountCollector["QQAPIProtocol", "QQAPIAccount"](
m.namespace = "avilla.protocol/qqapi::query"

@m.entity(CoreCapability.query, target="land.guild")
async def query_guild_channels(self, predicate: Callable[[str, str], bool] | str, previous: None):
result = await self.account.connection.call("get", f"users/@me/guilds", {})
async def query_guilds(self, predicate: Callable[[str, str], bool] | str, previous: None):
result = await self.account.connection.call_http("get", f"users/@me/guilds", {})
result = cast(list, result)
for i in result:
guild_id = str(i["id"])
Expand All @@ -25,7 +25,7 @@ async def query_guild_channels(self, predicate: Callable[[str, str], bool] | str

@m.entity(CoreCapability.query, target="channel", previous="land.guild")
async def query_guild_channels(self, predicate: Callable[[str, str], bool] | str, previous: Selector):
result = await self.account.connection.call("get", f"guilds/{previous.pattern['guild']}/channels", {})
result = await self.account.connection.call_http("get", f"guilds/{previous.pattern['guild']}/channels", {})
result = cast(list, result)
for i in result:
channel_id = str(i["id"])
Expand All @@ -34,7 +34,7 @@ async def query_guild_channels(self, predicate: Callable[[str, str], bool] | str

@m.entity(CoreCapability.query, target="member", previous="land.guild")
async def query_guild_users(self, predicate: Callable[[str, str], bool] | str, previous: Selector):
result = await self.account.connection.call("get", f"guilds/{previous.pattern['guild']}/members", {})
result = await self.account.connection.call_http("get", f"guilds/{previous.pattern['guild']}/members", {})
result = cast(list, result)
for i in result:
user_id = str(i["user"]["id"])
Expand All @@ -43,7 +43,7 @@ async def query_guild_users(self, predicate: Callable[[str, str], bool] | str, p

@m.entity(CoreCapability.query, target="member", previous="land.guild.channel")
async def query_guild_members(self, predicate: Callable[[str, str], bool] | str, previous: Selector):
result = await self.account.connection.call("get", f"guilds/{previous.pattern['guild']}/members", {})
result = await self.account.connection.call_http("get", f"guilds/{previous.pattern['guild']}/members", {})
result = cast(list, result)
for i in result:
user_id = str(i["user"]["id"])
Expand All @@ -52,15 +52,15 @@ async def query_guild_members(self, predicate: Callable[[str, str], bool] | str,

@m.entity(CoreCapability.query, target="member", previous="land.group")
async def query_group_members(self, predicate: Callable[[str, str], bool] | str, previous: Selector):
result = await self.account.connection.call("post", f"v2/groups/{previous.pattern['group']}/members", {})
result = await self.account.connection.call_http("post", f"v2/groups/{previous.pattern['group']}/members", {})
for i in result["members"]:
member_id = str(i["member_openid"])
if callable(predicate) and predicate("member", member_id) or member_id == predicate:
yield previous.member(member_id)

@m.entity(CoreCapability.query, target="member", previous="land.guild.role")
async def query_guild_role_members(self, predicate: Callable[[str, str], bool] | str, previous: Selector):
result = await self.account.connection.call(
result = await self.account.connection.call_http(
"get", f"guilds/{previous.pattern['guild']}/roles/{previous.pattern['role']}/members", {}
)
for i in result["data"]:
Expand All @@ -70,15 +70,15 @@ async def query_guild_role_members(self, predicate: Callable[[str, str], bool] |

@m.entity(CoreCapability.query, target="role", previous="land.guild")
async def query_guild_roles(self, predicate: Callable[[str, str], bool] | str, previous: Selector):
result = await self.account.connection.call("get", f"guilds/{previous.pattern['guild']}/roles", {})
result = await self.account.connection.call_http("get", f"guilds/{previous.pattern['guild']}/roles", {})
for i in result["roles"]:
role_id = str(i["id"])
if callable(predicate) and predicate("role", role_id) or role_id == predicate:
yield previous.role(role_id)

@m.entity(CoreCapability.query, target="role", previous="land.guild.user")
async def query_guild_user_roles(self, predicate: Callable[[str, str], bool] | str, previous: Selector):
user = await self.account.connection.call(
user = await self.account.connection.call_http(
"get", f"guilds/{previous.pattern['guild']}/members/{previous.pattern['user']}", {}
)
for i in user["roles"]:
Expand Down

0 comments on commit 355756b

Please sign in to comment.