This commit is contained in:
jxxghp 2023-09-05 11:20:06 +08:00
parent 4bf9045784
commit 2826b9411d
11 changed files with 55 additions and 27 deletions

View File

@ -396,7 +396,7 @@ class ChainBase(metaclass=ABCMeta):
return self.run_module("scrape_metadata", path=path, mediainfo=mediainfo)
return None
def register_commands(self, commands: dict) -> None:
def register_commands(self, commands: Dict[str, dict]) -> None:
"""
注册菜单命令
"""

View File

@ -53,11 +53,13 @@ class Command(metaclass=Singleton):
"/cookiecloud": {
"func": CookieCloudChain(self._db).remote_sync,
"description": "同步站点",
"category": "站点",
"data": {}
},
"/sites": {
"func": SiteChain(self._db).remote_list,
"description": "查询站点",
"category": "站点",
"data": {}
},
"/site_cookie": {
@ -78,21 +80,25 @@ class Command(metaclass=Singleton):
"/mediaserver_sync": {
"func": MediaServerChain(self._db).remote_sync,
"description": "同步媒体服务器",
"category": "管理",
"data": {}
},
"/subscribes": {
"func": SubscribeChain(self._db).remote_list,
"description": "查询订阅",
"category": "订阅",
"data": {}
},
"/subscribe_refresh": {
"func": SubscribeChain(self._db).remote_refresh,
"description": "刷新订阅",
"category": "订阅",
"data": {}
},
"/subscribe_search": {
"func": SubscribeChain(self._db).remote_search,
"description": "搜索订阅",
"category": "订阅",
"data": {}
},
"/subscribe_delete": {
@ -103,11 +109,13 @@ class Command(metaclass=Singleton):
"/downloading": {
"func": DownloadChain(self._db).remote_downloading,
"description": "正在下载",
"category": "下载",
"data": {}
},
"/transfer": {
"func": TransferChain(self._db).process,
"description": "下载文件整理",
"category": "下载",
"data": {}
},
"/redo": {
@ -118,6 +126,7 @@ class Command(metaclass=Singleton):
"/clear_cache": {
"func": SystemChain(self._db).remote_clear_cache,
"description": "清理缓存",
"category": "管理",
"data": {}
}
}
@ -128,6 +137,7 @@ class Command(metaclass=Singleton):
cmd=command.get('cmd'),
func=Command.send_plugin_event,
desc=command.get('desc'),
category=command.get('category'),
data={
'etype': command.get('event'),
'data': command.get('data')
@ -171,13 +181,15 @@ class Command(metaclass=Singleton):
"""
return self._commands
def register(self, cmd: str, func: Any, data: dict = None, desc: str = None) -> None:
def register(self, cmd: str, func: Any, data: dict = None,
desc: str = None, category: str = None) -> None:
"""
注册命令
"""
self._commands[cmd] = {
"func": func,
"description": desc,
"category": category,
"data": data or {}
}

View File

@ -1,5 +1,5 @@
import json
from typing import Optional, Union, List, Tuple, Any
from typing import Optional, Union, List, Tuple, Any, Dict
from app.core.context import MediaInfo, Context
from app.core.config import settings
@ -120,7 +120,7 @@ class TelegramModule(_ModuleBase):
"""
return self.telegram.send_torrents_msg(title=message.title, torrents=torrents, userid=message.userid)
def register_commands(self, commands: dict):
def register_commands(self, commands: Dict[str, dict]):
"""
注册命令实现这个函数接收系统可用的命令菜单
:param commands: 命令字典

View File

@ -2,7 +2,7 @@ import re
import threading
from pathlib import Path
from threading import Event
from typing import Optional, List
from typing import Optional, List, Dict
import telebot
from telebot import apihelper
@ -198,7 +198,7 @@ class Telegram(metaclass=Singleton):
return True if ret else False
def register_commands(self, commands: dict):
def register_commands(self, commands: Dict[str, dict]):
"""
注册菜单命令
"""

View File

@ -1,5 +1,5 @@
import xml.dom.minidom
from typing import Optional, Union, List, Tuple, Any
from typing import Optional, Union, List, Tuple, Any, Dict
from app.core.config import settings
from app.core.context import Context, MediaInfo
@ -152,7 +152,7 @@ class WechatModule(_ModuleBase):
"""
return self.wechat.send_torrents_msg(title=message.title, torrents=torrents, userid=message.userid)
def register_commands(self, commands: dict):
def register_commands(self, commands: Dict[str, dict]):
"""
注册命令实现这个函数接收系统可用的命令菜单
:param commands: 命令字典

View File

@ -2,7 +2,7 @@ import json
import re
import threading
from datetime import datetime
from typing import Optional, List
from typing import Optional, List, Dict
from app.core.config import settings
from app.core.context import MediaInfo, Context
@ -273,7 +273,7 @@ class WeChat(metaclass=Singleton):
logger.error(f"发送请求失败,错误信息:{err}")
return False
def create_menus(self, commands: dict):
def create_menus(self, commands: Dict[str, dict]):
"""
自动注册微信菜单
:param commands: 命令字典
@ -282,10 +282,11 @@ class WeChat(metaclass=Singleton):
"/cookiecloud": {
"func": CookieCloudChain(self._db).remote_sync,
"description": "同步站点",
"category": "站点",
"data": {}
}
}
注册报文格式
注册报文格式子菜单最多只有5条
{
"button":[
{
@ -313,24 +314,34 @@ class WeChat(metaclass=Singleton):
"""
# 请求URL
req_url = self._create_menu_url % (self.__get_access_token(), self._appid)
# 按钮
buttons = []
# 对commands按category分组
category_dict = {}
for key, value in commands.items():
category: Dict[str, dict] = value.get("category")
if category:
if not category_dict.get(category):
category_dict[category] = {}
category_dict[category][key] = value
# 一级菜单
buttons = []
for category, menu in category_dict.items():
# 二级菜单
sub_buttons = []
for key, value in menu.items():
sub_buttons.append({
"type": "click",
"name": value.get("description"),
"key": key
})
buttons.append({
"type": "click",
"name": value.get("description"),
"key": key
"name": category,
"sub_button": sub_buttons
})
if buttons:
# 请求参数
menus = {
"button": [
{
"name": "操作",
"sub_button": buttons
}
]
}
# 发送请求
self.__post_request(req_url, menus)
self.__post_request(req_url, {
"button": buttons
})

View File

@ -65,7 +65,8 @@ class _PluginBase(metaclass=ABCMeta):
[{
"cmd": "/xx",
"event": EventType.xx,
"desc": "xxxx",
"desc": "名称",
"category": "分类需要注册到Wechat时必须有分类",
"data": {}
}]
"""

View File

@ -212,6 +212,7 @@ class AutoSignIn(_PluginBase):
"cmd": "/site_signin",
"event": EventType.SiteSignin,
"desc": "站点签到",
"category": "站点",
"data": {}
}]

View File

@ -133,6 +133,7 @@ class DoubanSync(_PluginBase):
"cmd": "/douban_sync",
"event": EventType.DoubanSync,
"desc": "同步豆瓣想看",
"category": "订阅",
"data": {}
}]

View File

@ -110,6 +110,7 @@ class MediaSyncDel(_PluginBase):
"cmd": "/sync_del",
"event": EventType.HistoryDeleted,
"desc": "媒体库同步删除",
"category": "管理",
"data": {}
}]

View File

@ -150,6 +150,7 @@ class SiteStatistic(_PluginBase):
"cmd": "/site_statistic",
"event": EventType.SiteStatistic,
"desc": "站点数据统计",
"category": "站点",
"data": {}
}]