Skip to content

Commit

Permalink
fix: 我也不想水啊...但是他没pr?
Browse files Browse the repository at this point in the history
  • Loading branch information
sj817 committed Oct 7, 2024
1 parent 5cf930e commit 88d4d5b
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 561 deletions.
4 changes: 1 addition & 3 deletions src/adapter/input/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { KarinAdapter, KarinMessage, Contact, KarinElement, LoggerLevel, Message

const { enable, msgToFile, token: oldToken, ip } = config.Config.AdapterInput

/**
* 标准输入输出适配器
*/
/** 标准输入输出适配器 */
export class AdapterInput implements KarinAdapter {
token: string
socket!: WebSocket
Expand Down
12 changes: 3 additions & 9 deletions src/adapter/onebot/11/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export class OB11Event {
}
}

/**
* 元事件
*/
/** 元事件 */
metaEvent (data: OB11MetaEvent) {
if (data.meta_event_type === 'heartbeat') {
this.adapter.logger('trace', `[心跳]:${JSON.stringify(data.status)}`)
Expand All @@ -49,9 +47,7 @@ export class OB11Event {
}
}

/**
* 消息事件
*/
/** 消息事件 */
messageEvent (data: OB11MessageEvent) {
const message = {
event: EventType.Message as EventType.Message,
Expand Down Expand Up @@ -86,9 +82,7 @@ export class OB11Event {
karin.emit('adapter.message', e)
}

/**
* 通知事件
*/
/** 通知事件 */
noticeEvent (data: OB11NoticeEvent) {
const time = data.time
const selfId = data.self_id + ''
Expand Down
76 changes: 19 additions & 57 deletions src/adapter/onebot/11/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export class AdapterOneBot11 implements KarinAdapter {
this.version = { name: '', app_name: '', version: '' }
}

/**
* 反向ws初始化
*/
/** 反向ws初始化 */
async server (socket: WebSocket, request: IncomingMessage) {
this.socket = socket

Expand Down Expand Up @@ -124,9 +122,7 @@ export class AdapterOneBot11 implements KarinAdapter {
return this.account.uid || this.account.uin
}

/**
* 获取当前登录号信息
*/
/** 获取当前登录号信息 */
async getSelf () {
const data = await this.GetCurrentAccount()
try {
Expand Down Expand Up @@ -167,9 +163,7 @@ export class AdapterOneBot11 implements KarinAdapter {
return KarinConvertAdapter(data, this)
}

/**
* 专属当前Bot的日志打印方法
*/
/** 专属当前Bot的日志打印方法 */
logger (level: LoggerLevel, ...args: any[]) {
logger.bot(level, this.account.uid || this.account.uin, ...args)
}
Expand Down Expand Up @@ -511,9 +505,7 @@ export class AdapterOneBot11 implements KarinAdapter {
}
}

/**
* 获取登录号信息
*/
/** 获取登录号信息 */
async GetCurrentAccount (): Promise<{
account_uid: string
account_uin: string
Expand Down Expand Up @@ -567,34 +559,22 @@ export class AdapterOneBot11 implements KarinAdapter {
*/
sex: res.sex,
ext: {
/**
* 大会员
*/
/** 大会员 */
big_vip: undefined,
/**
* 好莱坞/腾讯视频会员
*/
/** 好莱坞/腾讯视频会员 */
hollywood_vip: undefined,
/**
* QQ会员
*/
/** QQ会员 */
qq_vip: undefined,
/**
* QQ超级会员
*/
/** QQ超级会员 */
super_vip: undefined,
/**
* 是否已经赞过
*/
/** 是否已经赞过 */
voted: undefined,
},
},
]
}

/**
* 获取好友列表
*/
/** 获取好友列表 */
async GetFriendList () {
const friendList = await this.SendApi(OB11Api.getFriendList)
return friendList.map(v => {
Expand Down Expand Up @@ -631,25 +611,15 @@ export class AdapterOneBot11 implements KarinAdapter {
*/
sex: v.sex,
ext: {
/**
* 大会员
*/
/** 大会员 */
big_vip: undefined,
/**
* 好莱坞/腾讯视频会员
*/
/** 好莱坞/腾讯视频会员 */
hollywood_vip: undefined,
/**
* QQ会员
*/
/** QQ会员 */
qq_vip: undefined,
/**
* QQ超级会员
*/
/** QQ超级会员 */
super_vip: undefined,
/**
* 是否已经赞过
*/
/** 是否已经赞过 */
voted: undefined,
},
}
Expand Down Expand Up @@ -678,9 +648,7 @@ export class AdapterOneBot11 implements KarinAdapter {
}
}

/**
* 获取群列表
*/
/** 获取群列表 */
async GetGroupList () {
const groupList = await this.SendApi(OB11Api.getGroupList)
return groupList.map(v => {
Expand Down Expand Up @@ -758,9 +726,7 @@ export class AdapterOneBot11 implements KarinAdapter {
})
}

/**
* 获取群荣誉信息
*/
/** 获取群荣誉信息 */
async GetGroupHonor (groupId: string, refresh = false) {
const groupHonor = await this.SendApi(OB11Api.getGroupHonorInfo, { group_id: Number(groupId), type: 'all' })

Expand Down Expand Up @@ -843,9 +809,7 @@ export class AdapterOneBot11 implements KarinAdapter {
}
}

/**
* 获取版本信息
*/
/** 获取版本信息 */
async GetVersion () {
const res = await this.SendApi(OB11Api.getVersionInfo)
return {
Expand All @@ -860,9 +824,7 @@ export class AdapterOneBot11 implements KarinAdapter {
throw new Error('Method not implemented.')
}

/**
* 精华消息
*/
/** 精华消息 */
async GetEssenceMessageList (groupId: string, page: number, pageSize: number) {
const list: EssenceMessageBody[] = []
const res = await this.SendApi(OB11Api.getEssenceMsgList, { group_id: Number(groupId) })
Expand Down
20 changes: 5 additions & 15 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ export class KarinCli {
})
}

/**
* pm2重启
*/
/** pm2重启 */
async restart () {
const pm2Cfg = this.getConfigData('pm2')
const serverCfg = this.getConfigData('server')
Expand All @@ -145,9 +143,7 @@ export class KarinCli {
process.exit(0)
}

/**
* pm2启动
*/
/** pm2启动 */
async pm2 () {
console.log('pm2启动中...')
const filePath = this.getConfigPath('pm2')
Expand All @@ -169,9 +165,7 @@ export class KarinCli {
process.exit(0)
}

/**
* pm2结束进程
*/
/** pm2结束进程 */
async stop () {
console.log('pm2服务停止中...')
const pm2Cfg = this.getConfigData('pm2')
Expand All @@ -188,9 +182,7 @@ export class KarinCli {
process.exit(0)
}

/**
* pm2查看日志
*/
/** pm2查看日志 */
async log () {
const pm2Cfg = this.getConfigData('pm2')
const serverCfg = this.getConfigData('server')
Expand All @@ -204,9 +196,7 @@ export class KarinCli {
spawn(cmd, ['logs', type, '--lines', lines], { stdio: 'inherit', shell: true, cwd: process.cwd() })
}

/**
* 更新依赖
*/
/** 更新依赖 */
async update () {
const list = await getNpmPlugins(false)
list.push('node-karin')
Expand Down
24 changes: 6 additions & 18 deletions src/core/listener/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
type AdapterType = KarinAdapter['adapter']['type']
type onAdapter = { type: AdapterType; adapter: new () => KarinAdapter; path?: string }

/**
* 产生事件映射
*/
/** 产生事件映射 */
export interface EmittEventMap {
'karin:count:send': number
'karin:count:fnc': string
Expand All @@ -41,9 +39,7 @@ type ContextEvents = {
[K in `ctx:${string}`]: (e: KarinMessage) => void
}

/**
* 监听事件映射
*/
/** 监听事件映射 */
export interface OnEventMap extends ContextEvents {
'karin:count:send': (count: number) => void
'karin:count:fnc': (fnc: string) => void
Expand All @@ -60,9 +56,7 @@ export interface OnEventMap extends ContextEvents {
'restart.http': undefined
}

/**
* 监听器实例
*/
/** 监听器实例 */
export class Listeners extends EventEmitter {
/** 框架名称 */
name: string
Expand Down Expand Up @@ -102,9 +96,7 @@ export class Listeners extends EventEmitter {
return super.emit(event, ...args)
}

/**
* 注册Bot 返回索引id
*/
/** 注册Bot 返回索引id */
addBot (data: { bot: KarinAdapter; type: AdapterType }): number | false {
this.#index++
const index = this.#index
Expand Down Expand Up @@ -150,9 +142,7 @@ export class Listeners extends EventEmitter {
return index
}

/**
* 发送上线通知
*/
/** 发送上线通知 */
async #online (uid: string) {
/** 重启 */
const key = `karin:restart:${uid}`
Expand Down Expand Up @@ -218,9 +208,7 @@ export class Listeners extends EventEmitter {
return this.list[index].bot
}

/**
* 获取当前已注册Bot数量
*/
/** 获取当前已注册Bot数量 */
getBotCount (): number {
return this.list.length
}
Expand Down
20 changes: 5 additions & 15 deletions src/core/plugin/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ class PluginLoader {
this.dependErr = {}
}

/**
* 插件初始化
*/
/** 插件初始化 */
async load () {
karin.once('plugin.watch', () => {
this.watchList.forEach(async ({ plugin, path }) => {
Expand All @@ -138,9 +136,7 @@ class PluginLoader {
return this
}

/**
* 获取Git插件
*/
/** 获取Git插件 */
async getGitPlugin () {
/** 获取所有插件包 */
const plugins = common.getPlugins()
Expand Down Expand Up @@ -258,9 +254,7 @@ class PluginLoader {
return list
}

/**
* 获取Npm插件
*/
/** 获取Npm插件 */
async getNpmPlugin () {
const list: Promise<boolean>[] = []
const info = await common.getNpmPlugins(true)
Expand Down Expand Up @@ -625,9 +619,7 @@ class PluginLoader {
}
}

/**
* 打印依赖缺失
*/
/** 打印依赖缺失 */
printDependErr () {
try {
const keys = Object.keys(this.dependErr)
Expand Down Expand Up @@ -753,7 +745,5 @@ class PluginLoader {
}
}

/**
* 加载插件
*/
/** 加载插件 */
export const pluginLoader = new PluginLoader()
Loading

0 comments on commit 88d4d5b

Please sign in to comment.