From c317d4ba6f1f35204e86a8a3f2258881721b5f6e Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 1 Jul 2023 20:07:18 +0800 Subject: [PATCH] CI: Alpha source --- .github/workflows/python.yml | 3 +- alpha/index.html | 42 ++++++ alpha/list.json | 3 + auto_send_reactions/DES.md | 1 - auto_send_reactions/main.py | 263 ----------------------------------- update_des.py | 18 +-- update_list.py | 69 ++++----- 7 files changed, 95 insertions(+), 304 deletions(-) create mode 100644 alpha/index.html create mode 100644 alpha/list.json delete mode 100644 auto_send_reactions/DES.md delete mode 100644 auto_send_reactions/main.py diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 2552aaf..326b382 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -8,6 +8,7 @@ on: - '**.md' - '.github/**' - 'list.json' + - 'alpha/list.json' - 'telegram_update.py' - 'update_list.py' - 'telegraph_update.py' @@ -49,4 +50,4 @@ jobs: # Optional. Commit message for the created commit. # Defaults to "Apply automatic changes" commit_message: "CI: Update version json" - file_pattern: 'list.json' + file_pattern: 'list.json alpha/list.json' diff --git a/alpha/index.html b/alpha/index.html new file mode 100644 index 0000000..e946f06 --- /dev/null +++ b/alpha/index.html @@ -0,0 +1,42 @@ + + + 无法访问! + + + + + + + + + + + + +
+ +
+
+

抱歉,您已被阻止

