diff options
author | Kyomotoi <[email protected]> | 2021-01-27 21:47:58 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2021-01-27 21:47:58 +0800 |
commit | eb52fab79ada7efe6191e3a5f90179766feaded0 (patch) | |
tree | ad6e513148203a6279ce8c72e9fb26fd7b415f95 /ATRI/plugins/setu/__init__.py | |
parent | b0b3a8c468b612502aea700fe59d9c885adf83dc (diff) | |
download | ATRI-eb52fab79ada7efe6191e3a5f90179766feaded0.tar.gz ATRI-eb52fab79ada7efe6191e3a5f90179766feaded0.tar.bz2 ATRI-eb52fab79ada7efe6191e3a5f90179766feaded0.zip |
[Update]
Diffstat (limited to 'ATRI/plugins/setu/__init__.py')
-rw-r--r-- | ATRI/plugins/setu/__init__.py | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/ATRI/plugins/setu/__init__.py b/ATRI/plugins/setu/__init__.py index 68cb1d2..2d630de 100644 --- a/ATRI/plugins/setu/__init__.py +++ b/ATRI/plugins/setu/__init__.py @@ -1,13 +1,23 @@ -from nonebot.plugin import on_regex +import random + +from nonebot.plugin import on_regex, on_command +from nonebot.adapters.cqhttp.message import MessageSegment, Message from nonebot.adapters.cqhttp import Bot +from nonebot.permission import SUPERUSER from nonebot.adapters.cqhttp.event import MessageEvent from ATRI.service.plugin import Plugin from ATRI.config import SETU_CONFIG +from ATRI.utils import compress_image +from ATRI.request import Request from ATRI.rule import is_in_service, is_in_ban_list, is_in_dormant +from .data_source import setu_port + # ===========================[Begin Command Processing]=========================== +resolution = 1 + __plugin_name__ = 'setu' __doc__ = """ @@ -23,7 +33,45 @@ setu = on_regex('|'.join(SETU_CONFIG['setu']['command']), @setu.handle() async def _(bot: Bot, event: MessageEvent) -> None: await bot.send(event, SETU_CONFIG['setu']['repo']['waiting']) + rd = random.randint(1, 2) + + if rd == 1: + data = await setu_port() + else: + data = await setu_port() + + if resolution == 1: + img = compress_image(await Request.get_image(data['data'][0]['url'])) + else: + img = await Request.get_image(data['data'][0]['url']) + msg0 = ( + f"{data['data'][0]['title']}\n" + f"pid: {data['data'][0]['pid']}\n" + f"{MessageSegment.image(file=f'file:///{img}')}" + ) + + await setu.finish(Message(msg0)) + + +setu_resolution = on_command(SETU_CONFIG['admin']['command'][0], + aliases=set(SETU_CONFIG['admin']['command']), + permission=SUPERUSER) + +@setu_resolution.handle() +async def _(bot, event: MessageEvent, state: dict) -> None: + msg = str(event.get_message()).strip() + if msg: + state['msg'] = msg + +@setu_resolution.got('msg', prompt='请键入正确参数奥') +async def _(bot, event: MessageEvent, state: dict) -> None: + global resolution + resolution = int(state['msg']) + if resolution == 1: + await setu_resolution.finish('完成~!已启用涩图压缩') + else: + await setu_resolution.finish('完成~!已关闭涩图压缩') -# ===========================[End Command Processing]=============================
\ No newline at end of file +# ===========================[End Command Processing]============================= |