0.4.82 • Published 10 days ago

onebots v0.4.82

Weekly downloads
-
License
MIT
Repository
github
Last release
10 days ago

Build Package Build Docs

npm dm oneBot V11 oneBot V12 node engine qq group

Docs

使用示例

全局安装(0.4.8以后不推荐)

1 安装依赖

  • 注意:
npm install -g onebots

2 初始化配置文件

在你想存放配置文件的目录执行如下命令

onebots

3 更改生成的默认配置文件成你想要的配置配置后再次运行上面的指令,启动项目

局部安装

1 初始化node项目

npm init -y

2. 安装onebots以及对应适配器的依赖

npm install onebots
npm install @icqqjs/icqq # 如需使用icqq适配器,请务必安装
npm install lib-wechat # 如需使用微信适配器,请务必安装
npm install qq-group-bot # 如需使用qq官方机器人适配器,请务必安装
npm install node-dd-bot # 如需使用钉钉机器人适配器,请务必安装
  • 关于@icqqjs的安装引导:

安装: 1. 在你的项目根目录新建文件 .npmrc ,并录入以下内容

@icqqjs:registry=https://npm.pkg.github.com
  1. 命令行输入 npm login --scope=@icqqjs --auth-type=legacy --registry=https://npm.pkg.github.com ,回车,根据提示登录github
npm login --scope=@icqqjs --auth-type=legacy --registry=https://npm.pkg.github.com

UserName: # 你的github账号
Password: # 前往 https://github.com/settings/tokens/new  获取,scopes勾选 read:packages 
E-Mail: # 你的公开邮箱地址
  1. 安装依赖
npm install @icqqjs/icqq  # or > yarn add @icqqjs/icqq

3. 执行如下命令生成配置文件

npx onebots -r icqq #注册icqq适配器并启动onebots
npx onebots -r wechat #注册微信适配器并启动onebots
npx onebots -r qq #注册qq官方适配器并启动onebots
npx onebots -r dingtalk #注册钉钉适配器并启动onebots
# 你也可以同时注册多个适配器,多次使用-r即可,例如 npx onebots -r qq -r icqq -r wechat

4. 更改生成的默认配置文件成你想要的配置配置后再次运行上面的指令,启动项目

默认配置文件

port: 6727 # 监听端口
log_level: info # 日志等级
platform: 5 # 机器人客户端协议(1:Android 2:APad 3:Watch 4:IMac 5:IPad)
timeout: 30 #登录超时时间(秒)
general: # 通用配置,在单个配置省略时的默认值
  V11: # oneBotV11的通用配置
    heartbeat: 3 # 心跳间隔 (秒)
    access_token: "" # 访问api的token
    post_timeout: 15 # 上报超时时间,(秒)
    secret: "" # 上报数据的sha1签名密钥
    rate_limit_interval: 4 # ws心跳间隔(秒)
    post_message_format: string # "string"或"array"
    reconnect_interval: 3 # 重连间隔 (秒)
    use_http: true # 是否使用 http
    enable_cors: true # 是否允许跨域
    filters: {} # 过滤器配置
    use_ws: true # 是否使用websocket
    http_reverse: [] # http上报地址
    ws_reverse: [] # 反向ws连接地址
  V12: # oneBotV12的通用配置
    heartbeat: 3 # 心跳间隔 (秒)
    access_token: "" # 访问api的token
    request_timeout: 15 # 上报超时时间 (秒)
    reconnect_interval: 3 # 重连间隔 (秒)
    enable_cors: true # 是否允许跨域
    use_http: true # 是否启用http
    use_ws: true # 是否启用 websocket
    filters: {} # 过滤器配置
    webhook: [] # http 上报地址
    ws_reverse: [] # 反向ws连接地址
  protocol:
    platform: 2
    sign_api_addr: "" #你的签名地址
    password: "" # 账号密码,未配置则扫码登陆
    # ...其他配置项参考icqq的Config配置
# 每个账号的单独配置(用于覆盖通用配置)
icqq.123456789:
  password: "" # 账号密码,未配置则扫码登陆
  version: V11 # 使用的oneBot版本
  # ...其他配置项参见上方对应oneBot版本的通用配置
  protocol:
    platform: 2
    sign_api_addr: "" #你的签名地址
    # ...其他配置项参考icqq的Config配置

