Skip to content

Commit

Permalink
🐛 version 0.1.1
Browse files Browse the repository at this point in the history
fix keyboard
  • Loading branch information
RF-Tar-Railt committed Apr 22, 2024
1 parent 7f0950e commit d52bb8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nonebot-adapter-kritor"
version = "0.1.0"
version = "0.1.1"
description = "Nonebot Adapter for Kritor Protocol"
authors = [
{name = "rf_tar_railt", email = "[email protected]"},
Expand Down
46 changes: 16 additions & 30 deletions src/nonebot/adapters/kritor/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
from .model import SceneType
from .protos.kritor.common import Scene as KritorScene
from .protos.kritor.common import (
Button,
Element,
KeyboardRow,
ContactElement,
KeyboardElement,
ElementElementType,
ImageElementImageType,
MusicElementMusicPlatform,
Expand Down Expand Up @@ -204,8 +207,8 @@ def markdown(markdown: str) -> "Markdown":
return Markdown("markdown", {"markdown": markdown})

@staticmethod
def button(bot_appid: int, rows: list[list["ButtonData"]]) -> "Keyboard":
return Keyboard("button", {"bot_appid": bot_appid, "rows": [{"buttons": row} for row in rows]})
def keyboard(bot_appid: int, buttons: list[list[Button]]) -> "Keyboard":
return Keyboard("keyboard", {"bot_appid": bot_appid, "rows": [{"buttons": row} for row in buttons]})


class TextData(TypedDict):
Expand Down Expand Up @@ -480,35 +483,8 @@ class Markdown(MessageSegment, element_type=ElementElementType.MARKDOWN):
data: MarkdownData = field(default_factory=dict) # type: ignore


class ButtonActionPermissionData(TypedDict):
type: int
role_ids: list[int]
user_ids: list[int]


class ButtonActionData(TypedDict):
type: int
permission: ButtonActionPermissionData
unsupported_tips: str
data: str
reply: bool
enter: bool


class ButtonRenderData(TypedDict):
label: str
visited_label: str
style: int


class ButtonData(TypedDict):
id: str
render_data: ButtonRenderData
action: ButtonActionData


class KeyboardRowData(TypedDict):
buttons: list[ButtonData]
buttons: list[Button]


class KeyboardData(TypedDict):
Expand All @@ -520,6 +496,16 @@ class KeyboardData(TypedDict):
class Keyboard(MessageSegment, element_type=ElementElementType.KEYBOARD):
data: KeyboardData = field(default_factory=dict) # type: ignore

@override
def dump(self) -> "Element":
return Element(
type=ElementElementType.KEYBOARD,
keyboard=KeyboardElement(
rows=[KeyboardRow(buttons=row["buttons"]) for row in self.data["rows"]],
bot_appid=self.data["bot_appid"],
),
)


TYPE_MAPPING = {cls.__element_type__: cls for cls in MessageSegment.__subclasses__()} # type: ignore

Expand Down

0 comments on commit d52bb8c

Please sign in to comment.