from asyncio import create_task, sleep
from datetime import datetime
from math import sqrt
from random import randint
from re import S, compile, split, sub
from nonebot import get_driver, on_message, on_notice, on_regex, on_request
from nonebot.adapters import Bot
from nonebot.adapters.onebot.v11.event import (
FriendAddNoticeEvent,
FriendRequestEvent,
GroupDecreaseNoticeEvent,
GroupIncreaseNoticeEvent,
GroupMessageEvent,
GroupRecallNoticeEvent,
GroupRequestEvent,
MessageEvent,
NoticeEvent,
PrivateMessageEvent,
)
from nonebot.adapters.onebot.v11.message import MessageSegment
from nonebot.log import logger
from nonebot.permission import SUPERUSER
from src.modules._gold import Gold
from src.modules._sponsor import Sponsor
from src.modules._tips import Tips
from src.modules._wg import Wg
from src.modules._zhb_list import Zhb_list
from src.modules._zhb_user import Zhb_user
from tortoise import Tortoise
from ujson import loads
from .channel_patch import GuildMessageEvent
from .config import (
bd_api,
black_api,
jb_api,
join_limit_api,
krsr_api,
privacy_api,
room_name_api,
version_set_api,
xl_api,
zz_api,
)
from .global_var import gv
from .scheduler import start_scheduler
from .sniff import start_sniff
from .utils import (
check_group_zhb,
check_in_group,
exec_shell,
get_group_name,
get_net_io,
get_qqnum_nickname,
get_room_list,
handle_exception,
network_status,
server_status,
wgnum_to_ip,
)
from .web import start_web_server
from .wgnum import check_num, refresh_friendlist, refresh_get_wgnum_count, release_wgnum
#################################
# 框架操作
#################################
driver = get_driver()
# 启动时执行
@driver.on_startup
async def do_startup():
gv.start_time = datetime.now()
try:
config = driver.config
gv.secret_key = config.onebot_access_token
gv.site_url = config.site_url
gv.cdn_host = config.cdn_host
gv.video_url = config.video_url
gv.bot_1_num = str(config.bot_1_num)
gv.bot_2_num = str(config.bot_2_num)
gv.superuser_num = config.superuser_num
gv.tshark_path = config.tshark_path
gv.miao_group_num = config.miao_group_num
gv.miao_group2_num = config.miao_group2_num
gv.shencha_group_num = config.shencha_group_num
gv.guild_id = config.guild_id
gv.channel_id = config.channel_id
gv.miaobi_system = config.miaobi_system
gv.safe_mode = config.safe_mode
special_wgnum = eval(config.special_wgnum)
if special_wgnum:
for k, v in special_wgnum.items():
gv.r2f[k] = v
gv.f2r[v] = k
except Exception:
logger.error("加载配置失败")
# 连接sqlite3数据库
models = [
"src.modules._gold",
"src.modules._sponsor",
"src.modules._tips",
"src.modules._visit",
"src.modules._wg",
"src.modules._xl",
"src.modules._zhb_list",
"src.modules._zhb_user",
"src.modules._guide",
]
await Tortoise.init(
db_url=f"sqlite://data/data.db",
modules={"models": models},
)
await Tortoise.generate_schemas()
logger.success("数据库连接成功")
# 读取缓存数据
gv.read_tmp_data()
# 获取数据库编号总数
await refresh_get_wgnum_count()
try:
gv.send_socket.bind(("miao", 0))
except Exception:
logger.error("未发现WG网卡,尝试启动...")
code, stdout, stderr = await exec_shell("bash src/shell/wg_up.sh")
if code:
exit("WG网卡绑定失败,无法启动服务器")
else:
gv.send_socket.bind(("miao", 0))
# 首次启动网卡时加载编号配置进入wg
insert_count = 0
for wgnum in range(1, gv.get_wgnum_count + 1):
code, stdout, stderr = await exec_shell(
f"bash src/shell/wg_insert.sh {wgnum_to_ip(wgnum)}"
)
if not code:
insert_count += 1
await exec_shell(f"bash src/shell/wg_insert.sh save")
if gv.get_wgnum_count == insert_count:
logger.success(f"成功从配置文件导入并加载编号{insert_count}个")
else:
exit(f"数据库编号数量与配置文件数量不一致!")
# 启动定时模块
create_task(start_scheduler())
# 启动WEB模块
create_task(start_web_server())
# 启动流量嗅探模块
create_task(start_sniff())
# 安全模式
if gv.safe_mode is False:
if not 8 <= datetime.now().hour <= 23:
gv.safe_mode = True
logger.success(
"启动完毕!等待go-cqhttp连接...\n\
.----------------. .----------------. .----------------. .----------------. \n\
| .--------------. || .--------------. || .--------------. || .--------------. |\n\
| | ____ ____ | || | _____ | || | __ | || | ____ | |\n\
| ||_ \ / _|| || | |_ _| | || | / \ | || | .' '. | |\n\
| | | \/ | | || | | | | || | / /\ \ | || | / .--. \ | |\n\
| | | |\ /| | | || | | | | || | / ____ \ | || | | | | | | |\n\
| | _| |_\/_| |_ | || | _| |_ | || | _/ / \ \_ | || | \ '--' / | |\n\
| ||_____||_____|| || | |_____| | || ||____| |____|| || | '.____.' | |\n\
| | | || | | || | | || | | |\n\
| '--------------' || '--------------' || '--------------' || '--------------' |\n\
'----------------' '----------------' '----------------' '----------------' "
)
# 关闭时执行
@driver.on_shutdown
async def do_shutdown():
logger.success("关闭中...")
await sleep(0.3)
gv.save_tmp_data()
await gv.aioget.aclose()
await Tortoise.close_connections()
logger.success(
"\n\
.----------------. .----------------. .----------------. \n\
| .--------------. || .--------------. || .--------------. |\n\
| | ______ | || | ____ ____ | || | _________ | |\n\
| | |_ _ \ | || | |_ _||_ _| | || | |_ ___ | | |\n\
| | | |_) | | || | \ \ / / | || | | |_ \_| | |\n\
| | | __'. | || | \ \/ / | || | | _| _ | |\n\
| | _| |__) | | || | _| |_ | || | _| |___/ | | |\n\
| | |_______/ | || | |______| | || | |_________| | |\n\
| | | || | | || | | |\n\
| '--------------' || '--------------' || '--------------' |\n\
'----------------' '----------------' '----------------' "
)
def bot_switch():
if gv.bot_1 is not None:
gv.admin_bot = gv.bot_1
elif gv.bot_2 is not None:
gv.admin_bot = gv.bot_2
else:
gv.admin_bot = None
if gv.bot_2 is not None:
gv.handle_bot = gv.bot_2
elif gv.bot_1 is not None:
gv.handle_bot = gv.bot_1
else:
gv.handle_bot = None
# qq机器人连接时执行
@driver.on_bot_connect
async def on_bot_connect_handle(bot: Bot):
if bot.self_id == gv.bot_1_num:
gv.bot_1 = bot
await refresh_friendlist()
elif bot.self_id == gv.bot_2_num:
gv.bot_2 = bot
elif bot.self_id == str(gv.superuser_num):
gv.superuser_bot = bot
bot_switch()
await sleep(3)
gv.private_mess.append((gv.superuser_num, f"{bot.self_id}上线"))
logger.success(f"{bot.self_id}上线")
# qq机器人断开时执行
@driver.on_bot_disconnect
async def on_bot_disconnect_handle(bot: Bot):
if bot.self_id == gv.bot_1_num:
gv.bot_1 = None
await refresh_
没有合适的资源?快使用搜索试试~ 我知道了~
源代码.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共80个文件
jpg:20个
py:19个
html:13个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 0 0 下载量 149 浏览量
2023-05-19
15:54:21
上传
评论
收藏 25.3MB ZIP 举报
温馨提示
源代码.zip
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/GIF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 80 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
2201_75426220
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)