1.0.4 • Published 2 years ago

@lc-cn/oicq-bots v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

oicq-bots

用于生产环境部署oicq

安装

npm install @lc-cn/oicq-bots
# or
yarn add @lc-cn/oicq-bots

样例

1.javascript

const {App} =require('@lc-cn/oicq-bots')
const fs = require('fs')
const path = require('path')
const configPath=path.join(process.cwd(),'oicq.config.json')
const appOption=JSON.parse(fs.readFileSync(configPath,{encoding:"utf-8"}))
const app=new App(appOption)
app.start(8086)

2.typescript

import {App,AppOptions} from '../src'
import * as fs from 'fs'
import * as path from "path";
const configPath=path.join(process.cwd(),'oicq.config.json')
const appOption:AppOptions=JSON.parse(fs.readFileSync(configPath,{encoding:"utf-8"}))
const app=new App(appOption)
app.start(8086)

Class:App

继承自Koa类,拥有Koa上所有方法和属性

MethodDescriptionargs
constructor构造函数options:AppOptions
addBot新增一个Botoption:BotOptions
removeBot移除一个Botuin:number
propertyDescriptiontype
botsbot容器BotList
router项目路由Router

Class Bot

继承自oicq的Client类,拥有Client类的所有方法和属性

MethodDescriptionargs
constructor构造函数options:BotOptions

Class Router

继承自KoaRouter类,拥有KoaRouter类所有方法和属性

MethodDescriptionargs
ws添加一个ws监听path: String, server: HttpServer
propertyDescriptiontype
wsStackws监听存放容器WebsocketServer[]
whiteList每生成一个route,会往里面存入一个Path,可用于historyApi的whitelistPath

Class BotList

继承自原生Array类,拥有Array类的所有方法和属性

MethodDescriptionargs
get获取指定uin的botuin:number
create根据options创建一个botoptions:BotOptions
remove移除指定uin的botuin:number

Interface/Type

type LoginType='qrcode'|'password'
type Path=string|RegExp
interface App extends Koa{
    constructor(options?:AppOptions):App
    addBot(options:BotOptions):Bot
    removeBot(uin:number):void
}
interface KoaOptions{
    env?: string | undefined,
    keys?: string[] | undefined,
    proxy?: boolean | undefined,
    subdomainOffset?: number | undefined,
    proxyIpHeader?: string | undefined,
    maxIpsCount?: number | undefined
}
interface AppOptions extends KoaOptions{
    path?:string
    bots?:BotOptions[]
}
interface BotOptions{
    uin:number
    config:Config,
    type:LoginType
    password?:string
    oneBot?:boolean|OneBotConfig//传true时将使用默认配置
}
interface OneBotConfig{
    use_http?: boolean,
    use_ws?: boolean,
    access_token?: string,
    secret?: string,
    post_timeout: number,
    post_message_format: "string" | "array"
    enable_cors?: boolean,
    event_filter: string,
    enable_heartbeat?: boolean,
    heartbeat_interval?: number,
    rate_limit_interval?: number,
    post_url?: string[],
    ws_reverse_url?: string[],
    ws_reverse_reconnect_interval?: number,
    use_cqhttp_notice?: boolean,
}
export const defaultOneBotConfig={
    use_cqhttp_notice: true,
    use_http: true,
    use_ws: true,
    access_token: "",
    secret: "",
    post_timeout: 30,
    post_message_format: "array",
    enable_cors: true,
    event_filter: "",
    enable_heartbeat: true,
    heartbeat_interval: 15000,
    rate_limit_interval: 500,
    post_url: [],
    ws_reverse_url: [],
    ws_reverse_reconnect_interval: 3000,
}

cli

项目增加了cli指令,用于增加/删除和启动项目

usage

此处提供两种用法:

1.全局安装@lc-cn/oicq-bots

npm install -g @lc-cn/oicq-bots
oitq add //开启一个添加账号流程
oitq remove // 开启一个移除账号流程
oitq start // 启动项目 

2.如果不想全局安装,可使用软连接激活cli指令

npm install @lc-cn/oicq-bots
npm link @lc-cn/oicq-bots
oitq add //开启一个添加账号流程
oitq remove // 开启一个移除账号流程
oitq start // 启动项目 
1.0.1

2 years ago

1.0.2-alpha

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0-alpha

2 years ago

1.0.1-beta

2 years ago

1.0.0

2 years ago