Skip to content

Commit

Permalink
update: 支持 md 模版和按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien8261 committed Jan 4, 2024
1 parent 9465ce4 commit 6b3d7f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
4 changes: 0 additions & 4 deletions amiyabot/adapters/tencent/qqGuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ async def build_message_send(chain: Chain, custom_chain: Optional[CHAIN_LIST] =
if isinstance(item, Markdown):
messages.add_data(item.get())

# Keyboard
if isinstance(item, Keyboard):
messages.add_data(item.get())

messages.done()

return messages
14 changes: 8 additions & 6 deletions amiyabot/builtin/messageChain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ def markdown(
render_time=render_time,
)

def markdown_template(self, template_id: str, params: List[dict]):
self.chain.append(Markdown(template_id, params))
return self

def keyboard(self, keyboard: Optional[InlineKeyboard] = None, template_id: Optional[str] = ''):
self.chain.append(Keyboard(template_id, keyboard))
def markdown_template(
self,
template_id: str,
params: List[dict],
keyboard: Optional[InlineKeyboard] = None,
keyboard_template_id: Optional[str] = '',
):
self.chain.append(Markdown(template_id, params, keyboard, keyboard_template_id))
return self

def embed(self, title: str, prompt: str, thumbnail: str, fields: List[str]):
Expand Down
27 changes: 8 additions & 19 deletions amiyabot/builtin/messageChain/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,34 +190,24 @@ def get(self):
class Markdown:
template_id: str
params: List[dict]
keyboard: Optional[InlineKeyboard] = None
keyboard_template_id: Optional[str] = ''

def get(self):
return {
data = {
'markdown': {
'custom_template_id': self.template_id,
'params': self.params,
}
}

if self.keyboard:
data.update({'keyboard': {'content': self.keyboard.dict()}})

@dataclass
class Keyboard:
template_id: Optional[str] = ''
keyboard: Optional[InlineKeyboard] = None
if self.keyboard_template_id:
data.update({'keyboard': {'id': self.keyboard_template_id}})

def get(self):
if self.keyboard:
return {
'keyboard': {
'content': self.keyboard.dict(),
}
}
else:
return {
'keyboard': {
'id': self.template_id,
}
}
return data


@dataclass
Expand All @@ -243,7 +233,6 @@ def get(self):
Embed,
Ark,
Markdown,
Keyboard,
Extend,
]
CHAIN_LIST = List[CHAIN_ITEM]

0 comments on commit 6b3d7f1

Please sign in to comment.