+
+ +
+
+
+ + + +
+
+
+
+
+ + diff --git a/alpha/list.json b/alpha/list.json new file mode 100644 index 0000000..615cf24 --- /dev/null +++ b/alpha/list.json @@ -0,0 +1,3 @@ +{ + "list": [] +} \ No newline at end of file diff --git a/auto_send_reactions/DES.md b/auto_send_reactions/DES.md deleted file mode 100644 index 655f84b..0000000 --- a/auto_send_reactions/DES.md +++ /dev/null @@ -1 +0,0 @@ -向别人的消息自动回复Emoji \ No newline at end of file diff --git a/auto_send_reactions/main.py b/auto_send_reactions/main.py deleted file mode 100644 index dcdb27b..0000000 --- a/auto_send_reactions/main.py +++ /dev/null @@ -1,263 +0,0 @@ -""" -自动回复Emoji插件 -Author: SuperManito -""" - -from pagermaid import bot, log -from pagermaid.single_utils import sqlite -from pagermaid.enums import Client, Message -from pagermaid.utils import lang, edit_delete, pip_install -from pagermaid.listener import listener - -pip_install("emoji") - -import emoji - - -# 获取内容中的表情符号,并用|分割 -def get_emoji(text): - if emojiArr := emoji.distinct_emoji_list(text): - delimiter = '|' - return delimiter.join(emojiArr) - else: - return False - - -@listener(is_plugin=False, - outgoing=True, - command="auto_send_reactions", - description='\n自动回复Emoji插件', - parameters="`\n自动回复Emoji插件,支持同时设置多个目标生效用户,目前仅支持回复用户在群组中发送的消息,默认在所有已加入的群组中生效\n" - "\n**设置插件状态**:" - "\n启用:`,auto_send_reactions enable`" - "\n停用:`,auto_send_reactions disable`" - "\n\n**设置目标生效用户**:" - "\n添加:`,auto_send_reactions set <用户id/用户名> <表情内容>`" - "\n移除:`,auto_send_reactions unset <用户id/用户名>`" - "\n支持直接回复消息以进行快速设置,可以省略用户标识参数" - "\n\n**设置生效群组黑名单**:" - "\n添加:`,auto_send_reactions block <群组id/群组用户名>`" - "\n移除:`,auto_send_reactions unblock <群组id/群组用户名>\n") -async def AutoSendReactions(client: Client, message: Message): - reply = message.reply_to_message - - # 启用插件 - if message.parameter[0] == "enable": - # for ID in ID_FROM_ARRAY : - # # 检查来源频道/群组 - # try: - # channel = await bot.get_chat(ID) - # except Exception as e: - # errorMsg = f"第{e.__traceback__.tb_lineno}行:{e}" - # await message.edit(f"出错了呜呜呜 ~ 无法识别的来源对话。\n\n{errorMsg}") - # return - - if not sqlite.get("AutoSendReactions.Enable"): - sqlite["AutoSendReactions.Enable"] = 'yes' - - # 返回消息 - await edit_delete(message, "✅ **已启用自动回复表情插件**") - - elif message.parameter[0] == "disable": - - if sqlite.get("AutoSendReactions.Enable"): - del sqlite["AutoSendReactions.Enable"] - - # 返回消息 - await edit_delete(message, "❌ **已停用自动回复表情插件**") - - elif message.parameter[0] in ["set", "unset"]: - - ## 设置插件 - if (message.parameter[0] == "set"): - - if not reply and (len(message.parameter) == 3): - target = message.parameter[1] - content = message.parameter[2] - try: - # 获取用户信息 - user_info = await bot.get_users(target) - # 判断参数合法性 - if not user_info: - return await message.edit("❌ **目标用户不存在或参数有误**") - if not content or not get_emoji(content): - return await message.edit("❌ **Emoji参数不能为空或不合法**") - user_name = ( - f'{user_info.first_name} {user_info.last_name}' - if user_info.last_name - else user_info.first_name - ) - # 设置或更新 - hasSetted = sqlite.get(f"AutoSendReactions.{target}") - sqlite[f"AutoSendReactions.{target}"] = content - await edit_delete( - message, - f"✅ 已{'更新' if hasSetted else '添加'}对 __{user_name}__ 的自动回复Emoji设置**" - ) - except Exception as e: - await message.edit(message, f"❌ **在设置中遇到了一些错误** > {e}") - await log(e) # 打印错误日志 - - elif reply and (len(message.parameter) == 2): - from_user = reply.from_user - target = from_user.id - content = message.parameter[1] - try: - # 判断参数合法性 - if not content or not get_emoji(content): - return await message.edit("❌ **Emoji参数不能为空或不合法**") - user_name = ( - f'{from_user.first_name} {from_user.last_name}' - if from_user.last_name - else from_user.first_name - ) - # 设置或更新 - hasSetted = sqlite.get(f"AutoSendReactions.{target}") - sqlite[f"AutoSendReactions.{target}"] = content - await edit_delete( - message, - f"✅ 已{'更新' if hasSetted else '添加'}对 __{user_name}__ 的自动回复Emoji设置" - ) - except Exception as e: - await message.edit(message, f"❌ **在设置中遇到了一些错误** > {e}") - await log(e) # 打印错误日志 - else: - return await message.edit( - f"{lang('error_prefix')}{lang('arg_error')}") - - elif (message.parameter[0] == "unset"): - - if not reply and (len(message.parameter) == 2): - target = message.parameter[1] - try: - # 获取用户信息 - user_info = await bot.get_users(target) - # 判断参数合法性 - if not user_info: - return await message.edit("❌ **目标用户不存在或参数有误**") - user_id = user_info.id - user_name = ( - f'{user_info.first_name} {user_info.last_name}' - if user_info.last_name - else user_info.first_name - ) - if hasSetted := sqlite.get(f"AutoSendReactions.{user_id}"): - del sqlite[f"AutoSendReactions.{user_id}"] - await edit_delete( - message, f"✅ 对 __{user_name}__ 的自动回复Emoji设置已删除") - else: - await edit_delete( - message, f"❌ 还没有对 __{user_name}__ 设置自动回复Emoji哦~") - except Exception as e: - await message.edit(message, f"❌ **在设置中遇到了一些错误** > {e}") - await log(e) # 打印错误日志 - - elif reply and (len(message.parameter) == 1): - from_user = reply.from_user - target = from_user.id - try: - user_name = ( - f'{from_user.first_name} {from_user.last_name}' - if from_user.last_name - else from_user.first_name - ) - if hasSetted := sqlite.get(f"AutoSendReactions.{target}"): - del sqlite[f"AutoSendReactions.{target}"] - await edit_delete( - message, f"✅ 已删除对 __{user_name}__ 的自动回复Emoji设置") - else: - await edit_delete( - message, f"❌ 还没有对 __{user_name}__ 设置自动回复Emoji哦~") - except Exception as e: - await message.edit(message, f"❌ **在设置中遇到了一些错误** > {e}") - await log(e) # 打印错误日志 - else: - return await message.edit( - f"{lang('error_prefix')}{lang('arg_error')}") - - else: - return await message.edit( - f"{lang('error_prefix')}{lang('arg_error')}") - - elif (message.parameter[0] - == "block") or (message.parameter[0] == "unblock") and (len( - message.parameter) == 2): - group = message.parameter[1] - group_info = await bot.get_chat(chat_id=group) - if not group_info: - return await message.edit("❌ **目标群组不存在或参数有误**") - group_id = group_info.id - group_name = group_info.title - - if (message.parameter[0] == "block"): - if hasBlocked := sqlite.get(f"AutoSendReactionsBlock.{group_id}"): - await edit_delete( - message, f"❌ 已经将 __{group_name}__ 加入自动回复Emoji黑名单群组了哦~") - else: - sqlite[f"AutoSendReactionsBlock.{group_id}"] = 'yes' - await edit_delete(message, - f"✅ 已将 __{group_name}__ 加入至自动回复Emoji黑名单群组") - elif (message.parameter[0] == "unblock"): - if hasBlocked := sqlite.get(f"AutoSendReactionsBlock.{group_id}"): - del sqlite[f"AutoSendReactionsBlock.{group_id}"] - await edit_delete(message, - f"✅ 已将 __{group_name}__ 从自动回复Emoji黑名单群组中移除") - else: - await edit_delete( - message, f"❌ 还没有将 __{group_name}__ 加入进自动回复Emoji群组黑名单哦~") - - else: - return await message.edit(f"{lang('error_prefix')}{lang('arg_error')}" - ) - - -@listener(is_plugin=False, incoming=True, ignore_edited=True) -async def AutoSendReactions(message: Message): - from_user = '' - try: - # 判断是否启用了本插件 - if not sqlite.get("AutoSendReactions.Enable"): - return - if 'GROUP' not in str(message.chat.type): - return - # 判断是否在黑名单中 - if sqlite.get(f"AutoSendReactionsBlock.{message.chat.id}"): - return - if not message.from_user: - # 过滤匿名管理员 - return - - from_user = message.from_user - if not sqlite.get(f"AutoSendReactions.{from_user.id}"): - return - # 判断群组是否启用了表情回应功能 - group_info = await bot.get_chat(chat_id=message.chat.id) - if not group_info.available_reactions: - return - - # 发送表情 - emoji = sqlite.get(f"AutoSendReactions.{from_user.id}").split('|')[0] - user_name = ( - f'{from_user.first_name} {from_user.last_name}' - if from_user.last_name - else from_user.first_name - ) - try: - await bot.send_reaction(message.chat.id, message.id, emoji) - - except Exception as e: - errorMsg = f"❌ 自动回复Emoji失败({user_name} {emoji})> {e}" - await log(errorMsg) - return False - - # 打印日志 - # text = message.text.markdown - # await log(f"AutoSendReactions 监控到来自 {user_name} 的消息:{str(text)}") - - except Exception as e: - errorMsg = f"❌ 第{e.__traceback__.tb_lineno}行:{e}" - await log(errorMsg) - return False - - -## ⬆️ 不懂勿动 ⬆️ diff --git a/update_des.py b/update_des.py index 5a6115f..f24ec94 100644 --- a/update_des.py +++ b/update_des.py @@ -3,14 +3,16 @@ import os def update_des(): - with open("list.json", "r", encoding="utf8") as f: - list_json = json.load(f) - for plugin in list_json["list"]: - if os.path.exists(f"{plugin['name']}{os.sep}DES.md"): - with open(f"{plugin['name']}{os.sep}DES.md", "r", encoding="utf8") as f: - plugin["des"] = f.read().strip() - with open("list.json", "w", encoding="utf8") as f: - json.dump(list_json, f, ensure_ascii=False, indent=4) + list_json_start = ["", "alpha/"] + for start in list_json_start: + with open(f"{start}list.json", "r", encoding="utf8") as f: + list_json = json.load(f) + for plugin in list_json["list"]: + if os.path.exists(f"{start}{plugin['name']}{os.sep}DES.md"): + with open(f"{start}{plugin['name']}{os.sep}DES.md", "r", encoding="utf8") as f: + plugin["des"] = f.read().strip() + with open(f"{start}list.json", "w", encoding="utf8") as f: + json.dump(list_json, f, ensure_ascii=False, indent=4) if __name__ == "__main__": diff --git a/update_list.py b/update_list.py index 4c5578c..f3a468a 100644 --- a/update_list.py +++ b/update_list.py @@ -7,43 +7,50 @@ from update_des import update_des main = get("https://api.github.com/repos/TeamPGM/PagerMaid_Plugins_Pyro/commits/v2").json() plugins = [] +alpha_plugins = [] +list_json_start = ["", "alpha/"] for file in main["files"]: - if file["filename"] == "list.json": + if "list.json" in file["filename"]: print(main['sha'] + " no need!") exit() if "/main.py" in file["filename"]: - plugins.append(file["filename"].split("/")[0]) + if file["filename"].startswith("alpha"): + alpha_plugins.append(file["filename"].split("/")[1]) + else: + plugins.append(file["filename"].split("/")[0]) delete = bool(main['commit']['message'].startswith("Delete")) -with open("list.json", "r", encoding="utf8") as f: - list_json = json.load(f) -for plugin in plugins: - exist = False - for plug_dict in list_json["list"]: - if plug_dict["name"] == plugin: - exist = True - old_version = decimal.Decimal(plug_dict["version"]) - plug_dict["version"] = old_version + decimal.Decimal("0.01") - plug_dict["size"] = f"{os.path.getsize(f'{plugin}{os.sep}main.py') / 1000} kb" - if delete: - list_json["list"].remove(plug_dict) - break - if not exist: - short_des = main['commit']['message'].split("\nCo-authored-by")[0].strip() - list_json["list"].append( - { - "name": plugin, - "version": "1.0", - "section": "chat", - "maintainer": main['commit']['author']['name'], - "size": f"{os.path.getsize(f'{plugin}{os.sep}main.py') / 1000} kb", - "supported": True, - "des_short": short_des, - "des": "", - } - ) -with open("list.json", "w", encoding="utf8") as f: - json.dump(list_json, f, ensure_ascii=False, indent=4) + +for idx, plugins_ in enumerate([plugins, alpha_plugins]): + with open(f"{list_json_start[idx]}list.json", "r", encoding="utf8") as f: + list_json = json.load(f) + for plugin in plugins_: + exist = False + for plug_dict in list_json["list"]: + if plug_dict["name"] == plugin: + exist = True + old_version = decimal.Decimal(plug_dict["version"]) + plug_dict["version"] = old_version + decimal.Decimal("0.01") + plug_dict["size"] = f"{os.path.getsize(f'{list_json_start[idx]}{plugin}{os.sep}main.py') / 1000} kb" + if delete: + list_json["list"].remove(plug_dict) + break + if not exist: + short_des = main['commit']['message'].split("\nCo-authored-by")[0].strip() + list_json["list"].append( + { + "name": plugin, + "version": "1.0", + "section": "chat", + "maintainer": main['commit']['author']['name'], + "size": f"{os.path.getsize(f'{list_json_start[idx]}{plugin}{os.sep}main.py') / 1000} kb", + "supported": True, + "des_short": short_des, + "des": "", + } + ) + with open(f"{list_json_start[idx]}list.json", "w", encoding="utf8") as f: + json.dump(list_json, f, ensure_ascii=False, indent=4) update_des()