PagerMaid_Plugins/square.py

37 lines
1.1 KiB
Python
Raw Normal View History

from pagermaid.listener import listener
from pagermaid.utils import alias_command
2022-01-18 08:47:20 +00:00
from pagermaid import version
@listener(is_plugin=True, outgoing=True, command=alias_command("square"),
description="生成文本矩形",
2021-07-31 13:21:03 +00:00
parameters="<文本> <行> <列>")
async def square(context):
2021-07-31 13:21:03 +00:00
if not len(context.parameter) > 2:
await context.edit('出错了呜呜呜 ~ 参数错误。')
return
2021-07-31 13:21:03 +00:00
parameters = context.parameter[-2:]
hang = parameters[0]
lie = parameters[1]
try:
hang = int(hang)
lie = int(lie)
except ValueError:
await context.edit('出错了呜呜呜 ~ 参数错误。')
return
if hang < 1 or lie < 1:
await context.edit('出错了呜呜呜 ~ 参数错误。')
return
2021-07-31 13:21:03 +00:00
parameters = [i for i in context.parameter if i not in parameters]
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)