Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 keyboard #92

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.8', '3.9' ]
python-version: [ '3.8' ]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
18 changes: 18 additions & 0 deletions amiyabot/adapters/tencent/qqGroup/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,24 @@ async def insert_media(url: str, file_type: int = 1):
if isinstance(item, Html):
await insert_media(await item.create_html_image())

# Ark
if isinstance(item, Ark):
payload.msg_type = 3
payload.ark = item.get()['ark']

refresh_payload()

# Markdown
if isinstance(item, Markdown):
md = item.get()

payload.msg_type = 2
payload.markdown = md['markdown']
if 'keyboard' in md:
payload.keyboard = md['keyboard']

refresh_payload()

if payload.content:
payload_list.append(payload)

Expand Down
3 changes: 1 addition & 2 deletions amiyabot/builtin/lib/imageCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def __parse(self):
length += self.__font_seat(char)[0]
sub_text += char

if length > self.width_seat:
self.width_seat = length
self.width_seat = max(self.width_seat, length)

is_end = idx == len(text) - 1
if length >= self.max_seat or char == '\n' or is_end:
Expand Down
43 changes: 34 additions & 9 deletions amiyabot/builtin/messageChain/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@dataclass
class Permission:
type: int = 1
type: int = 2
specify_role_ids: List[str] = field(default_factory=lambda: ['1', '2', '3'])
specify_user_ids: List[str] = field(default_factory=lambda: [])

Expand All @@ -13,17 +13,20 @@ class Permission:
class RenderData:
label: str = ''
visited_label: str = ''
style: int = 0


@dataclass
class Action:
type: int = 1
type: int = 2
data: str = ''
anchor: int = 0
unsupport_tips: str = ''

click_limit: int = 10

reply: bool = False
enter: bool = False
anchor: bool = False
at_bot_show_channel_list: bool = False

permission: Permission = field(default_factory=Permission)
Expand All @@ -43,21 +46,43 @@ class Row:
def add_button(
self,
button: Union[str, Button],
label: str,
visited_label: Optional[str] = None,
action_type: int = 1,
rander_label: str,
rander_visited_label: str = '',
rander_style: int = 0,
action_type: int = 2,
action_data: str = '',
action_anchor: int = 0,
action_unsupport_tips: str = '',
action_click_limit: int = 10,
action_reply: bool = False,
action_enter: bool = False,
action_at_bot_show_channel_list: bool = False,
permission_type: int = 2,
permission_specify_role_ids: Optional[List[str]] = None,
permission_specify_user_ids: Optional[List[str]] = None,
):
if len(self.buttons) >= 5:
raise OverflowError('Create up to 5 buttons per row')

if isinstance(button, str):
button = Button(button)

button.render_data.label = label
button.render_data.visited_label = visited_label or label
button.render_data.label = rander_label
button.render_data.visited_label = rander_visited_label or rander_label
button.render_data.style = rander_style

button.action.type = action_type
button.action.data = action_data or button.id
button.action.data = action_data or rander_label
button.action.anchor = action_anchor
button.action.unsupport_tips = action_unsupport_tips
button.action.click_limit = action_click_limit
button.action.reply = action_reply
button.action.enter = action_enter
button.action.at_bot_show_channel_list = action_at_bot_show_channel_list

button.action.permission.type = permission_type
button.action.permission.specify_role_ids = permission_specify_role_ids
button.action.permission.specify_user_ids = permission_specify_user_ids

self.buttons.append(button)

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jieba~=0.42.1
peewee~=3.14.10
pillow~=9.5.0
playwright~=1.31.1
pydantic~=1.9.1
pydantic~=1.10.0
pymysql~=1.0.2
pyyaml~=6.0
requests~=2.27.1
setuptools~=60.2.0
starlette~=0.19.1
uvicorn~=0.18.2
websockets~=10.1
zhon~=1.1.5
zhon~=1.1.5
Loading