一个构建开黑啦卡片的工具
Project description
KaiheilaCardBuilder
一个构造开黑啦卡片的工具
使用方法
from khl_card import *
# 新建卡片
# 这里构建了一个卡片,带有一个模块
card = Card(Section(Kmarkdown('测试卡片')))
# 给卡片添加模块,这里是分割线
card.append(Divider())
# 拥有的模块列表,具体用法参考开黑啦官方文档
['Header', 'Section', 'ImageGroup', 'Container', 'Context', 'ActionGroup', 'File', 'Audio', 'Video', 'Divider',
'Invite', 'Countdown']
# 拥有的元素列表,具体用法参考开黑啦官方文档
['PlainText', 'Kmarkdown', 'Paragraph', 'Image', 'Button', '_BaseAccessory']
# 倒计时模块的简便创建
card.append(Countdown.new_day_countdown('2022-07-05 08:00:00'))
card.append(Countdown.new_hour_countdown('2022-07-05 08:00:00'))
card.append(Countdown.new_second_countdown('2022-07-05 08:00:00'))
# 现在支持链式调用
card.append(Section(Kmarkdown('调用1'))).append(Section(Kmarkdown('调用2'))).append(Section(Kmarkdown('调用3')))
# 构建卡片,返回的卡片的字典
card.build()
# 构建卡片,返回官方编辑器可以用的 json 文本
print(card.build_to_json())
# 输出:
{
"type": "card",
"theme": "primary",
"size": "lg",
"modules": [
{
"type": "section",
"mode": "right",
"text": {
"type": "kmarkdown",
"content": "测试卡片"
}
},
{
"type": "divider"
},
{
"type": "countdown",
"mode": "day",
"endTime": 1656979200000,
"startTime": 1655827836854
},
{
"type": "countdown",
"mode": "hour",
"endTime": 1656979200000,
"startTime": 1655827836854
},
{
"type": "countdown",
"mode": "second",
"endTime": 1656979200000,
"startTime": 1655827836891
},
{
"type": "section",
"mode": "right",
"text": {
"type": "kmarkdown",
"content": "调用1"
}
},
{
"type": "section",
"mode": "right",
"text": {
"type": "kmarkdown",
"content": "调用2"
}
},
{
"type": "section",
"mode": "right",
"text": {
"type": "kmarkdown",
"content": "调用3"
}
}
]
}
# 现在可以使用 CardMessageBuilder 来构造卡片消息
cm = CardMessageBuilder().card(
CardBuilder()
.image_group(
ImageGroupBuilder()
.add(Image('http://img.sdadad'))
.build()
)
.context(
ContextBuilder()
.add(Kmarkdown.bold('Test context: ') + Kmarkdown('abcde')) # 现在 KMD 也能够使用 + 拼接了
.build()
)
.divider()
.invite('asfws66')
.container(
ContainerBuilder()
.add(Image('http://img.sdadad'))
.add(Image('http://img.sdadad'))
.build()
)
.header('This is a header')
.section(Kmarkdown('This is a section'))
.file('file_url', 'title')
.audio('src', 'title', 'cover')
.build()
).build()
print(cm.build_to_json())
# 输出:
[
{
"type": "card",
"theme": "primary",
"size": "lg",
"modules": [
{
"type": "image-group",
"elements": [
{
"type": "image",
"src": "http://img.sdadad",
"alt": "",
"size": "lg",
"circle": false
}
]
},
{
"type": "context",
"elements": [
{
"type": "kmarkdown",
"content": "**Test context: **abcde"
}
]
},
{
"type": "divider"
},
{
"type": "invite",
"code": "asfws66"
},
{
"type": "container",
"elements": [
{
"type": "image",
"src": "http://img.sdadad",
"alt": "",
"size": "lg",
"circle": false
},
{
"type": "image",
"src": "http://img.sdadad",
"alt": "",
"size": "lg",
"circle": false
}
]
},
{
"type": "header",
"text": {
"type": "plain-text",
"content": "This is a header"
}
},
{
"type": "section",
"mode": "right",
"text": {
"type": "kmarkdown",
"content": "This is a section"
}
},
{
"type": "file",
"src": "file_url",
"title": "title"
},
{
"type": "audio",
"src": "src",
"title": "title",
"cover": "cover"
}
]
}
]
更新日志
1.3.0
添加 CardMessageBuilder
CardBuilder
ImageGroupBuilder
ContainerBuilder
ContextBuilder
ActionGroupBuilder
来快捷的构造卡片
添加KMD的特殊用法快捷,KMD能够使用 +
拼接。例:Kmarkdown.bold('Test context: ') + Kmarkdown('abcde')
1.2.5
添加 CardMessage
, Button
可以使用 ThemeTypes
1.2.4
Section 能够使用结构体
1.2.3
修改结构,Paragraph
不应该属于文字类元素
1.2.2
添加 Card
的链式调用
1.2.1
现在 Card
构建使用可变参数
1.1.1
卡片按钮现在使用 PlainText
或 Kmarkdown
1.1.0
添加 Card
的一些方法
修复 Button
的构建 bug
修复 Color
中 __str__
的问题
为倒计时模块添加快速创建方法
from khl_card.modules import *
Countdown.new_day_countdown('2022-05-05 08:00:00')
Countdown.new_hour_countdown('2022-05-05 08:00:00')
Countdown.new_second_countdown('2022-05-05 08:00:00')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file kaiheilacardbuilder_m-1.3.0.tar.gz
.
File metadata
- Download URL: kaiheilacardbuilder_m-1.3.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.7.4 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecb3b2d7f4a52bfe084c97d4cee1fb305852084f4566df233d83351b648186d3 |
|
MD5 | 26de582e33169ab6e504cde1fdd01667 |
|
BLAKE2b-256 | c8e0e1c69fd5bba8d4f981a0ca5c07b67723515aea14757eacdb3fc11b6e86c5 |
File details
Details for the file kaiheilacardbuilder_m-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: kaiheilacardbuilder_m-1.3.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.7.4 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdf6f9d8acfa1677c68935d911c80208696695fbecaa36528be3938f0b2eccea |
|
MD5 | 6b588e2e81fa9342626138f34be805cb |
|
BLAKE2b-256 | d7bb66492167783e4297c0555e24b22413222146690303d882c94b9131e8f9b7 |