diff options
Diffstat (limited to 'ATRI/plugins')
-rw-r--r-- | ATRI/plugins/anime_search.py | 20 | ||||
-rw-r--r-- | ATRI/plugins/manege/data_source.py | 57 | ||||
-rw-r--r-- | ATRI/plugins/saucenao/data_source.py | 25 |
3 files changed, 51 insertions, 51 deletions
diff --git a/ATRI/plugins/anime_search.py b/ATRI/plugins/anime_search.py index 535dec2..b9a068b 100644 --- a/ATRI/plugins/anime_search.py +++ b/ATRI/plugins/anime_search.py @@ -23,10 +23,9 @@ __doc__ = """ class Anime(Service): - def __init__(self): Service.__init__(self, "以图搜番", __doc__, rule=is_in_service("以图搜番")) - + @staticmethod async def _request(url: str) -> dict: aim = URL + url @@ -36,12 +35,12 @@ class Anime(Service): raise RequestError("Request failed!") result = await res.json() return result - + @classmethod async def search(cls, url: str) -> str: data = await cls._request(url) data = data["result"] - + d = dict() for i in range(len(data)): if data[i]["anilist"]["title"]["native"] in d.keys(): @@ -49,7 +48,7 @@ class Anime(Service): else: from_m = data[i]["from"] / 60 from_s = data[i]["from"] % 60 - + to_m = data[i]["to"] / 60 to_s = data[i]["to"] % 60 @@ -63,7 +62,7 @@ class Anime(Service): f"第{n}集", f"约{int(from_m)}min{int(from_s)}s至{int(to_m)}min{int(to_s)}s处", ] - + result = sorted(d.items(), key=lambda x: x[1], reverse=True) t = 0 msg0 = str() @@ -76,7 +75,7 @@ class Anime(Service): f"Name: {i[0]}\n" f"Time: {i[1][1]} {i[1][2]}" ) - + if len(result) == 2: return msg0 else: @@ -86,6 +85,7 @@ class Anime(Service): anime_search = Anime().on_command("以图搜番", "发送一张图以搜索可能的番剧") + @anime_search.args_parser # type: ignore async def _get_anime(bot: Bot, event: MessageEvent, state: T_State): msg = str(event.message).strip() @@ -97,16 +97,18 @@ async def _get_anime(bot: Bot, event: MessageEvent, state: T_State): else: state["anime"] = msg + @anime_search.handle() async def _ready_sear(bot: Bot, event: MessageEvent, state: T_State): user_id = event.get_user_id() if not _anime_flmt.check(user_id): await anime_search.finish(_anime_flmt_notice) - + msg = str(event.message).strip() if msg: state["anime"] = msg + @anime_search.got("anime", "图呢?") async def _deal_sear(bot: Bot, event: MessageEvent, state: T_State): user_id = event.get_user_id() @@ -114,7 +116,7 @@ async def _deal_sear(bot: Bot, event: MessageEvent, state: T_State): img = re.findall(r"url=(.*?)]", msg) if not img: await anime_search.reject("请发送图片而不是其它东西!!") - + await bot.send(event, "别急,在找了") a = await Anime().search(img[0]) result = f"> {MessageSegment.at(user_id)}\n" + a diff --git a/ATRI/plugins/manege/data_source.py b/ATRI/plugins/manege/data_source.py index 6ce9c60..8e61492 100644 --- a/ATRI/plugins/manege/data_source.py +++ b/ATRI/plugins/manege/data_source.py @@ -28,7 +28,6 @@ __doc__ = """ class Manege(Service): - def __init__(self): Service.__init__(self, "管理", __doc__, True) @@ -53,8 +52,7 @@ class Manege(Service): except BaseException: data = dict() return data - - + @staticmethod def _save_block_user_list(data: dict) -> None: file_name = "block_user.json" @@ -62,10 +60,10 @@ class Manege(Service): if not path.is_file(): with open(path, "w", encoding="utf-8") as w: w.write(json.dumps({})) - + with open(path, "w", encoding="utf-8") as w: w.write(json.dumps(data, indent=4)) - + @staticmethod def _load_block_group_list() -> dict: """ @@ -82,13 +80,13 @@ class Manege(Service): with open(path, "w", encoding="utf-8") as w: w.write(json.dumps({})) return dict() - + try: data = json.loads(path.read_bytes()) except BaseException: data = dict() return data - + @staticmethod def _save_block_group_list(data: dict) -> None: file_name = "block_group.json" @@ -96,55 +94,51 @@ class Manege(Service): if not path.is_file(): with open(path, "w", encoding="utf-8") as w: w.write(json.dumps({})) - + with open(path, "w", encoding="utf-8") as w: w.write(json.dumps(data, indent=4)) - + @classmethod def block_user(cls, user_id: str) -> bool: data = cls._load_block_user_list() now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - data[user_id] = { - "time": now_time - } + data[user_id] = {"time": now_time} try: cls._save_block_user_list(data) return True except BaseException: return False - + @classmethod def unblock_user(cls, user_id: str) -> bool: data: dict = cls._load_block_user_list() if user_id not in data: return False - + try: data.pop(user_id) cls._save_block_user_list(data) return True except BaseException: return False - + @classmethod def block_group(cls, group_id: str) -> bool: data = cls._load_block_group_list() now_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - data[group_id] = { - "time": now_time - } + data[group_id] = {"time": now_time} try: cls._save_block_group_list(data) return True except BaseException: return False - + @classmethod def unblock_group(cls, group_id: str) -> bool: data: dict = cls._load_block_group_list() if group_id not in data: return False - + try: data.pop(group_id) cls._save_block_group_list(data) @@ -164,7 +158,7 @@ class Manege(Service): data["enabled"] = is_enabled ServiceTools().save_service(data, service) return True - + @staticmethod def control_user_service(service: str, user_id: str, is_enabled: bool) -> bool: """ @@ -175,7 +169,7 @@ class Manege(Service): except BaseException: return False temp_list: list = data.get("disable_user", list()) - + if is_enabled: try: temp_list.remove(user_id) @@ -186,7 +180,7 @@ class Manege(Service): data["disable_user"] = temp_list ServiceTools().save_service(data, service) return True - + @staticmethod def control_group_service(service: str, group_id: str, is_enabled: bool) -> bool: """ @@ -198,7 +192,7 @@ class Manege(Service): except BaseException: return False temp_list: list = data.get("disable_group", list()) - + if is_enabled: try: temp_list.remove(group_id) @@ -224,7 +218,7 @@ class Manege(Service): except BaseException: data = dict() return data - + @staticmethod def save_friend_apply_list(data: dict) -> None: file_name = "friend_add.json" @@ -235,7 +229,7 @@ class Manege(Service): with open(path, "w", encoding="utf-8") as w: w.write(json.dumps(data, indent=4)) - + @staticmethod def load_invite_apply_list() -> dict: file_name = "group_invite.json" @@ -250,7 +244,7 @@ class Manege(Service): except BaseException: data = dict() return data - + @staticmethod def save_invite_apply_list(data: dict) -> None: file_name = "group_invite.json" @@ -268,16 +262,13 @@ class Manege(Service): data = load_error(track_id) except ReadFileError: return "请检查ID是否正确..." - + prompt = data.get("prompt", "ignore") time = data.get("time", "ignore") content = data.get("content", "ignore") - + msg0 = TRACK_BACK_FORMAT.format( - track_id=track_id, - prompt=prompt, - time=time, - content=content + track_id=track_id, prompt=prompt, time=time, content=content ) repo = f"详细请移步此处~\n{await UbuntuPaste(content=msg0).paste()}" return repo diff --git a/ATRI/plugins/saucenao/data_source.py b/ATRI/plugins/saucenao/data_source.py index 58b031b..3f77118 100644 --- a/ATRI/plugins/saucenao/data_source.py +++ b/ATRI/plugins/saucenao/data_source.py @@ -15,8 +15,15 @@ __doc__ = """ class SaouceNao(Service): - - def __init__(self, api_key: str = None, output_type=2, testmode=1, dbmaski=32768, db=5, numres=5): + def __init__( + self, + api_key: str = None, + output_type=2, + testmode=1, + dbmaski=32768, + db=5, + numres=5, + ): Service.__init__(self, "以图搜图", __doc__, rule=is_in_service("以图搜图")) params = dict() @@ -27,31 +34,31 @@ class SaouceNao(Service): params["db"] = db params["numres"] = numres self.params = params - + async def _request(self, url: str): self.params["url"] = url - + try: res = await request.post(URL, params=self.params) except RequestError: raise RequestError("Request failed!") data = await res.json() return data - + async def search(self, url: str) -> str: data = await self._request(url) res = data["results"] - + result = list() for i in range(len(res)): data = res[i] - + _result = dict() _result["similarity"] = data["header"]["similarity"] _result["index_name"] = data["header"]["index_name"] _result["url"] = choice(data["data"].get("ext_urls", ["None"])) result.append(_result) - + msg0 = str() for i in result: msg0 += ( @@ -60,7 +67,7 @@ class SaouceNao(Service): f"Name: {i['index_name']}\n" f"URL: {i['url'].replace('https://', '')}" ) - + if len(res) <= 3: return msg0 else: |