qq.123456789: # `${适配器名称}:${appId}`
  versions:
    - version: V11
  # 。。。其他配置项参见上方对应oneBot版本的通用配置
  protocol: # 将会覆盖通用配置中的protocol
    token: '' # qq机器人token
    secret: '' # qq机器人secret
    sandbox: false # 是否沙箱环境
    intents: # 需要监听的intents
      - 'GROUP_AT_MESSAGE_CREATE' # 群聊@事件 没有群聊权限请注释
      - 'C2C_MESSAGE_CREATE' # 私聊事件 没有私聊权限请注释
      - 'DIRECT_MESSAGE' # 频道私信事件
      #     - 'GUILD_MESSAGES' # 私域机器人频道消息事件,公域机器人请注释
      - 'GUILDS' # 频道变更事件
      - 'GUILD_MEMBERS' # 频道成员变更事件
      - 'GUILD_MESSAGE_REACTIONS' # 频道消息表态事件
      - 'INTERACTION' # 互动事件
      - 'PUBLIC_GUILD_MESSAGES' # 公域机器人频道消息事件,私域机器人请注释
  # 。。。其他配置项参见上方对应oneBot版本的通用配置
  
dingtalk.abcedfg: # `${适配器名称}:${clientId}`
  versions:
    - version: V11
    - version: V12
  protocol:
    clientSecret: '' # 钉钉机器人秘钥 必填
    username: '钉钉机器人' #钉钉后台配置的机器人名称 不填则显示'钉钉机器人'
    avatar: '' # 机器人头像 不填则显示钉钉logo

wechat.bot1: # `${适配器名称}:${机器人唯一标识}`
  versions:
    - version: V11
    - version: V12
  protocol: {}

配置解释

Config

配置项类型默认值desc
portnumber6727服务监听端口
logLevelstringinfo日志级别
general{V11:V11.Config,V12:V12.Config}general通用配置
adapter.numberOneBotConfig-机器人配置

OneBotConfig

配置项类型默认值desc
passwordstring-仅icqq生效,账号密码 未填写或填写为空则扫码登陆
V11V11.ConfigconfigV11V11配置
V12V12.ConfigconfigV12V12配置
protocol传递给client初始化的配置{}

ConfigV11

配置项类型默认值desc
heartbeatnumber3心跳间隔 单位:秒
access_tokenstring-访问令牌
secretstring-签名密钥
rate_limit_intervalnumber4限速间隔 单位:秒
post_message_formatstringstring消息格式化
reconnect_intervalnumber3重连间隔 单位:秒
use_httpbooleanfalse是否使用http协议
enable_corsbooleanfalse是否允许跨域
filtersFilters{}事件过滤器配置
use_wsbooleanfalse是否使用ws协议
http_reverse_urlstring[]-http上报地址地址
ws_reverse_urlstring[]-反向ws连接地址

ConfigV12

配置项类型默认值desc
heartbeatnumber3心跳间隔 单位:秒
access_tokenstring-访问令牌
request_timeoutnumber15请求超时 单位:秒
reconnect_intervalnumber3重连间隔 单位:秒
enable_corsbooleanfalse是否允许跨域
filtersFilters{}事件过滤器配置
use_httpbooleanfalse是否使用http协议
use_wsbooleanfalse是否使用ws协议
webhook_reverse_urlstring[]-webhook上报地址
ws_reverse_urlstring[]-反向ws连接地址

事件过滤器

语法说明

  • onebots 的事件过滤器最外层是一个JSON对象,其中的键是键如果是运算法,则值作为运算符的参数,如果不是运算符,则表示对事件数据对象相应 key 进行过滤。
  • 过滤规则中任何一个对象, 只有在它的所有项都匹配的情况下, 才会让事件通过(等价于一个 and 运算),如果值为一个数组,则表示事件对应 key 值需满足其中一个。
  • 可用逻辑运算符有:$and (逻辑与) 、$or (逻辑或) 、 $not (逻辑非)、$nor (逻辑异或)、$regexp (文本正则匹配)、$like (文本模糊匹配)、$gt (数值大于比较)、$gte (数值大于等于比较)、$lt (数值小于比较)、$lte (数值小于等于比较)、$between (数值范围比较)

