/// /// /// /// import * as log4js from 'log4js'; import { BinaryLike } from 'crypto'; import { EventEmitter } from 'events'; import { AxiosInstance } from 'axios'; import { WebSocket } from 'ws'; export const toObject: (data: any) => T; /** md5 hash */ export const md5: (data: BinaryLike) => string; export function isEmpty(data: T): boolean; export function remove(list: T[], item: T): void; export function getBase64FromLocal(filepath: string): Promise; export function getBase64FromWeb(url: string): Promise; export function getFileBase64(file: string | Buffer): string | Promise; export function deepClone(obj: T): any; /** * 寻找数组中最后一个符合条件的元素下标 * @param list 数组 * @param predicate 条件 * @returns {number} 元素下标,未找到返回-1 */ export function findLastIndex(list: T[], predicate: (item: T, index: number) => boolean): number; export function trimQuote(str: string): string; export enum OpCode { DISPATCH = 0,// 服务端进行消息推送 HEARTBEAT = 1,// 客户端发送心跳 IDENTIFY = 2,// 鉴权 RESUME = 6,// 恢复连接 RECONNECT = 7,// 服务端通知客户端重连 INVALID_SESSION = 9,// 当identify或resume的时候,如果参数有错,服务端会返回该消息 HELLO = 10,// 当客户端与网关建立ws连接之后,网关下发的第一条消息 HEARTBEAT_ACK = 11 } export const UnsupportedMethodError: Error; export const SessionEvents: { CLOSED: string; READY: string; ERROR: string; INVALID_SESSION: string; RECONNECT: string; DISCONNECT: string; EVENT_WS: string; RESUMED: string; DEAD: string; }; export const WebsocketCloseReason: ({ code: number; reason: string; resume?: undefined; } | { code: number; reason: string; resume: boolean; })[]; export enum Intends { GUILDS = 1,// 频道操作事件 GUILD_MEMBERS = 2,// 频道成员变更事件 GUILD_MESSAGES = 512,// 私域频道消息事件 GUILD_MESSAGE_REACTIONS = 1024,// 频道消息表态事件 DIRECT_MESSAGE = 4096,// 频道私信事件 OPEN_FORUMS_EVENTS = 262144, AUDIO_OR_LIVE_CHANNEL_MEMBERS = 524288,// 音频或直播频道成员 C2C_MESSAGE_CREATE = 33554432,// 私聊消息事件 GROUP_AT_MESSAGE_CREATE = 33554432,// 群聊@消息事件 INTERACTION = 67108864,// 互动事件 MESSAGE_AUDIT = 134217728,// 消息审核事件 FORUMS_EVENTS = 268435456,// 论坛事件(仅私域) AUDIO_ACTIONS = 536870912,// 音频操作事件 PUBLIC_GUILD_MESSAGES = 1073741824 } export type Intent = 'GUILDS' | 'GUILD_MEMBERS' | 'GUILD_MESSAGES' | 'GUILD_MESSAGE_REACTIONS' | 'DIRECT_MESSAGE' | 'AUDIO_OR_LIVE_CHANNEL_MEMBERS' | 'GROUP_MESSAGE_CREATE' | 'C2C_MESSAGE_CREATE' | 'GROUP_AT_MESSAGE_CREATE' | 'INTERACTION' | 'MESSAGE_AUDIT' | 'FORUMS_EVENTS' | 'OPEN_FORUMS_EVENTS' | 'AUDIO_ACTIONS' | 'PUBLIC_GUILD_MESSAGES'; export enum ChannelType { Content = 0,// 文本频道 Record = 2,// 语音频道 ChannelGroup = 4,// 频道分组 Live = 10005,// 直播频道 App = 10006,// 应用频道 Forms = 10007 } export enum ChannelSubType { Chat = 0,// 闲聊 Announces = 1,// 公告 Strategy = 2,// 攻略 Black = 3 } export enum PrivateType { Public = 0,// 公开 Admin = 1,// 频道主和管理员 Some = 2 } export enum SpeakPermission { All = 1,// 所有人 Some = 2 } export namespace Channel { interface Info { id: string; guild_id: string; name: string; type: ChannelType; sub_type: ChannelSubType; position: number; parent_id?: string; owner_id: string; private_type: PrivateType; speak_permission: SpeakPermission; application_id?: string; permissions?: string; } type ApiInfo = Omit & { channel_id: string; channel_name: string; }; } export namespace Guild { interface Info { id: string; name: string; icon: string; owner_id: string; owner: boolean; join_time: number; member_count: number; max_members: number; description: string; } type ApiInfo = Omit & { guild_id: string; guild_name: string; }; interface Role { id: string; name: string; color: string; hoist: boolean; number: number; member_limit: number; } } export namespace User { interface Info { id: string; username: string; avatar: string; bot: boolean; public_flag: number; } enum Permission { normal = 1, admin = 2, owner = 4, channelAdmin = 5 } } export namespace GuildMember { interface Info { user: User.Info; nick: string; roles: string[]; join_time: number; } interface ApiInfo { member_id: string; username: string; avatar: string; card: string; bot?: boolean; roles: string[]; join_time: number; union_openid?: string; union_user_account?: string; } } export type Dict = Record; export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "mark" | "off"; export interface wsResData { op: number; d?: { heartbeat_interval?: number; session_id?: string; user?: { id?: string; username?: string; bot?: boolean; status?: number; }; }; s: number; t: string; id?: string; } export enum AnnounceType { Member = 0, WelCome = 1 } export type Announce = { guild_id: string; channel_id: string; message_id: string; announces_type: AnnounceType; recommend_channels: { channel_id: string; introduce: string; }[]; }; export type ChannelPermissions = { channel_id: string; permissions: string; }; export type ChannelMemberPermissions = { user_id: string; } & ChannelPermissions; export type ChannelRolePermissions = { role_id: string; } & ChannelPermissions; export type UpdatePermissionParams = { add?: string; remove?: string; }; export type FaceType = 1 | 2; export type ChannelUpdateInfo = Partial>; export type RoleCreateParam = { name?: string; color: number; hoist: 0 | 1; }; export type RoleUpdateParam = Partial>; export type PinsMessage = { guild_id: string; channel_id: string; message_ids: string[]; }; export interface DMS { guild_id: string; channel_id: string; create_time: number; } export interface ScheduleInfo { id?: string; name: string; description?: string; start_timestamp: string; end_timestamp: string; creator?: GuildMember.ApiInfo; jump_channel_id: string; remind_type: RemindType; } export type RemindType = 0 | 1 | 2 | 3 | 4 | 5 | 6; export type AudioStatus = 0 | 1 | 2 | 3; export interface AudioControl { audio_url?: string; text?: string; status: AudioStatus; } export interface AudioAction { guild_id: string; channel_id: string; audio_url: string; text: string; } export interface Thread { guild_id: string; channel_id: string; author_id: string; thread_info: ThreadInfo; } export interface ThreadInfo { thread_id: string; title: string; content: string; date_time: number; } export interface Post { guild_id: string; channel_id: string; author_id: string; post_info: PostInfo; } export interface PostInfo { thread_id: string; post_id: string; content: string; date_time: number; } export interface Reply { guild_id: string; channel_id: string; author_id: string; reply_info: ReplyInfo; } export interface ReplyInfo { thread_id: string; post_id: string; reply_id: string; content: string; date_time: number; } export type ApiPermissionDemand = { guild_id: string; channel_id: string; api_identify: ApiBaseInfo; title: string; desc: string; }; export type ApiBaseInfo = { path: string; method: "GET" | "POST" | "DELETE" | "PATCH" | "PUT"; }; export type RecommendInfo = { channel_id: string; introduce: string; }; export enum AuditType { Thread = 1, Post = 2, Reply = 3 } export const MAX_RETRY = 10; export class SessionManager extends EventEmitter { private bot; access_token: string; wsUrl: string; retry: number; alive?: boolean; heartbeatInterval: number; isReconnect: boolean; userClose: boolean; sessionRecord: { sessionID: string; seq: number; }; heartbeatParam: { op: OpCode; d: any; }; constructor(bot: QQBot); getAccessToken(): Promise; getWsUrl(): Promise; getValidIntends(): number; start(): Promise; stop(): Promise; private checkNeedToRestart; connect(): void; reconnectWs(): void; sendWs(msg: unknown): void; authWs(): void; startListen(): void; } export enum MusicPlatform { qq = "qq", netease = "163" } export interface Quotable { id?: string; event_id?: string; } export interface MessageElemMap { text: { text: string; }; at: { user_id: 'all' | string; }; face: { /** face为0~348,sface不明 */ id: number; /** 表情说明,接收消息时有效 */ text?: string; }; image: { /** * @type {string} 本地图片文件路径,例如"/tmp/1.jpg" * @type {string} base64协议数据,例如 "base64://*****" 或 "data:image/png;base64,iVBORw0KG * @type {string} 网络图片文件地址,例如"http://www.baidu.com/iconfont.png" * @type {Buffer} 图片Buffer数据 */ file: string | Buffer; url?: string; /** 仅接收有效 */ name?: string; }; video: { file: string; url?: string; /** 仅接收有效 */ name?: string; }; audio: { file: string; url?: string; /** 仅接收有效 */ name?: string; }; markdown: { content: string; custom_template_id: never; params: never; } | { custom_template_id: string; content: never; params: { key: string; values: string; }[]; }; keyboard: { id: string; }; reply: Quotable; link: { channel_id: string; }; button: { data: Dict; }; ark: { template_id: number; kv: Dict[]; }; embed: { title: string; prompt: string; htumbnail: Dict; fields: Dict[]; }; } export type MessageElemType = keyof MessageElemMap; export type MessageElem = { type: T; } & MessageElemMap[T]; export type TextElem = MessageElem<"text">; export type AtElem = MessageElem<"at">; export type FaceElem = MessageElem<"face">; export type ArkElem = MessageElem<'ark'>; export type EmbedElem = MessageElem<'embed'>; export type ImageElem = MessageElem<"image">; export type VideoElem = MessageElem<"video">; export type AudioElem = MessageElem<"audio">; export type LinkElem = MessageElem<'link'>; export type MDElem = MessageElem<'markdown'>; export type KeyboardElem = MessageElem<'keyboard'>; export type ButtonElem = MessageElem<'button'>; export type ReplyElem = MessageElem<"reply">; type RepeatableCombineElem = string | TextElem | FaceElem | LinkElem | AtElem | ButtonElem; type SingleWithRepeatEnd = [T, ...RepeatableCombineElem[]]; type SingleWithRepeat = [...RepeatableCombineElem[], T] | SingleWithRepeatEnd; type WithReply = T | [T] | SingleWithRepeat | [ReplyElem, ...SingleWithRepeat] | [ReplyElem, ...RepeatableCombineElem[]]; export type Sendable = RepeatableCombineElem | (RepeatableCombineElem)[] | WithReply; export class Message { bot: Bot; message_type: Message.Type; sub_type: Message.SubType; get self_id(): string; guild_id?: string; channel_id?: string; group_id?: string; id: string; message_id: string; sender: Message.Sender; user_id: string; constructor(bot: Bot, attrs: Dict); raw_message: string; source?: { message_id: string; id: string; }; message: Sendable; get [Symbol.unscopables](): { bot: boolean; }; toJSON(): { [k: string]: any; }; } export namespace Message { interface Sender { user_id: string; user_name: string; permissions: User.Permission[]; } type Type = 'private' | 'group' | 'guild'; type SubType = 'direct' | 'friend' | 'temp' | 'normal'; function parse(this: QQBot, payload: Dict): (string | MessageElem[])[]; } export interface MessageEvent { reply(message: Sendable, quote?: boolean): Promise; } export class PrivateMessageEvent extends Message implements MessageEvent { constructor(bot: Bot, sub_type: Message.SubType, payload: Partial); recall(): Promise; reply(message: Sendable): Promise; } export class GroupMessageEvent extends Message implements MessageEvent { group_id: string; group_name: string; constructor(bot: Bot, payload: Partial); reply(message: Sendable): Promise; } export class GuildMessageEvent extends Message implements MessageEvent { guild_id: string; guild_name: string; channel_id: string; channel_name: string; constructor(bot: Bot, payload: Partial); /** * 将该消息设置为公告 */ asAnnounce(): Promise; /** * 置顶消息 */ pin(): Promise; /** * 撤回消息 * @param hidetip {boolean} 是否隐藏提示 */ recall(hidetip?: boolean): Promise; /** * 回复消息 * @param message {Sendable} 回复内容 */ reply(message: Sendable): Promise; /** * 消息表态 * @param type {1|2} 表情类型 * @param id {`${number}`} 表态表情id */ reaction(type: FaceType, id: `${number}`): Promise; /** * 删除消息表态 * @param type {1|2} 表情类型 * @param id {`${number}`} 表态表情id */ deleteReaction(type: FaceType, id: `${number}`): Promise; /** * 获取表态用户列表 * @param type {1|2} 表情类型 * @param id {`${number}`} 表态表情id */ getReactionMembers(type: FaceType, id: `${number}`): Promise<{ user_id: string; user_name: string; avatar: string; }[]>; } export namespace MessageEvent { const parse: EventParser; } export class NoticeEvent { bot: Bot; notice_type: NoticeEvent.Type; sub_type: string; guild_id?: string; channel_id?: string; group_id?: string; operator_id?: string; constructor(bot: Bot, payload: Dict); } export namespace NoticeEvent { type Type = 'friend' | 'group' | 'direct' | 'channel' | 'forum' | 'guild'; } export class ActionNoticeEvent extends NoticeEvent { event_id: string; notice_id: string; data: ActionNoticeEvent.ActionData; private replied; constructor(bot: Bot, payload: Dict); /** * 回应操作 * @param code {0|1|2|3|4|5} 结果编码,释义见官网,默认0 */ reply(code?: ActionNoticeEvent.ReplyCode): Promise; } export class FriendActionNoticeEvent extends ActionNoticeEvent { operator_id: string; notice_type: 'friend'; constructor(bot: Bot, payload: Dict); } export class GroupActionNoticeEvent extends ActionNoticeEvent { group_id: string; operator_id: string; notice_type: 'group'; constructor(bot: Bot, payload: Dict); } export class GuildActionNoticeEvent extends ActionNoticeEvent { guild_id: string; channel_id: string; operator_id: string; notice_type: 'guild'; constructor(bot: Bot, payload: Dict); } export namespace ActionNoticeEvent { type ReplyCode = 0 | 1 | 2 | 3 | 4 | 5; type ActionData = { type: number; resolved: { button_data?: string; button_id: string; user_id?: string; feature_id?: string; message_id?: string; }; }; const parse: EventParser; } export class FriendReceiveNoticeEvent extends NoticeEvent { user_id: string; time: number; get actionText(): "开启" | "关闭"; constructor(bot: Bot, sub_type: 'receive_open' | 'receive_close', payload: Dict); } export namespace FriendReceiveNoticeEvent { const parse: EventParser; } export class FriendChangeNoticeEvent extends NoticeEvent { user_id: string; time: number; get actionText(): "新增" | "减少"; constructor(bot: Bot, sub_type: 'increase' | 'decrease', payload: Dict); } export namespace FriendChangeNoticeEvent { const parse: EventParser; } export class GroupReceiveNoticeEvent extends NoticeEvent { group_id: string; operator_id: string; time: number; get actionText(): "开启" | "关闭"; constructor(bot: Bot, sub_type: 'receive_open' | 'receive_close', payload: Dict); } export namespace GroupReceiveNoticeEvent { const parse: EventParser; } export class GroupChangeNoticeEvent extends NoticeEvent { group_id: string; operator_id: string; time: number; get actionText(): "新增" | "减少"; constructor(bot: Bot, sub_type: 'increase' | 'decrease', payload: Dict); } export namespace GroupChangeNoticeEvent { const parse: EventParser; } export class GuildChangeNoticeEvent extends NoticeEvent { guild_id: string; guild_name: string; operator_id: string; time: number; sub_type: 'increase' | 'update' | 'decrease'; get actionText(): "更新" | "新增" | "减少"; constructor(bot: Bot, sub_type: 'increase' | 'decrease' | 'update', payload: Dict); } export namespace GuildChangeNoticeEvent { const parse: EventParser; } export class ChannelChangeNoticeEvent extends NoticeEvent { guild_id: string; channel_id: string; channel_name: string; channel_type: number; operator_id: string; time: number; sub_type: ChannelChangeNoticeEvent.SubType; get actionText(): "更新" | "新增" | "减少" | "进入" | "离开"; constructor(bot: Bot, sub_type: ChannelChangeNoticeEvent.SubType, payload: Dict); } export namespace ChannelChangeNoticeEvent { type SubType = 'increase' | 'update' | 'decrease' | 'enter' | 'exit'; const parse: EventParser; } export class GuildMemberChangeNoticeEvent extends NoticeEvent { guild_id: string; operator_id: string; user_id: string; user_name: string; is_bot: boolean; time: number; sub_type: 'member.increase' | 'member.update' | 'member.decrease'; get actionText(): "加入" | "变更" | "退出"; constructor(bot: Bot, sub_type: 'member.increase' | 'member.decrease' | 'member.update', payload: Dict); } export namespace GuildMemberChangeNoticeEvent { const parse: EventParser; } export class ForumNoticeEvent extends NoticeEvent { guild_id: string; channel_id: string; author_id: string; sub_type: ForumNoticeEvent.SubType; constructor(bot: Bot, payload: Dict); } export namespace ForumNoticeEvent { type SubType = 'thread.create' | 'thread.delete' | 'thread.update' | 'post.create' | 'post.delete' | 'reply.create' | 'reply.delete' | 'audit'; const parse: EventParser; } export class ThreadChangeNoticeEvent extends ForumNoticeEvent { thread_id: string; title: string; content: string; time: number; get actionText(): "创建" | "删除" | "更新"; constructor(bot: Bot, sub_type: 'create' | 'update' | 'delete', payload: Dict); } export class PostChangeNoticeEvent extends ForumNoticeEvent { thread_id: string; post_id: string; content: string; time: number; get actionText(): "删除" | "发布"; constructor(bot: Bot, sub_type: 'create' | 'delete', payload: Dict); } export class ReplyChangeNoticeEvent extends ForumNoticeEvent { thread_id: string; post_id: string; reply_id: string; content: string; time: number; get actionText(): "创建" | "删除"; constructor(bot: Bot, sub_type: 'create' | 'delete', payload: Dict); } export class AuditNoticeEvent extends ForumNoticeEvent { thread_id: string; post_id: string; reply_id: string; type: AuditType; /** 审核结果: 0 成功 1 失败 */ result: 0 | 1; message?: string; get typeText(): "主题" | "帖子" | "回复"; constructor(bot: Bot, payload: Dict); } export enum QQEvent { DIRECT_MESSAGE_CREATE = "message.private.direct", AT_MESSAGE_CREATE = "message.guild", MESSAGE_CREATE = "message.guild", GUILD_CREATE = "notice.guild.increase", GUILD_UPDATE = "notice.guild.update", GUILD_DELETE = "notice.guild.decrease", CHANNEL_CREATE = "notice.channel.increase", CHANNEL_UPDATE = "notice.channel.update", CHANNEL_DELETE = "notice.channel.decrease", AUDIO_OR_LIVE_CHANNEL_MEMBER_ENTER = "notice.channel.enter", AUDIO_OR_LIVE_CHANNEL_MEMBER_EXIT = "notice.channel.exit", GUILD_MEMBER_ADD = "notice.guild.member.increase", GUILD_MEMBER_UPDATE = "notice.guild.member.update", GUILD_MEMBER_REMOVE = "notice.guild.member.decrease", GROUP_ADD_ROBOT = "notice.group.increase", GROUP_DEL_ROBOT = "notice.group.decrease", GROUP_MSG_REJECT = "notice.group.receive_close", GROUP_MSG_RECEIVE = "notice.group.receive_open", FRIEND_ADD = "notice.friend.increase", FRIEND_DEL = "notice.friend.decrease", C2C_MSG_REJECT = "notice.friend.receive_close", C2C_MSG_RECEIVE = "notice.friend.receive_open", INTERACTION_CREATE = "notice", C2C_MESSAGE_CREATE = "message.private.friend", GROUP_AT_MESSAGE_CREATE = "message.group", FORUM_THREAD_CREATE = "notice.forum.thread.create", FORUM_THREAD_UPDATE = "notice.forum.thread.update", FORUM_THREAD_DELETE = "notice.forum.thread.delete", FORUM_POST_CREATE = "notice.forum.post.create", FORUM_POST_DELETE = "notice.forum.post.delete", FORUM_REPLY_CREATE = "notice.forum.reply.create", FORUM_REPLY_DELETE = "notice.forum.reply.delete", FORUM_PUBLISH_AUDIT_RESULT = "notice.forum.audit", OPEN_FORUM_THREAD_CREATE = "notice.forum", OPEN_FORUM_THREAD_UPDATE = "notice.forum", OPEN_FORUM_THREAD_DELETE = "notice.forum", OPEN_FORUM_POST_CREATE = "notice.forum", OPEN_FORUM_POST_DELETE = "notice.forum", OPEN_FORUM_REPLY_CREATE = "notice.forum", OPEN_FORUM_REPLY_DELETE = "notice.forum" } export type EventParser = (this: Bot, event: T, payload: Dict) => Parameters[0]; export const EventParserMap: Map; export interface EventMap { 'message'(e: PrivateMessageEvent | GroupMessageEvent | GuildMessageEvent): void; 'message.group'(e: GroupMessageEvent): void; 'message.private.friend'(e: PrivateMessageEvent): void; 'message.private.direct'(e: PrivateMessageEvent): void; 'message.guild'(e: GuildMessageEvent): void; 'notice'(e: NoticeEvent): void; 'notice.friend'(e: FriendActionNoticeEvent | FriendChangeNoticeEvent | FriendReceiveNoticeEvent): void; 'notice.friend.action'(e: FriendActionNoticeEvent): void; 'notice.friend.increase'(e: FriendChangeNoticeEvent): void; 'notice.friend.decrease'(e: FriendChangeNoticeEvent): void; 'notice.friend.receive_close'(e: FriendReceiveNoticeEvent): void; 'notice.friend.receive_open'(e: FriendReceiveNoticeEvent): void; 'notice.group'(e: ActionNoticeEvent | GroupChangeNoticeEvent | GroupReceiveNoticeEvent): void; 'notice.group.increase'(e: GroupChangeNoticeEvent): void; 'notice.group.decrease'(e: GroupChangeNoticeEvent): void; 'notice.group.receive_close'(e: GroupReceiveNoticeEvent): void; 'notice.group.receive_open'(e: GroupReceiveNoticeEvent): void; 'notice.group.action'(e: GroupActionNoticeEvent): void; 'notice.guild'(e: ActionNoticeEvent | GuildChangeNoticeEvent | GuildMemberChangeNoticeEvent): void; 'notice.guild.action'(e: GuildActionNoticeEvent): void; 'notice.guild.increase'(e: GuildChangeNoticeEvent): void; 'notice.guild.update'(e: GuildChangeNoticeEvent): void; 'notice.guild.decrease'(e: GuildChangeNoticeEvent): void; 'notice.channel'(e: ChannelChangeNoticeEvent): void; 'notice.channel.enter'(e: ChannelChangeNoticeEvent): void; 'notice.channel.exit'(e: ChannelChangeNoticeEvent): void; 'notice.channel.increase'(e: ChannelChangeNoticeEvent): void; 'notice.channel.update'(e: ChannelChangeNoticeEvent): void; 'notice.channel.decrease'(e: ChannelChangeNoticeEvent): void; 'notice.guild.member'(e: GuildMemberChangeNoticeEvent): void; 'notice.guild.member.increase'(e: GuildMemberChangeNoticeEvent): void; 'notice.guild.member.update'(e: GuildMemberChangeNoticeEvent): void; 'notice.guild.member.decrease'(e: GuildMemberChangeNoticeEvent): void; 'notice.forum'(e: ThreadChangeNoticeEvent | AuditNoticeEvent | PostChangeNoticeEvent | ReplyChangeNoticeEvent | ForumNoticeEvent): void; 'notice.forum.thread'(e: ThreadChangeNoticeEvent): void; 'notice.forum.thread.create'(e: ThreadChangeNoticeEvent): void; 'notice.forum.thread.update'(e: ThreadChangeNoticeEvent): void; 'notice.forum.thread.delete'(e: ThreadChangeNoticeEvent): void; 'notice.forum.audit'(e: AuditNoticeEvent): void; 'notice.forum.post'(e: PostChangeNoticeEvent): void; 'notice.forum.post.create'(e: PostChangeNoticeEvent): void; 'notice.forum.post.delete'(e: PostChangeNoticeEvent): void; 'notice.forum.reply'(e: ReplyChangeNoticeEvent): void; 'notice.forum.reply.create'(e: ReplyChangeNoticeEvent): void; 'notice.forum.reply.delete'(e: ReplyChangeNoticeEvent): void; } export class QQBot extends EventEmitter { config: QQBot.Config; request: AxiosInstance; self_id: string; nickname: string; status: number; logger: log4js.Logger; ws: WebSocket; sessionManager: SessionManager; constructor(config: QQBot.Config); removeAt(payload: Dict): void; processPayload(event_id: string, event: string, payload: Dict): Dict | PrivateMessageEvent | GroupMessageEvent | GuildMessageEvent | NoticeEvent; dispatchEvent(event: string, wsRes: any): void; /** * 上传多媒体文件 * @param target_id 接受者id * @param target_type 接受者类型:user|group * @param file_data 文件数据:可以是本地文件(file://)或网络地址(http://)或base64或Buffer * @param file_type 数据类型:1 image;2 video; 3 audio * @returns */ uploadMedia(target_id: string, target_type: 'user' | 'group', file_data: string | Buffer, file_type: 1 | 2 | 3, decode?: boolean): Promise; em(event: string, payload: Dict): void; } export interface QQBot { on(event: T, callback: EventMap[T]): this; on(event: S & Exclude, callback: (...args: any[]) => void): this; once(event: T, callback: EventMap[T]): this; once(event: S & Exclude, callback: (...args: any[]) => void): this; off(event: T, callback?: EventMap[T]): this; off(event: S & Exclude, callback?: (...args: any[]) => void): this; emit(event: T, ...args: Parameters): boolean; emit(event: S & Exclude, ...args: any[]): boolean; addListener(event: T, callback: EventMap[T]): this; addListener(event: S & Exclude, callback: (...args: any[]) => void): this; addListenerOnce(event: T, callback: EventMap[T]): this; addListenerOnce(event: S & Exclude, callback: (...args: any[]) => void): this; removeListener(event: T, callback?: EventMap[T]): this; removeListener(event: S & Exclude, callback?: (...args: any[]) => void): this; removeAllListeners(event: T): this; removeAllListeners(event: S & Exclude): this; } export namespace QQBot { interface Token { access_token: string; expires_in: number; cache: string; } interface Config { appid: string; secret: string; sandbox?: boolean; timeout?: number; maxRetry?: number; dataDir?: string; /** * 是否移除第一个@ */ removeAt?: boolean; delay?: Dict; intents?: Intent[]; logLevel?: LogLevel; } function getFullTargetId(message: GuildMessageEvent | GroupMessageEvent | PrivateMessageEvent): string; } export class Sender { private bot; private baseUrl; private message; private source; brief: string; private isFile; private messagePayload; private buttons; private filePayload; contentType: string; constructor(bot: QQBot, baseUrl: string, message: Sendable, source?: Quotable); private getType; private parseFromTemplate; private fixGuildMediaData; processMessage(): Promise; sendMsg(): Promise; } export class Bot extends QQBot { constructor(config: Bot.Config); /** * 获取机器人信息 */ getSelfInfo(): Promise; /** * 获取频道角色权限信息 * @param channel_id 频道id * @param role_id 角色id */ getChannelPermissionOfRole(channel_id: string, role_id: string): Promise; /** * 设置频道公告 * @param guild_id * @param channel_id * @param message_id */ setChannelAnnounce(guild_id: string, channel_id: string, message_id: string): Promise; /** * 更新频道角色权限 * @param channel_id * @param role_id * @param permission */ updateChannelPermissionOfRole(channel_id: string, role_id: string, permission: UpdatePermissionParams): Promise; /** * 获取频道用户权限 * @param channel_id * @param member_id */ getChannelMemberPermission(channel_id: string, member_id: string): Promise; /** * 更新频道用户权限 * @param channel_id * @param member_id * @param permission */ updateChannelMemberPermission(channel_id: string, member_id: string, permission: UpdatePermissionParams): Promise; /** * 获取频道置顶消息id列表 * @param channel_id */ getChannelPins(channel_id: string): Promise; /** * 置顶频道消息 * @param channel_id * @param message_id */ pinChannelMessage(channel_id: string, message_id: string): Promise; /** * 取消置顶频道消息 * @param channel_id * @param message_id */ unPinChannelMessage(channel_id: string, message_id: string): Promise; /** * 创建子频道 * @param guild_id * @param channelInfo */ createChannel(guild_id: string, channelInfo: Omit): Promise; /** * 修改子频道 * @param channel_id * @param updateInfo */ updateChannel(channel_id: string, updateInfo: ChannelUpdateInfo): Promise; /** * 删除子频道 * @param channel_id */ deleteChannel(channel_id: string): Promise; /** * 获取频道角色列表 * @param guild_id */ getGuildRoles(guild_id: string): Promise; /** * 创建频道角色 * @param guild_id * @param role */ creatGuildRole(guild_id: string, role: RoleCreateParam): Promise; /** * 修改频道角色 * @param guild_id * @param role_id * @param updateInfo */ updateGuildRole(guild_id: string, role_id: string, updateInfo: RoleUpdateParam): Promise; /** * 删除频道角色 * @param role_id */ deleteGuildRole(role_id: string): Promise; /** * 获取频道可访问API类别 * @param guild_id */ getGuildAccessApis(guild_id: string): Promise; /** * 申请频道API * @param guild_id * @param channel_id * @param apiInfo * @param desc */ applyGuildAccess(guild_id: string, channel_id: string, apiInfo: ApiBaseInfo, desc?: string): Promise; /** * 取消频道禁言 * @param guild_id */ unMuteGuild(guild_id: string): Promise; /** * 频道禁言 * @param guild_id * @param seconds * @param end_time */ muteGuild(guild_id: string, seconds: number, end_time?: number): Promise; /** * 批量取消频道成员禁言 * @param guild_id * @param member_ids */ unMuteGuildMembers(guild_id: string, member_ids: string[]): Promise; /** * 批量禁言频道成员 * @param guild_id * @param member_ids * @param seconds * @param end_time */ muteGuildMembers(guild_id: string, member_ids: string[], seconds: number, end_time?: number): Promise; addGuildMemberRoles(guild_id: string, channel_id: string, member_id: string, role_id: string): Promise; /** * 移除频道成员角色 * @param guild_id * @param channel_id * @param member_id * @param role_id */ removeGuildMemberRoles(guild_id: string, channel_id: string, member_id: string, role_id: string): Promise; /** * 踢出频道成员 * @param guild_id * @param member_id * @param clean * @param blacklist */ kickGuildMember(guild_id: string, member_id: string, clean?: -1 | 0 | 3 | 7 | 15 | 30, blacklist?: boolean): Promise; /** * 取消频道成员禁言 * @param guild_id * @param member_id */ unMuteGuildMember(guild_id: string, member_id: string): Promise; /** * 禁言频道成员 * @param guild_id * @param member_id * @param seconds * @param end_time */ muteGuildMember(guild_id: string, member_id: string, seconds: number, end_time?: number): Promise; /** * 获取频道列表 */ getGuildList(): Promise; /** * 获取频道信息 * @param guild_id */ getGuildInfo(guild_id: string): Promise; /** * 获取子频道消息 * @param channel_id {string} 子频道id * @param message_id {string} 消息id */ getGuildMessage(channel_id: string, message_id: string): Promise; /** * 获取频道成员列表 * @param guild_id */ getGuildMemberList(guild_id: string): Promise; /** * 获取频道成员信息 * @param guild_id * @param member_id */ getGuildMemberInfo(guild_id: string, member_id: string): Promise; /** * 获取群成员列表 * @param group_id */ getGroupMemberList(group_id: string): Promise; /** * 获取群成员信息 * @param group_id * @param member_id */ getGroupMemberInfo(group_id: string, member_id: string): Promise; /** * 获取好友列表 */ getFriendList(): Promise; /** * 获取好友信息 * @param friend_id */ getFriendInfo(friend_id: string): Promise; /** * 发送私聊信息 * @param user_id * @param message * @param source */ sendPrivateMessage(user_id: string, message: Sendable, source?: Quotable): Promise; /** * 撤回私聊消息 * @param user_id * @param message_id */ recallPrivateMessage(user_id: string, message_id: string): Promise; /** * 发送群消息 * @param group_id * @param message * @param source */ sendGroupMessage(group_id: string, message: Sendable, source?: Quotable): Promise; /** * 撤回群消息 * @param group_id * @param message_id */ recallGroupMessage(group_id: string, message_id: string): Promise; /** * 获取子频道列表 */ getChannelList(guild_id: string): Promise; /** * 获取子频道信息 * @param channel_id */ getChannelInfo(channel_id: string): Promise; /** * 创建私信会话 * @param guild_id * @param user_id */ createDirectSession(guild_id: string, user_id: string): Promise; /** * 发送频道私信 * @param guild_id * @param message * @param source */ sendDirectMessage(guild_id: string, message: Sendable, source?: Quotable): Promise; /** * 获取频道私信 * @param guild_id * @param message_id */ getDirectMessage(guild_id: string, message_id: string): Promise; /** * 撤回频道私信 * @param guild_id * @param message_id * @param hidetip */ recallDirectMessage(guild_id: string, message_id: string, hidetip?: boolean): Promise; /** * 发送频道消息 * @param channel_id * @param message * @param source */ sendGuildMessage(channel_id: string, message: Sendable, source?: Quotable): Promise; /** * 撤回频道消息 * @param channel_id * @param message_id * @param hidetip */ recallGuildMessage(channel_id: string, message_id: string, hidetip?: boolean): Promise; /** * 对频道消息进行表态 * @param channel_id {string} 子频道id * @param message_id {string} 消息id * @param type {0|1} 表情类型 * @param id {`${number}`} 表情id */ reactionGuildMessage(channel_id: string, message_id: string, type: FaceType, id: `${number}`): Promise; /** * 删除频道消息表态 * @param channel_id {string} 子频道id * @param message_id {string} 消息id * @param type {0|1} 表情类型 * @param id {`${number}`} 表情id */ deleteGuildMessageReaction(channel_id: string, message_id: string, type: FaceType, id: `${number}`): Promise; /** * 获取表态用户列表 * @param channel_id {string} 子频道id * @param message_id {string} 消息id * @param type {0|1} 表情类型 * @param id {`${number}`} 表情id */ getGuildMessageReactionMembers(channel_id: string, message_id: string, type: FaceType, id: `${number}`): Promise<{ user_id: string; user_name: string; avatar: string; }[]>; /** 获取频道日程 * @param channel_id {string} * @param since {number} */ getChannelSchedules(channel_id: string, since?: number): Promise; /** * 获取日程详情 * @param channel_id * @param schedule_id */ getChannelScheduleInfo(channel_id: string, schedule_id: string): Promise; /** * 创建日程 * @param channel_id * @param schedule */ createChannelSchedule(channel_id: string, schedule: Exclude): Promise; /** * 修改日程 * @param channel_id * @param schedule_id * @param schedule */ updateChannelSchedule(channel_id: string, schedule_id: string, schedule: Exclude): Promise; /** * 删除日程 * @param channel_id * @param schedule_id */ deleteChannelSchedule(channel_id: string, schedule_id: string): Promise; /** * 音频控制 * @param channel_id * @param audio_control */ controlChannelAudio(channel_id: string, audio_control: AudioControl): Promise; /** * 上麦 * @param channel_id */ setOnlineMic(channel_id: string): Promise; /** * 下麦 * @param channel_id */ setOfflineMic(channel_id: string): Promise; /** * 获取频道帖子列表 * @param channel_id */ getChannelThreads(channel_id: string): Promise; /** * 获取频道帖子详情 * @param channel_id * @param thread_id */ getChannelThreadInfo(channel_id: string, thread_id: string): Promise; /** * 创建频道帖子 * @param channel_id * @param title * @param content * @param format {1|2|3|4} */ publishThread(channel_id: string, title: string, content: string, format?: 1 | 2 | 3 | 4): Promise; /** * 删除频道帖子 * @param channel_id * @param thread_id */ deleteThread(channel_id: string, thread_id: string): Promise; /** * 回应操作 * @param action_id {string} 操作id * @param code {number} */ replyAction(action_id: string, code?: ActionNoticeEvent.ReplyCode): Promise; start(): Promise; stop(): Promise; } export namespace Bot { interface Info { id: string; username: string; avatar: string; union_openid?: string; union_user_account?: string; } interface Config extends QQBot.Config { } } export function defineConfig(config: Bot.Config): Bot.Config; export function createBot(config: Bot.Config): Bot; export class Contactable { bot: Bot; guild_id?: string; channel_id?: string; group_id?: string; user_id?: string; constructor(bot: Bot); } export namespace Friend { interface Info { id: string; user: User.Info; name: string; } } export namespace Group { interface Info { id: string; name: string; } } export namespace GroupMember { interface Info { user: User.Info; group_id: string; } }