koishi-plugin-adapter-onebot-multi 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/admin.d.ts +52 -0
- package/lib/bot/base.d.ts +36 -0
- package/lib/bot/cqcode.d.ts +13 -0
- package/lib/bot/index.d.ts +43 -0
- package/lib/bot/message.d.ts +25 -0
- package/lib/bot/qqguild.d.ts +31 -0
- package/lib/config-manager.d.ts +70 -0
- package/lib/heartbeat.d.ts +18 -0
- package/lib/index.d.ts +49 -0
- package/lib/index.js +3165 -0
- package/lib/panel.d.ts +32 -0
- package/lib/status.d.ts +39 -0
- package/lib/types.d.ts +481 -0
- package/lib/utils.d.ts +13 -0
- package/lib/ws.d.ts +31 -0
- package/package.json +49 -0
- package/readme.md +5 -0
package/lib/admin.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { ConfigManager, BotConfigRecord } from './config-manager';
|
|
3
|
+
import { StatusManager, BotStatus } from './status';
|
|
4
|
+
export interface BotFullInfo extends BotStatus {
|
|
5
|
+
config: Omit<BotConfigRecord, 'token'>;
|
|
6
|
+
}
|
|
7
|
+
export interface AdminPanelData {
|
|
8
|
+
bots: BotFullInfo[];
|
|
9
|
+
updatedAt: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Console 管理面板服务
|
|
13
|
+
* 提供 Bot 配置的增删改查 API
|
|
14
|
+
*/
|
|
15
|
+
export declare function setupAdminPanel(ctx: Context, configManager: ConfigManager, statusManager: StatusManager): void;
|
|
16
|
+
declare module '@koishijs/console' {
|
|
17
|
+
interface Events {
|
|
18
|
+
'onebot-multi/admin/list'(): Promise<AdminPanelData>;
|
|
19
|
+
'onebot-multi/admin/create'(data: {
|
|
20
|
+
selfId: string;
|
|
21
|
+
token?: string;
|
|
22
|
+
protocol: 'ws' | 'ws-reverse';
|
|
23
|
+
endpoint?: string;
|
|
24
|
+
path?: string;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
success: boolean;
|
|
27
|
+
record: BotConfigRecord;
|
|
28
|
+
}>;
|
|
29
|
+
'onebot-multi/admin/update'(data: {
|
|
30
|
+
selfId: string;
|
|
31
|
+
updates: {
|
|
32
|
+
token?: string;
|
|
33
|
+
protocol?: 'ws' | 'ws-reverse';
|
|
34
|
+
endpoint?: string;
|
|
35
|
+
path?: string;
|
|
36
|
+
};
|
|
37
|
+
}): Promise<{
|
|
38
|
+
success: boolean;
|
|
39
|
+
needRestart: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
'onebot-multi/admin/delete'(selfId: string): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
'onebot-multi/admin/toggle'(selfId: string): Promise<{
|
|
45
|
+
success: boolean;
|
|
46
|
+
enabled: boolean;
|
|
47
|
+
}>;
|
|
48
|
+
'onebot-multi/admin/restart'(selfId: string): Promise<{
|
|
49
|
+
success: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Bot, Context, Schema, Universal } from 'koishi';
|
|
2
|
+
import * as OneBot from '../utils';
|
|
3
|
+
import { OneBotMessageEncoder } from './message';
|
|
4
|
+
export declare class BaseBot<C extends Context = Context, T extends BaseBot.Config = BaseBot.Config> extends Bot<C, T> {
|
|
5
|
+
static MessageEncoder: typeof OneBotMessageEncoder;
|
|
6
|
+
static inject: string[];
|
|
7
|
+
parent?: BaseBot;
|
|
8
|
+
internal: OneBot.Internal;
|
|
9
|
+
createDirectChannel(userId: string): Promise<{
|
|
10
|
+
id: string;
|
|
11
|
+
type: Universal.Channel.Type;
|
|
12
|
+
}>;
|
|
13
|
+
getMessage(channelId: string, messageId: string): Promise<Universal.Message>;
|
|
14
|
+
deleteMessage(channelId: string, messageId: string): Promise<void>;
|
|
15
|
+
getLogin(): Promise<Universal.Login>;
|
|
16
|
+
getUser(userId: string): Promise<Universal.User>;
|
|
17
|
+
getFriendList(): Promise<{
|
|
18
|
+
data: Universal.User[];
|
|
19
|
+
}>;
|
|
20
|
+
handleFriendRequest(messageId: string, approve: boolean, comment?: string): Promise<void>;
|
|
21
|
+
handleGuildRequest(messageId: string, approve: boolean, comment?: string): Promise<void>;
|
|
22
|
+
handleGuildMemberRequest(messageId: string, approve: boolean, comment?: string): Promise<void>;
|
|
23
|
+
deleteFriend(userId: string): Promise<void>;
|
|
24
|
+
getMessageList(channelId: string, before?: string, direction?: Universal.Direction): Promise<{
|
|
25
|
+
data: Universal.Message[];
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
export declare namespace BaseBot {
|
|
29
|
+
interface Config {
|
|
30
|
+
advanced?: AdvancedConfig;
|
|
31
|
+
}
|
|
32
|
+
interface AdvancedConfig {
|
|
33
|
+
splitMixedContent?: boolean;
|
|
34
|
+
}
|
|
35
|
+
const AdvancedConfig: Schema<AdvancedConfig>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Dict, h } from 'koishi';
|
|
2
|
+
export declare function CQCode(type: string, attrs: Dict<string>): string;
|
|
3
|
+
export interface CQCode {
|
|
4
|
+
type: string;
|
|
5
|
+
data: Dict<string>;
|
|
6
|
+
capture?: RegExpExecArray;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace CQCode {
|
|
9
|
+
function escape(source: any, inline?: boolean): string;
|
|
10
|
+
function unescape(source: string): string;
|
|
11
|
+
function from(source: string): CQCode;
|
|
12
|
+
function parse(source: string | CQCode[]): h[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Context, Schema, Session } from 'koishi';
|
|
2
|
+
import { QQGuildBot } from './qqguild';
|
|
3
|
+
import { BaseBot } from './base';
|
|
4
|
+
import { WsClient, WsServer } from '../ws';
|
|
5
|
+
import { HeartbeatMonitor } from '../heartbeat';
|
|
6
|
+
export * from './base';
|
|
7
|
+
export * from './cqcode';
|
|
8
|
+
export * from './message';
|
|
9
|
+
export * from './qqguild';
|
|
10
|
+
export declare class OneBotBot<C extends Context = Context, T extends OneBotBot.Config = OneBotBot.Config> extends BaseBot<C, T> {
|
|
11
|
+
guildBot: QQGuildBot<C>;
|
|
12
|
+
heartbeat: HeartbeatMonitor;
|
|
13
|
+
constructor(ctx: C, config: T);
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
initialize(): Promise<void>;
|
|
16
|
+
setupGuildService(): Promise<void>;
|
|
17
|
+
getChannel(channelId: string): Promise<import("@satorijs/protocol").Channel>;
|
|
18
|
+
getGuild(guildId: string): Promise<import("@satorijs/protocol").Guild>;
|
|
19
|
+
getGuildList(): Promise<{
|
|
20
|
+
data: import("@satorijs/protocol").Guild[];
|
|
21
|
+
}>;
|
|
22
|
+
getChannelList(guildId: string): Promise<{
|
|
23
|
+
data: import("@satorijs/protocol").Channel[];
|
|
24
|
+
}>;
|
|
25
|
+
getGuildMember(guildId: string, userId: string): Promise<import("@satorijs/protocol").GuildMember>;
|
|
26
|
+
getGuildMemberList(guildId: string): Promise<{
|
|
27
|
+
data: import("@satorijs/protocol").GuildMember[];
|
|
28
|
+
}>;
|
|
29
|
+
kickGuildMember(guildId: string, userId: string, permanent?: boolean): Promise<void>;
|
|
30
|
+
muteGuildMember(guildId: string, userId: string, duration: number): Promise<void>;
|
|
31
|
+
muteChannel(channelId: string, guildId?: string, enable?: boolean): Promise<void>;
|
|
32
|
+
checkPermission(name: string, session: Partial<Session>): Promise<boolean>;
|
|
33
|
+
}
|
|
34
|
+
export declare namespace OneBotBot {
|
|
35
|
+
interface BaseConfig extends BaseBot.Config {
|
|
36
|
+
selfId: string;
|
|
37
|
+
token?: string;
|
|
38
|
+
heartbeatInterval?: number;
|
|
39
|
+
}
|
|
40
|
+
const BaseConfig: Schema<BaseConfig>;
|
|
41
|
+
type Config = BaseConfig & (WsServer.Options | WsClient.Options);
|
|
42
|
+
const Config: Schema<Config>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Context, h, MessageEncoder, Universal } from 'koishi';
|
|
2
|
+
import { BaseBot } from './base';
|
|
3
|
+
import { CQCode } from './cqcode';
|
|
4
|
+
export interface Author extends Universal.User {
|
|
5
|
+
time?: string | number;
|
|
6
|
+
messageId?: string;
|
|
7
|
+
}
|
|
8
|
+
declare class State {
|
|
9
|
+
type: 'message' | 'forward' | 'reply';
|
|
10
|
+
author: Partial<Author>;
|
|
11
|
+
children: CQCode[];
|
|
12
|
+
constructor(type: 'message' | 'forward' | 'reply');
|
|
13
|
+
}
|
|
14
|
+
export declare const PRIVATE_PFX = "private:";
|
|
15
|
+
export declare class OneBotMessageEncoder<C extends Context = Context> extends MessageEncoder<C, BaseBot<C>> {
|
|
16
|
+
stack: State[];
|
|
17
|
+
children: CQCode[];
|
|
18
|
+
prepare(): Promise<void>;
|
|
19
|
+
forward(): Promise<void>;
|
|
20
|
+
flush(): Promise<void>;
|
|
21
|
+
private sendFile;
|
|
22
|
+
private text;
|
|
23
|
+
visit(element: h): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Context, Universal } from 'koishi';
|
|
2
|
+
import { BaseBot } from './base';
|
|
3
|
+
import { OneBotBot } from './index';
|
|
4
|
+
import * as OneBot from '../utils';
|
|
5
|
+
export declare namespace QQGuildBot {
|
|
6
|
+
interface Config extends BaseBot.Config {
|
|
7
|
+
parent: OneBotBot<Context>;
|
|
8
|
+
profile: OneBot.GuildServiceProfile;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare class QQGuildBot<C extends Context> extends BaseBot<C> {
|
|
12
|
+
parent: OneBotBot<Context>;
|
|
13
|
+
hidden: boolean;
|
|
14
|
+
constructor(ctx: C, config: QQGuildBot.Config);
|
|
15
|
+
get status(): Universal.Status;
|
|
16
|
+
set status(status: Universal.Status);
|
|
17
|
+
start(): Promise<void>;
|
|
18
|
+
stop(): Promise<void>;
|
|
19
|
+
getChannel(channelId: string, guildId?: string): Promise<Universal.Channel>;
|
|
20
|
+
getChannelList(guildId: string): Promise<{
|
|
21
|
+
data: Universal.Channel[];
|
|
22
|
+
}>;
|
|
23
|
+
getGuild(guildId: string): Promise<Universal.Guild>;
|
|
24
|
+
getGuildList(): Promise<{
|
|
25
|
+
data: Universal.Guild[];
|
|
26
|
+
}>;
|
|
27
|
+
getGuildMember(guildId: string, userId: string): Promise<Universal.GuildMember>;
|
|
28
|
+
getGuildMemberList(guildId: string): Promise<{
|
|
29
|
+
data: Universal.GuildMember[];
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import type { BotConfig } from './index';
|
|
3
|
+
declare module 'koishi' {
|
|
4
|
+
interface Tables {
|
|
5
|
+
'onebot_multi_bots': BotConfigRecord;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export interface BotConfigRecord {
|
|
9
|
+
id: number;
|
|
10
|
+
selfId: string;
|
|
11
|
+
token?: string;
|
|
12
|
+
protocol: 'ws' | 'ws-reverse';
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
path?: string;
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
}
|
|
19
|
+
export declare class ConfigManager {
|
|
20
|
+
private ctx;
|
|
21
|
+
constructor(ctx: Context);
|
|
22
|
+
/**
|
|
23
|
+
* 获取存储的密码哈希
|
|
24
|
+
*/
|
|
25
|
+
private getStoredPasswordHash;
|
|
26
|
+
/**
|
|
27
|
+
* 设置管理密码(哈希存储)
|
|
28
|
+
*/
|
|
29
|
+
setAdminPassword(password: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* 检查是否已设置密码
|
|
32
|
+
*/
|
|
33
|
+
hasAdminPassword(): Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* 验证管理密码
|
|
36
|
+
*/
|
|
37
|
+
verifyAdminPassword(password: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* 获取所有 Bot 配置(排除系统配置)
|
|
40
|
+
*/
|
|
41
|
+
getAllConfigs(): Promise<BotConfigRecord[]>;
|
|
42
|
+
/**
|
|
43
|
+
* 获取启用的 Bot 配置(排除系统配置)
|
|
44
|
+
*/
|
|
45
|
+
getEnabledConfigs(): Promise<BotConfigRecord[]>;
|
|
46
|
+
/**
|
|
47
|
+
* 获取单个 Bot 配置
|
|
48
|
+
*/
|
|
49
|
+
getConfig(selfId: string): Promise<BotConfigRecord | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* 创建 Bot 配置
|
|
52
|
+
*/
|
|
53
|
+
createConfig(config: Omit<BotConfigRecord, 'id' | 'createdAt' | 'updatedAt'>): Promise<BotConfigRecord>;
|
|
54
|
+
/**
|
|
55
|
+
* 更新 Bot 配置
|
|
56
|
+
*/
|
|
57
|
+
updateConfig(selfId: string, updates: Partial<Omit<BotConfigRecord, 'id' | 'selfId' | 'createdAt'>>): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* 删除 Bot 配置
|
|
60
|
+
*/
|
|
61
|
+
deleteConfig(selfId: string): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* 切换 Bot 启用状态
|
|
64
|
+
*/
|
|
65
|
+
toggleEnabled(selfId: string): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* 将数据库配置转换为 BotConfig 格式
|
|
68
|
+
*/
|
|
69
|
+
toBotConfig(record: BotConfigRecord): BotConfig;
|
|
70
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import type { OneBotBot } from './bot';
|
|
3
|
+
export interface HeartbeatConfig {
|
|
4
|
+
/** 心跳检测间隔(毫秒) */
|
|
5
|
+
heartbeatInterval?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class HeartbeatMonitor {
|
|
8
|
+
private ctx;
|
|
9
|
+
private bot;
|
|
10
|
+
private interval;
|
|
11
|
+
private timer;
|
|
12
|
+
private logger;
|
|
13
|
+
private lastOnlineState;
|
|
14
|
+
constructor(ctx: Context, bot: OneBotBot, interval: number);
|
|
15
|
+
start(): void;
|
|
16
|
+
stop(): void;
|
|
17
|
+
private check;
|
|
18
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
import { OneBotBot } from './bot';
|
|
3
|
+
import { BaseBot } from './bot/base';
|
|
4
|
+
import { PanelConfig } from './panel';
|
|
5
|
+
import * as OneBot from './utils';
|
|
6
|
+
export { OneBot };
|
|
7
|
+
export * from './bot';
|
|
8
|
+
export * from './ws';
|
|
9
|
+
export * from './heartbeat';
|
|
10
|
+
export * from './status';
|
|
11
|
+
export * from './panel';
|
|
12
|
+
export * from './config-manager';
|
|
13
|
+
export interface BotConfig {
|
|
14
|
+
selfId: string;
|
|
15
|
+
token?: string;
|
|
16
|
+
protocol?: 'ws' | 'ws-reverse';
|
|
17
|
+
endpoint?: string;
|
|
18
|
+
path?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Config {
|
|
21
|
+
responseTimeout?: number;
|
|
22
|
+
heartbeatInterval?: number;
|
|
23
|
+
retryTimes?: number;
|
|
24
|
+
retryInterval?: number;
|
|
25
|
+
retryLazy?: number;
|
|
26
|
+
advanced?: BaseBot.AdvancedConfig;
|
|
27
|
+
panel?: PanelConfig;
|
|
28
|
+
}
|
|
29
|
+
export declare const Config: Schema<Config>;
|
|
30
|
+
export declare const name = "adapter-onebot-multi";
|
|
31
|
+
export declare const inject: {
|
|
32
|
+
required: string[];
|
|
33
|
+
};
|
|
34
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
35
|
+
declare module 'koishi' {
|
|
36
|
+
interface Events {
|
|
37
|
+
'onebot/message-reactions-updated'(session: import('koishi').Session): void;
|
|
38
|
+
'onebot/channel-updated'(session: import('koishi').Session): void;
|
|
39
|
+
'onebot/channel-created'(session: import('koishi').Session): void;
|
|
40
|
+
'onebot/channel-destroyed'(session: import('koishi').Session): void;
|
|
41
|
+
'onebot-multi/bot-online'(bot: OneBotBot): void;
|
|
42
|
+
'onebot-multi/bot-offline'(bot: OneBotBot): void;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
declare module '@satorijs/core' {
|
|
46
|
+
interface Session {
|
|
47
|
+
onebot?: OneBot.Payload & OneBot.Internal;
|
|
48
|
+
}
|
|
49
|
+
}
|