From fddbc732eff735c977ea25b7120d48489fd7dd12 Mon Sep 17 00:00:00 2001 From: snowy Date: Fri, 20 Oct 2023 22:04:44 +0800 Subject: [PATCH] edit readme --- src/api/canvas.py | 70 +++++++++++++++++++++++++++++++++++ src/liteyuki_main/__init__.py | 37 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/api/canvas.py diff --git a/src/api/canvas.py b/src/api/canvas.py new file mode 100644 index 00000000..93a0ba30 --- /dev/null +++ b/src/api/canvas.py @@ -0,0 +1,70 @@ +# 写一个UINode基类,所有的UI节点都继承自这个基类 +# 其他不同的基类例如文本,图像,面板都继承自UINode +# UI节点从任意树形节点可以被渲染通过Pillow +# UI节点可以被渲染成图片,也可以被渲染成PDF +# UI节点可以被渲染成图片,也可以被渲染成PDF +# UI节点可以被渲染成图片,也可以被渲染成PDF + +# Path: src/api/canvas.py +class UINode: + def __init__(self): + self.children = [] + self.parent = None + self.x = 0 + self.y = 0 + self.width = 0 + self.height = 0 + self.visible = True + self.z_index = 0 + self.background_color = None + self.background_image = None + self.border_color = None + self.border_width = 0 + self.border_radius = 0 + self.border_style = None + self.padding = 0 + self.margin = 0 + self.shadow = None + + def add_child(self, child): + self.children.append(child) + child.parent = self + + def remove_child(self, child): + self.children.remove(child) + child.parent = None + + def render(self, canvas): + if not self.visible: + return + self.render_background(canvas) + self.render_border(canvas) + self.render_padding(canvas) + self.render_margin(canvas) + self.render_shadow(canvas) + self.render_self(canvas) + self.render_children(canvas) + + def render_children(self, canvas): + for child in self.children: + child.render(canvas) + + + def render_background(self, canvas): + + + + def render_border(self, canvas): + pass + + def render_padding(self, canvas): + pass + + def render_margin(self, canvas): + pass + + def render_shadow(self, canvas): + pass + + def render_self(self, canvas): + pass diff --git a/src/liteyuki_main/__init__.py b/src/liteyuki_main/__init__.py index 74f32591..7388d31f 100644 --- a/src/liteyuki_main/__init__.py +++ b/src/liteyuki_main/__init__.py @@ -22,6 +22,7 @@ load_resource_from_index() async def detect_superuser(bot: Bot): db = Data('common', 'config') db.remove('auth_code') + # print a data to detect if there is superusers if not len(bot.config.superusers): auth_code = str(random.randint(1000, 9999)) db.set('auth_code', auth_code) @@ -47,6 +48,42 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg(), ): logger.opt(colors=True).warning(Language().get('log.main.fail_to_reg_su', USER_ID=event.user_id)) +@echo.handle() +async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg(), ): + await echo.send(arg) + + @su_test.handle() async def _(): await su_test.send('suc') + + +@ban.handle() +async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg(), ): + await bot.call_api('set_group_ban', group_id=event.group_id, user_id=int(arg), duration=60 * 60 * 24 * 365 * 10) + await ban.send('suc') + + +def decode_text(text: str): + # input a string, output a string + # transfer cqcode to text + replace_data = { + '&': '&', + '[': '[', + ']': ']', + ',': ',', + '%20': ' ' + } + for old, new in replace_data.items(): + text = text.replace(old, new) + return text + + +def list_all_folder(path: str): + # input a path, output a list + # list all folder in the path + folder_list = [] + for folder in os.listdir(path): + if os.path.isdir(os.path.join(path, folder)): + folder_list.append(folder) + return folder_list