One-click installation and use of NoneBot (for CentOS)

Original link: https://blog.saky.site/post/nonebot/

This tutorial takes the latest NoneBot 2.0 as an example

The one-click installation script will automatically install python3.9 and NoneBot scaffolding

 yum install -y wget && wget -O https://carcloud.ml/sh/nonebot_install.sh && bash nonebot_install.sh

create project

Use scaffolding to create a project:

 nb create

This command will execute the process of creating a project, you will see some queries:

  1. project template
 [?] 选择一个要使用的模板: bootstrap (初学者或用户)

Here we choose the bootstrap template, which is a simple project template that can install store plugins. If you need to write your own plugin , please choose the simple template here.

  1. project name
 [?] 项目名称: mybot

Here we take mybot as an example as the project name. You can name it according to your needs.

  1. For other options, please note that multiple options use spaces to select or cancel, and press Enter to confirm.
 [?] 要使用哪些驱动器? FastAPI (FastAPI 驱动器) [?] 要使用哪些适配器? Console (基于终端的交互式适配器) [?] 立即安装依赖? (Y/n) Yes [?] 创建虚拟环境? (Y/n) Yes

Here we choose to create a virtual environment, and nb-cli will automatically use this virtual environment in subsequent operations. If you don’t need to automatically create a virtual environment or have created other virtual environments, nb-cli will install dependencies to the currently active Python virtual environment.

  1. Select built-ins (optional)
 [?] 要使用哪些内置插件? echo

Here we choose the echo plugin as an example. This is a simple repeat echo plugin that can be used to test whether your bot is working properly.

run project

After the project is created, you can run the project with the following command in项目目录:

 nb run

You should now have your first NoneBot project up and running! Please note that the FastAPI driver and Console adapter are used in the generated project, you can modify the configuration or install other adapters yourself later.

Customize NoneBot

Note : In the latest version of NoneBot, there is only .env.prod file by default

  • .env file is the basic configuration file. The configuration items in this file will be loaded in different environments, but will be overwritten by the configuration in .env.{ENVIRONMENT} file.
  • Go to the project root directory, create a new .env file, and write the current environment information:
 HOST=0.0.0.0 # 配置NoneBot 监听的IP / 主机名PORT=8080 # 配置NoneBot 监听的端口,默认为8080,建议修改COMMAND_START=["/"] # 配置命令起始字符COMMAND_SEP=["."] # 配置命令分割字符

go-cqhttp starter for NoneBot

 nb plugin install nonebot-plugin-gocqhttp
  • Default WebUI address: http://NoneBot运行服务器ip:NoneBot监听的端口/go-cqhttp/
  • Enter the web console, enter the QQ number, do not enter the password, and choose to scan the code to log in with Android Watch

NoneBot runs in the background (keep alive)

Screen detailed command reference: https://www.runoob.com/linux/linux-comm-screen.html

 ## 安装screen yum install screen ## NoneBot可以自定义screen -S NoneBot ## cd 项目目录后执行nb run nb run ## 离开窗口:screen终端下按下Ctrl+ad键即可离开虚拟窗口,回到真实的terminal ## 再次进入窗口NoneBot screen -r NoneBot

NoneBot Wike & Store

This article is transferred from: https://blog.saky.site/post/nonebot/
This site is only for collection, and the copyright belongs to the original author.