示例

1. 仅上报私聊事件

filters:
  message_type: private

2. 私聊或指定群聊

filters:
  $or:
    message_type: private
    group_id:
      - 123456789 987654321

3. 私聊事件且不是指定用户

filters:
  message_type: private
  $not:
    user_id:
      - 123456789 987654321

4. 私聊事件(排除指定用户的事件)或指定群聊事件

filters:
  $or:
    - message_type: private
      $not:
        user_id: 123456789
    - message_type: group
      group_id: 987654321

5. 仅上报消息事件且用户年龄大于18岁

filters:
  type: message
  sender:
    age:
      $gt: 18

6. 仅上报消息事件且消息内容以!开头的消息

filters:
  type: message
  raw_message:
    .regexp: '^!|\!'

7. 不上报消息内容包含cnm的消息

filters:
  $not:
    type: message
    raw_message:
      $like: cnm

使用API管理oneBot

urlmethodparamsdesc
/listGET获取当前运行的机器人列表
/detailGETuin获取指定机器人配置
/qrcodeGETuin获取指定机器人登录二维码
/addPOST{uin,...config}添加机器人 config 为机器人配置
/editPOST{uin,...config}修改机器人配置 config 为机器人配置
/removegetuin,force移除机器人,force为true时,将删除机器人data目录

鸣谢

  1. icqqjs/icqq 底层服务支持
  2. takayama-lily/onebot oneBot V11 原先版本
0.4.82

10 days ago

0.4.81

11 days ago

0.4.79

17 days ago

0.4.78

27 days ago

0.4.77

2 months ago

0.4.73

2 months ago

0.4.71

2 months ago

0.4.72

2 months ago

0.4.70

2 months ago

0.4.68

2 months ago

0.4.69

2 months ago

0.4.67

2 months ago

0.4.65

2 months ago

0.4.66

2 months ago

0.4.64

2 months ago

0.4.63

2 months ago

0.4.62

2 months ago

0.4.61

2 months ago

0.4.60

3 months ago

0.4.59

3 months ago

0.4.57

3 months ago

0.4.58

3 months ago

0.4.56

3 months ago

0.4.54

3 months ago

0.4.53

3 months ago

0.4.51

4 months ago

0.4.50

4 months ago

0.4.48

4 months ago

0.4.49

4 months ago

0.4.47

4 months ago

0.4.46

4 months ago

0.4.44

4 months ago

0.4.45

4 months ago

0.4.42

4 months ago

0.4.43

4 months ago

0.4.40

4 months ago

0.4.41

4 months ago

0.4.39

4 months ago

0.4.37

4 months ago

0.4.38

4 months ago

0.4.32

4 months ago

0.4.35

4 months ago

0.4.36

4 months ago

0.4.33

4 months ago

0.4.34

4 months ago

0.4.31

6 months ago

0.4.30

6 months ago

0.4.20

7 months ago

0.4.21

7 months ago

0.4.28

6 months ago

0.4.29

6 months ago

0.4.26

6 months ago

0.4.27

6 months ago

0.4.25

6 months ago

0.4.22

7 months ago

0.4.23

6 months ago

0.4.19

8 months ago

0.4.18

8 months ago

0.4.17

8 months ago

0.4.16

8 months ago

0.4.9

10 months ago

0.4.8

10 months ago

0.4.10

10 months ago

0.4.15

8 months ago

0.4.13

9 months ago

0.4.14

9 months ago

0.4.11

10 months ago

0.4.12

9 months ago

0.4.5

11 months ago

0.4.4

11 months ago

0.4.7

11 months ago

0.4.6

11 months ago

0.4.1

11 months ago

0.4.0

12 months ago

0.4.3

11 months ago

0.4.2

11 months ago

0.2.6

12 months ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.5

12 months ago

0.2.4

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.15

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.8

1 year ago

0.0.26

1 year ago

0.1.7

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.1.9

1 year ago

0.0.29

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.6-alpha

1 year ago

0.0.15

1 year ago

0.0.9

1 year ago

0.0.16

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

2 years ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.1

2 years ago