square 生成文本矩形 (#177)

Co-authored-by: Xtao_dada <xtao@xtaolink.cn>
This commit is contained in:
Vesugierii 2021-07-31 21:06:12 +08:00 committed by GitHub
parent 28fe2fe808
commit 3304b60d1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View File

@ -679,6 +679,16 @@
"supported": true,
"des-short": "智能聊天机器人。(支持回复)",
"des": "使用自然语言处理 (NLP) 来帮助用户通过文本进行交互。(支持回复)。\n指令-chatbot"
},
{
"name": "square",
"version": "1.0",
"section": "chat",
"maintainer": "Vesugierii",
"size": "1.2 kb",
"supported": true,
"des-short": "生成文本矩形",
"des": "指令:-square"
}
]
}

35
square.py Normal file
View File

@ -0,0 +1,35 @@
from pagermaid.listener import listener
from pagermaid.utils import alias_command
@listener(is_plugin=True, outgoing=True, command=alias_command("square"),
description="生成文本矩形",
parameters="<行> <列> <文本>")
async def square(context):
if not len(context.parameter):
await context.edit('出错了呜呜呜 ~ 参数错误。')
return
hang = context.parameter[0]
lie = context.parameter[1]
try:
hang = int(hang)
lie = int(lie)
except ValueError:
await context.edit('出错了呜呜呜 ~ 参数错误。')
return
if hang < 1 or lie < 1:
await context.edit('出错了呜呜呜 ~ 参数错误。')
return
parameters = context.parameter
del parameters[0]
del parameters[0]
text = " ".join(parameters)
text *= lie
text = text.strip()
result = []
for i in range(hang):
result.append(text)
result = '\n'.join(result)
if len(result) > 4096:
await context.edit('出错了呜呜呜 ~ 文本过长。')
else:
await context.edit(result)