Skip to content

Commit

Permalink
Merge pull request #196 from AirportR/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
AirportR authored Jul 2, 2024
2 parents 9287a9f + 6231bd5 commit e83eb5f
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 102 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_meta_image.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: build_meta_image

on:
workflow_dispatch:
push:
paths:
- 'docker/Metafile'
Expand Down
2 changes: 1 addition & 1 deletion botmodule/command/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ async def select_slave_only_1(_: Client, call: Union[CallbackQuery, Message], **
if isinstance(call, CallbackQuery):
await target.edit_text(target.text, reply_markup=IKM)
else:
return await target.reply(f"请选择测试后端:\n", quote=True, reply_markup=IKM)
return await target.reply("请选择测试后端:\n", quote=True, reply_markup=IKM)


async def select_slave_only(app: Client, call: Union[CallbackQuery, Message], timeout=60, **kwargs) -> tuple[str, str]:
Expand Down
97 changes: 41 additions & 56 deletions botmodule/command/submanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pyrogram.types import Message
from pyrogram.enums import ParseMode

from utils import check, cleaner
from utils import check, cleaner, message_delete_queue as mdq
from botmodule.init_bot import config, admin
from utils.check import check_user, get_telegram_id_from_message

Expand All @@ -22,61 +22,49 @@ async def sub_invite(_, message: pyrogram.types.Message):
arg = cleaner.ArgCleaner().getall(str(message.text))
try:
if message.reply_to_message is None:
await message.reply("请先用该指令回复一个目标")
botmsg = await message.reply("请先用该指令回复一个目标")
mdq.put(botmsg)
return
r_message = message.reply_to_message
invite_id = str(get_telegram_id_from_message(r_message))
logger.info("被邀请人id: " + invite_id)
if len(arg) < 2:
m4 = await message.reply("使用方法: /share <订阅名>")
mdq.put(m4)
return
else:
r_message = message.reply_to_message
invite_id = str(get_telegram_id_from_message(r_message))
logger.info("被邀请人id: " + invite_id)
if len(arg) < 2:
m4 = await message.reply("使用方法: /share <订阅名>")
await asyncio.sleep(10)
await m4.delete()
subinfo = config.get_sub(arg[1])
owner = subinfo.get('owner', '')
if not subinfo:
m3 = await message.reply("❌未找到该订阅")
mdq.put(m3)
return
else:
subinfo = config.get_sub(arg[1])
owner = subinfo.get('owner', '')
if not subinfo:
m3 = await message.reply("❌未找到该订阅")
await asyncio.sleep(10)
await m3.delete()
return
if ID != owner:
m2 = await message.reply("❌身份ID不匹配,您无法操作该订阅!")
await asyncio.sleep(10)
await m2.delete()
return
else:
subname = arg[1]
share_ID = subinfo.get('share', [])
if invite_id in share_ID:
m3 = await message.reply(f"TA已经有 **{subname}** 测试权限啦")
await asyncio.sleep(10)
await m3.delete()
return
share_ID.append(invite_id)
subinfo['share'] = share_ID
subinfo2 = {subname: subinfo}
config.newsub(subinfo2)
config.reload()
try:
invite_name = r_message.from_user.first_name
except AttributeError:
invite_name = r_message.sender_chat.title
await message.reply(f"**{invite_name}** 现在开始拥有 **{subname}** 的测试权限")
if ID != owner:
m2 = await message.reply("❌身份ID不匹配,您无法操作该订阅!")
mdq.put(m2)
return

subname = arg[1]
share_ID = subinfo.get('share', [])
if invite_id in share_ID:
m3 = await message.reply(f"TA已经有 **{subname}** 测试权限啦")
mdq.put(m3)
return
share_ID.append(invite_id)
subinfo['share'] = share_ID
subinfo2 = {subname: subinfo}
config.newsub(subinfo2)
config.reload()
try:
invite_name = r_message.from_user.first_name
except AttributeError:
invite_name = r_message.sender_chat.title
await message.reply(f"**{invite_name}** 现在开始拥有 **{subname}** 的测试权限")

except RPCError as r:
print(r)


# async def remove_sub_invite(_, message: pyrogram.types.Message):
# ID = get_telegram_id_from_message(message)
# arg = cleaner.ArgCleaner().getall(str(message.text))
# try:
# print("等待实现")
# except RPCError as r:
# print(r)


async def sub(_, message: "Message"):
ID = get_telegram_id_from_message(message)
arg = cleaner.ArgCleaner().getall(str(message.text))
Expand All @@ -86,8 +74,7 @@ async def sub(_, message: "Message"):
subinfo = config.get_sub(arg[1])
if not subinfo:
m2 = await message.reply("❌未找到该订阅")
await asyncio.sleep(5)
await m2.delete()
mdq.put(m2)
return
subpwd = subinfo.get('password', '')
subowner = subinfo.get('owner', '')
Expand All @@ -97,11 +84,10 @@ async def sub(_, message: "Message"):
return
if subowner and subowner == ID:
if hashlib.sha256(pwd.encode("utf-8")).hexdigest() == subpwd:
await message.reply(str(subinfo.get('url', '')), )
await message.reply(str(subinfo.get('url', '')), parse_mode=ParseMode.DISABLED)
else:
m2 = await message.reply("❌密码错误,请检查后重试")
await asyncio.sleep(5)
await m2.delete()
mdq.put(m2)
else:
await message.reply("❌身份ID不匹配,您无权查看该订阅。")
else:
Expand Down Expand Up @@ -140,8 +126,7 @@ async def new(_, message):
owner = subinfo.get('owner', '')
if subinfo and ID != owner:
m2 = await message.reply("⚠️该订阅名称已被占用")
await asyncio.sleep(5)
await m2.delete()
mdq.put(m2)
return
try:
suburl = arg[1]
Expand Down
67 changes: 36 additions & 31 deletions botmodule/subinfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import hashlib
import time
from loguru import logger
Expand All @@ -17,45 +16,49 @@ async def getSubInfo(_, message):
arg = ArgCleaner.getarg(str(message.text))
call_time = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())
try:
if len(arg) == 1:
b1 = await message.reply("使用方法: /traffic & /subinfo & /流量查询 + <订阅链接> & <订阅名>")
mdq.put(b1)
return
back_message = await message.reply("正在查询流量信息...") # 发送提示
text = str(message.text)
url = geturl(text)
arglen = len(arg)
status = False
subname = arg[1]
url = geturl(str(message.text))
no_url = False
subname = arg[1] if len(arg) > 1 else ""
if not url:
if arglen == 1:
await back_message.edit_text("使用方法: /traffic & /subinfo & /流量查询 + <订阅链接> & <订阅名>")
mdq.put(back_message)
# 尝试从配置文件中获取订阅
pwd = arg[2] if len(arg) > 2 else arg[1]
subinfo = config.get_sub(arg[1])
if not subinfo:
await back_message.edit_text("❌未找到该订阅")
mdq.put(back_message, 5)
return
subpwd = subinfo.get('password', '')
subowner = subinfo.get('owner', '')
share_list = subinfo.get("share", [])
url = str(subinfo.get('url', ''))
if not isinstance(share_list, list):
share_list = []
if await check_user(message, admin, isalert=False):
# 管理员至高权限
no_url = True
else:
pwd = arg[2] if len(arg) > 2 else arg[1]
subinfo = config.get_sub(arg[1])
if not subinfo:
await back_message.edit_text("❌未找到该订阅")
return
subpwd = subinfo.get('password', '')
subowner = subinfo.get('owner', '')
if await check_user(message, admin, isalert=False):
# 管理员至高权限
url = str(subinfo.get('url', ''))
status = True
else:
if subowner and subowner == ID:
if hashlib.sha256(pwd.encode("utf-8")).hexdigest() == subpwd:
url = str(subinfo.get('url', ''))
status = True
else:
await back_message.edit_text("❌密码错误,请检查后重试")
return
if subowner and subowner == ID:
if hashlib.sha256(pwd.encode("utf-8")).hexdigest() == subpwd:
no_url = True
else:
await back_message.edit_text("❌身份ID不匹配,您无权查看该订阅流量信息。")
await back_message.edit_text("❌密码错误,请检查后重试。")
return
elif str(ID) in share_list:
no_url = True
else:
await back_message.edit_text("❌身份ID不匹配,您无权查看该订阅流量信息。")
return
subcl = SubCollector(url)
subcl.cvt_enable = False
subinfo = await subcl.getSubTraffic()
site_name = await subcl.getSiteTitle()
if not subinfo:
await back_message.edit_text("此订阅无法获取流量信息")
await back_message.edit_text("此订阅无法获取流量信息.")
return
days_diff = subinfo[5] if len(subinfo) > 5 else ""
if days_diff:
Expand All @@ -70,10 +73,12 @@ async def getSubInfo(_, message):
⏱️过期时间:{subinfo[4]} {days_diff}
🔍查询时间:{call_time}
"""
if status:
if no_url:
subinfo_text = f"☁️订阅名称:{subname}" + subinfo_text
else:
subinfo_text = f"☁️订阅链接:{url}" + subinfo_text
site_name = f"✈️机场名:{site_name}\n" if site_name else "✈️机场名:未知\n"
subinfo_text = site_name + subinfo_text
await back_message.edit_text(subinfo_text, parse_mode=ParseMode.DISABLED)
except RPCError as r:
logger.error(str(r))
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM airportr/fulltclash:debian AS compile-image

FROM python:3.11.7-slim-bookworm
FROM python:3.11.9-slim-bookworm

ARG GIT_Branch
ENV GIT_Branch=$GIT_Branch
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM airportr/fulltclash:alpine AS compile-image

FROM python:3.11.7-alpine3.19
FROM python:3.11.9-alpine3.20

ARG GIT_Branch
ENV GIT_Branch=$GIT_Branch
Expand Down
4 changes: 2 additions & 2 deletions docker/Metafile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11.7-slim-bookworm AS compile-image
FROM python:3.11.9-slim-bookworm AS compile-image

RUN apt-get update && \
apt-get install --no-install-recommends -y \
Expand All @@ -11,7 +11,7 @@ ADD https://raw.githubusercontent.com/AirportR/FullTclash/dev/requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt && \
pip3 install --no-cache-dir supervisor

FROM python:3.11.7-slim-bookworm
FROM python:3.11.9-slim-bookworm

COPY --from=compile-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=compile-image /opt/venv /opt/venv
Expand Down
4 changes: 2 additions & 2 deletions docker/Metafile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11.7-alpine3.19 AS compile-image
FROM python:3.11.9-alpine3.20 AS compile-image

RUN apk add --no-cache \
gcc g++ make libffi-dev libstdc++ gcompat libgcc build-base py3-pybind11-dev abseil-cpp-dev re2-dev ca-certificates
Expand All @@ -10,7 +10,7 @@ ADD https://raw.githubusercontent.com/AirportR/FullTclash/dev/requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt && \
pip3 install --no-cache-dir supervisor

FROM python:3.11.7-alpine3.19
FROM python:3.11.9-alpine3.20

COPY --from=compile-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=compile-image /opt/venv /opt/venv
Expand Down
2 changes: 1 addition & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from utils.cron import *
from typing import Callable, Any, Union, Coroutine, Optional

__version__ = "3.6.12" # 项目版本号
__version__ = "3.6.13" # 项目版本号
HOME_DIR = getcwd()
DEFAULT_UA = f"fulltclash/{__version__}" # 默认请求头
__all__ = [
Expand Down
14 changes: 9 additions & 5 deletions utils/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,18 @@ def unsafe_load(name: str, pkg: str) -> bool:
self._script = dict(sorted(self._script.items(), key=lambda x: x[1][2]))
logger.info(f"外接测试脚本成功导入数量: {num}")

def init_callback(self) -> list:
path = os.path.join(os.getcwd(), "addons", "callback")
def init_callback(self, path: Union[str, List[str]] = None) -> list:
if path is None:
path = ["addons/callback"]
callbackfunc_list = []
num = 0

def unsafe_load(name: str, pkg: str) -> bool:
try:
mod = importlib.import_module(pathlib.Path(pkg).joinpath(name).as_posix().replace('/', '.'))
except (ModuleNotFoundError, NameError, Exception):
m = pathlib.Path(pkg).joinpath(name).as_posix().replace('/', '.')
mod = importlib.import_module(m)
except (ModuleNotFoundError, NameError, Exception) as e:
logger.error(str(e))
mod = None
if mod is None:
return False
Expand All @@ -289,6 +292,7 @@ def unsafe_load(name: str, pkg: str) -> bool:
if entry == "__init__.py":
continue
_name, _ext = os.path.splitext(entry)
_name = _name.split(".")[0]
if _ext not in self.module_suffixes:
continue
is_loaded = unsafe_load(_name, _pkg)
Expand Down Expand Up @@ -790,7 +794,7 @@ def get_ua(self):
获取自定义ua
"""
try:
return str(self.config['ua'])
return {"user-agent": str(self.config['ua'])}
except KeyError:
return ""

Expand Down
Loading

0 comments on commit e83eb5f

Please sign in to comment.