From 78412d33932a9b5dc2e4d4ddc778dd998e6dc8f3 Mon Sep 17 00:00:00 2001 From: Refound-445 <2877834692@qq.com> Date: Sat, 25 Jan 2025 18:24:20 +0800 Subject: [PATCH] up --- ipynb/run_with_napcat.ipynb | 188 +++++++++++++++++++++++++++++++ ipynb/run_with_napcat_en.ipynb | 196 +++++++++++++++++++++++++++++++++ 2 files changed, 384 insertions(+) create mode 100644 ipynb/run_with_napcat.ipynb create mode 100644 ipynb/run_with_napcat_en.ipynb diff --git a/ipynb/run_with_napcat.ipynb b/ipynb/run_with_napcat.ipynb new file mode 100644 index 0000000..9dc24b1 --- /dev/null +++ b/ipynb/run_with_napcat.ipynb @@ -0,0 +1,188 @@ +{ + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.10.12", + "mimetype": "text/x-python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "pygments_lexer": "ipython3", + "nbconvert_exporter": "python", + "file_extension": ".py" + }, + "kaggle": { + "accelerator": "gpu", + "dataSources": [], + "isInternetEnabled": true, + "language": "python", + "sourceType": "notebook", + "isGpuEnabled": true + } + }, + "nbformat_minor": 5, + "nbformat": 4, + "cells": [ + { + "id": "626294c0-7107-49e2-8b76-02d8220a4e63", + "cell_type": "markdown", + "source": "# 1.安装Napcat", + "metadata": {} + }, + { + "id": "6c845c9b-df3f-4e3a-b764-24d19a811edc", + "cell_type": "code", + "source": "!curl -o napcat.sh https://nclatest.znin.net/NapNeko/NapCat-Installer/main/script/install.sh && echo -e \"y\\nn\\n\" | sudo bash napcat.sh", + "metadata": { + "trusted": true, + "execution": { + "iopub.status.busy": "2025-01-25T09:46:33.306378Z", + "iopub.execute_input": "2025-01-25T09:46:33.306682Z", + "iopub.status.idle": "2025-01-25T09:46:34.485925Z", + "shell.execute_reply.started": "2025-01-25T09:46:33.306655Z", + "shell.execute_reply": "2025-01-25T09:46:34.485178Z" + }, + "_kg_hide-input": false + }, + "outputs": [ + { + "name": "stdout", + "text": " % Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0^C\n", + "output_type": "stream" + } + ], + "execution_count": 1 + }, + { + "id": "c85256bb-873b-449c-8bc6-32cc46f25c63", + "cell_type": "markdown", + "source": "# 2.安装需要的库", + "metadata": {} + }, + { + "id": "807ad9ba-f9f0-45a4-985b-bdce343751de", + "cell_type": "code", + "source": "!pip install -q nb-cli nb-cli-plugin-bootstrap nonebot2[fastapi] nonebot-adapter-onebot nonebot-plugin-logpile", + "metadata": { + "trusted": true, + "execution": { + "iopub.status.busy": "2025-01-25T09:46:34.487283Z", + "iopub.execute_input": "2025-01-25T09:46:34.487608Z" + }, + "_kg_hide-input": false + }, + "outputs": [ + { + "name": "stdout", + "text": " Preparing metadata (setup.py) ... \u001B[?25l\u001B[?25hdone\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m64.4/64.4 kB\u001B[0m \u001B[31m4.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m49.6/49.6 kB\u001B[0m \u001B[31m3.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m96.0/96.0 kB\u001B[0m \u001B[31m6.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m78.9/78.9 kB\u001B[0m \u001B[31m5.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m94.8/94.8 kB\u001B[0m \u001B[31m7.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m61.6/61.6 kB\u001B[0m \u001B[31m4.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m114.7/114.7 kB\u001B[0m \u001B[31m8.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m1.1/1.1 MB\u001B[0m \u001B[31m40.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m62.3/62.3 kB\u001B[0m \u001B[31m4.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m4.3/4.3 MB\u001B[0m \u001B[31m93.9 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m:00:01\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m425.7/425.7 kB\u001B[0m \u001B[31m25.7 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m469.0/469.0 kB\u001B[0m \u001B[31m28.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m442.1/442.1 kB\u001B[0m \u001B[31m30.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m71.5/71.5 kB\u001B[0m \u001B[31m5.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m3.8/3.8 MB\u001B[0m \u001B[31m75.6 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m:00:01\u001B[0m\n\u001B[?25h", + "output_type": "stream" + } + ], + "execution_count": null + }, + { + "id": "4b070e72-9521-4f50-a040-6a72614b891b", + "cell_type": "markdown", + "source": "# 3.初始化Bot并安装插件", + "metadata": {} + }, + { + "id": "bb418a49-e179-4852-a80f-f54d8e6c4dde", + "cell_type": "code", + "source": "!nb bs -y --no-venv -a nonebot.adapters.onebot.v11 nailong\n%cd nailong\n!nb plugin install nonebot-plugin-nailongremove", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + }, + { + "id": "b6f16f96-fee2-4934-a3e1-ff0cb3d42426", + "cell_type": "markdown", + "source": "# 4.插件基本配置\n## 可以在此处修改一些基本配置项(**全局唯一可以修改的代码部分**)", + "metadata": {} + }, + { + "id": "1e2b820b-2268-43b3-876d-ecce2cb97bf7", + "cell_type": "code", + "source": "# .env.prod文件设置\ntext='''DRIVER=~fastapi+~httpx+~websockets\nONEBOT_ACCESS_TOKEN='temp123456'\nENVIRONMENT=.dev'''", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + }, + { + "id": "01584ab9-06ad-4438-8718-51e62447618a", + "cell_type": "markdown", + "source": "## 此处为Napcat代理相关配置", + "metadata": {} + }, + { + "id": "438d22d3-a229-4742-aa30-7082303bb914", + "cell_type": "code", + "source": [ + "# Napcat代理设置\n", + "json = '''{\n", + " \"network\": {\n", + " \"httpServers\": [],\n", + " \"httpClients\": [],\n", + " \"websocketServers\": [],\n", + " \"websocketClients\": [\n", + " {\n", + " \"name\": \"nonebot\",\n", + " \"enable\": true,\n", + " \"url\": \"ws://127.0.0.1:8080/onebot/v11/ws\",\n", + " \"messagePostFormat\": \"array\",\n", + " \"reportSelfMessage\": true,\n", + " \"reconnectInterval\": 5000,\n", + " \"token\": \"temp123456\",\n", + " \"debug\": false,\n", + " \"heartInterval\": 30000\n", + " }\n", + " ]\n", + " },\n", + " \"musicSignUrl\": \"\",\n", + " \"enableLocalFile2Url\": false,\n", + " \"parseMultMsg\": true\n", + "}'''\n", + "# 读取并修改 .env 文件\n", + "env_file_path = '.env.prod' # 设置你的 .env 文件路径\n", + "# 打开文件并添加内容\n", + "with open(env_file_path, 'w') as file:\n", + " file.write(text)\n", + "# 配置Napcat\n", + "file_path = '/opt/QQ/resources/app/app_launcher/napcat/config/onebot11_3990547445.json'\n", + "with open(file_path, 'w') as file:\n", + " file.write(json)" + ], + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + }, + { + "id": "63f3abc0-ccba-4b41-9955-8028e71f5503", + "cell_type": "markdown", + "source": "# 5.启动Bot,并扫码登录QQ", + "metadata": {} + }, + { + "id": "3c8aed7b-6eb5-4a4e-811e-2c502c9cfc87", + "cell_type": "code", + "source": "!xvfb-run -a qq --no-sandbox & nb run", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + } + ] +} diff --git a/ipynb/run_with_napcat_en.ipynb b/ipynb/run_with_napcat_en.ipynb new file mode 100644 index 0000000..4126790 --- /dev/null +++ b/ipynb/run_with_napcat_en.ipynb @@ -0,0 +1,196 @@ +{ + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.10.12", + "mimetype": "text/x-python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "pygments_lexer": "ipython3", + "nbconvert_exporter": "python", + "file_extension": ".py" + }, + "kaggle": { + "accelerator": "gpu", + "dataSources": [], + "isInternetEnabled": true, + "language": "python", + "sourceType": "notebook", + "isGpuEnabled": true + } + }, + "nbformat_minor": 5, + "nbformat": 4, + "cells": [ + { + "id": "626294c0-7107-49e2-8b76-02d8220a4e63", + "cell_type": "markdown", + "source": "# 1.Install Napcat", + "metadata": {} + }, + { + "id": "6c845c9b-df3f-4e3a-b764-24d19a811edc", + "cell_type": "code", + "source": "!curl -o napcat.sh https://nclatest.znin.net/NapNeko/NapCat-Installer/main/script/install.sh && echo -e \"y\\nn\\n\" | sudo bash napcat.sh", + "metadata": { + "trusted": true, + "execution": { + "iopub.status.busy": "2025-01-25T09:46:33.306378Z", + "iopub.execute_input": "2025-01-25T09:46:33.306682Z", + "iopub.status.idle": "2025-01-25T09:46:34.485925Z", + "shell.execute_reply.started": "2025-01-25T09:46:33.306655Z", + "shell.execute_reply": "2025-01-25T09:46:34.485178Z" + }, + "_kg_hide-input": false + }, + "outputs": [ + { + "name": "stdout", + "text": " % Total % Received % Xferd Average Speed Time Time Time Current\n Dload Upload Total Spent Left Speed\n 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0^C\n", + "output_type": "stream" + } + ], + "execution_count": 1 + }, + { + "id": "c85256bb-873b-449c-8bc6-32cc46f25c63", + "cell_type": "markdown", + "source": "# 2.Install Required Libraries", + "metadata": {} + }, + { + "id": "807ad9ba-f9f0-45a4-985b-bdce343751de", + "cell_type": "code", + "source": "!pip install -q nb-cli nb-cli-plugin-bootstrap nonebot2[fastapi] nonebot-adapter-onebot nonebot-plugin-logpile", + "metadata": { + "trusted": true, + "execution": { + "iopub.status.busy": "2025-01-25T09:46:34.487283Z", + "iopub.execute_input": "2025-01-25T09:46:34.487608Z" + }, + "_kg_hide-input": false + }, + "outputs": [ + { + "name": "stdout", + "text": " Preparing metadata (setup.py) ... \u001B[?25l\u001B[?25hdone\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m64.4/64.4 kB\u001B[0m \u001B[31m4.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m49.6/49.6 kB\u001B[0m \u001B[31m3.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m96.0/96.0 kB\u001B[0m \u001B[31m6.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m78.9/78.9 kB\u001B[0m \u001B[31m5.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m94.8/94.8 kB\u001B[0m \u001B[31m7.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m61.6/61.6 kB\u001B[0m \u001B[31m4.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m114.7/114.7 kB\u001B[0m \u001B[31m8.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m1.1/1.1 MB\u001B[0m \u001B[31m40.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m62.3/62.3 kB\u001B[0m \u001B[31m4.2 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m4.3/4.3 MB\u001B[0m \u001B[31m93.9 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m:00:01\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m425.7/425.7 kB\u001B[0m \u001B[31m25.7 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m469.0/469.0 kB\u001B[0m \u001B[31m28.3 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m442.1/442.1 kB\u001B[0m \u001B[31m30.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m71.5/71.5 kB\u001B[0m \u001B[31m5.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m\n\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m3.8/3.8 MB\u001B[0m \u001B[31m75.6 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m:00:01\u001B[0m\n\u001B[?25h", + "output_type": "stream" + } + ], + "execution_count": null + }, + { + "id": "4b070e72-9521-4f50-a040-6a72614b891b", + "cell_type": "markdown", + "source": "# 3.Initialize The Bot and Install Plugins", + "metadata": {} + }, + { + "id": "bb418a49-e179-4852-a80f-f54d8e6c4dde", + "cell_type": "code", + "source": "!nb bs -y --no-venv -a nonebot.adapters.onebot.v11 nailong\n%cd nailong\n!nb plugin install nonebot-plugin-nailongremove", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + }, + { + "id": "b6f16f96-fee2-4934-a3e1-ff0cb3d42426", + "cell_type": "markdown", + "source": [ + "# 4. Plugin Basic Configuration\n", + "## You can modify some basic configuration items here (**the only globally editable code section**)." + ], + "metadata": {} + }, + { + "id": "1e2b820b-2268-43b3-876d-ecce2cb97bf7", + "cell_type": "code", + "source": [ + "# .env.prod File Configuration\n", + "text='''DRIVER=~fastapi+~httpx+~websockets\n", + "ONEBOT_ACCESS_TOKEN='temp123456'\n", + "ENVIRONMENT=.dev'''" + ], + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + }, + { + "id": "01584ab9-06ad-4438-8718-51e62447618a", + "cell_type": "markdown", + "source": "## Napcat Proxy-related Configuration", + "metadata": {} + }, + { + "id": "438d22d3-a229-4742-aa30-7082303bb914", + "cell_type": "code", + "source": [ + "# Napcat Proxy Settings\n", + "json = '''{\n", + " \"network\": {\n", + " \"httpServers\": [],\n", + " \"httpClients\": [],\n", + " \"websocketServers\": [],\n", + " \"websocketClients\": [\n", + " {\n", + " \"name\": \"nonebot\",\n", + " \"enable\": true,\n", + " \"url\": \"ws://127.0.0.1:8080/onebot/v11/ws\",\n", + " \"messagePostFormat\": \"array\",\n", + " \"reportSelfMessage\": true,\n", + " \"reconnectInterval\": 5000,\n", + " \"token\": \"temp123456\",\n", + " \"debug\": false,\n", + " \"heartInterval\": 30000\n", + " }\n", + " ]\n", + " },\n", + " \"musicSignUrl\": \"\",\n", + " \"enableLocalFile2Url\": false,\n", + " \"parseMultMsg\": true\n", + "}'''\n", + "# Read and modify .env file\n", + "env_file_path = '.env.prod' # Set your .env file path\n", + "# Open the file and add content\n", + "with open(env_file_path, 'w') as file:\n", + " file.write(text)\n", + "# Configure Napcat\n", + "file_path = '/opt/QQ/resources/app/app_launcher/napcat/config/onebot11_3990547445.json'\n", + "with open(file_path, 'w') as file:\n", + " file.write(json)" + ], + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + }, + { + "id": "63f3abc0-ccba-4b41-9955-8028e71f5503", + "cell_type": "markdown", + "source": "# 5.Start the Bot and scan the QR code to log in to QQ", + "metadata": {} + }, + { + "id": "3c8aed7b-6eb5-4a4e-811e-2c502c9cfc87", + "cell_type": "code", + "source": "!xvfb-run -a qq --no-sandbox & nb run", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + } + ] +}