diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 9895a0a..f590272 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -3,11 +3,12 @@ module.exports = { es2021: true, node: true }, - extends: ['standard'], + extends: ['standard', 'plugin:jsdoc/recommended'], parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, + plugins: ['import', 'n', 'promise', 'jsdoc'], globals: { Bot: true, redis: true, @@ -21,7 +22,11 @@ module.exports = { 'arrow-body-style': 'off', 'camelcase': 'off', 'quote-props': ['error', 'consistent'], - 'no-eval': ['error', { 'allowIndirect': true }] + 'no-eval': ['error', { allowIndirect: true }], + 'jsdoc/require-returns': 0, + 'jsdoc/require-param-description': 0, + 'jsdoc/require-returns-description': 0, + 'jsdoc/require-param-type': 0 }, ignorePatterns: ['resources/state/echarts.min.js'] } diff --git a/.husky/pre-commit b/.husky/pre-commit index dd77bab..ec86e0c 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,3 +1,5 @@ +#!/bin/sh + echo "-----------代码正在eslint格式化-----------" pnpm run lint diff --git a/apps/admin.js b/apps/admin.js index 140db0d..172eaea 100644 --- a/apps/admin.js +++ b/apps/admin.js @@ -230,7 +230,6 @@ const getStatus = function (rote, alone) { /** * 检查一个数值是否满足给定的限制条件,并返回经过验证的数值。 - * * @param {number} value - 要检查的数值。 * @param {string} limit - 要检查的限制条件。 * 限制条件可以是以下格式之一: diff --git a/apps/assistant.js b/apps/assistant.js index 3b54dbb..72f44b5 100644 --- a/apps/assistant.js +++ b/apps/assistant.js @@ -138,7 +138,10 @@ export class Assistant extends plugin { return this.e.bot ?? Bot } - /** 改头像 */ + /** + * 改头像 + * @param e + */ async SetAvatar (e) { if (!common.checkPermission(e, 'master')) return if (!e.img) { @@ -177,7 +180,10 @@ export class Assistant extends plugin { this.finish('_avatarContext') } - /** 改昵称 */ + /** + * 改昵称 + * @param e + */ async SetNickname (e) { if (!common.checkPermission(e, 'master')) return let name = e.msg.replace(/#|改昵称/g, '').trim() @@ -190,7 +196,10 @@ export class Assistant extends plugin { }) } - /** 改群名片 */ + /** + * 改群名片 + * @param e + */ async SetGroupCard (e) { if (!common.checkPermission(e, 'master')) return let group = '' @@ -222,7 +231,10 @@ export class Assistant extends plugin { }) } - /** 改群头像 */ + /** + * 改群头像 + * @param e + */ async SetGroupAvatar (e) { if (e.isPrivate) { if (!e.isMaster) return logger.mark(`${e.logFnc}不为主人`) @@ -277,7 +289,10 @@ export class Assistant extends plugin { this.finish('_GroupAvatarContext') } - /** 改群昵称 */ + /** + * 改群昵称 + * @param e + */ async SetGroupName (e) { if (!common.checkPermission(e, 'admin', 'admin')) return let group = '' @@ -314,7 +329,10 @@ export class Assistant extends plugin { } } - /** 改签名 */ + /** + * 改签名 + * @param e + */ async SetSignature (e) { if (!common.checkPermission(e, 'master')) return let signs = e.msg.replace(/#|改签名/g, '').trim() @@ -326,7 +344,10 @@ export class Assistant extends plugin { }) } - /** 改状态 */ + /** + * 改状态 + * @param e + */ async SetOnlineStatus (e) { if (!common.checkPermission(e, 'master')) return let signs = e.msg.replace(/#|改状态/g, '').trim() @@ -345,7 +366,10 @@ export class Assistant extends plugin { return true } - /** 发好友 */ + /** + * 发好友 + * @param e + */ async SendFriendMsg (e) { if (!common.checkPermission(e, 'master')) return let regRet = FriendsReg.exec(e.msg) @@ -364,7 +388,10 @@ export class Assistant extends plugin { .catch(err => common.handleException(e, err, { MsgTemplate: '❎ 发送失败\n错误信息为:{error}' })) } - /** 发群聊 */ + /** + * 发群聊 + * @param e + */ async SendGroupMsg (e) { if (!common.checkPermission(e, 'master')) return let regRet = GroupMsgReg.exec(e.msg) @@ -437,7 +464,10 @@ export class Assistant extends plugin { return false } - /** 退群 */ + /** + * 退群 + * @param e + */ async QuitGroup (e) { if (!common.checkPermission(e, 'master')) return let quits = e.msg.replace(/#|退群/g, '').trim() @@ -461,7 +491,10 @@ export class Assistant extends plugin { }) } - /** 删好友 */ + /** + * 删好友 + * @param e + */ async DeleteFriend (e) { if (!common.checkPermission(e, 'master')) return let quits = e.msg.replace(/#|删好友/g, '').trim() @@ -483,7 +516,10 @@ export class Assistant extends plugin { }) } - /** 改性别 */ + /** + * 改性别 + * @param e + */ async SetGender (e) { if (!common.checkPermission(e, 'master')) return let sex = e.msg.replace(/#|改性别/g, '').trim() @@ -505,7 +541,10 @@ export class Assistant extends plugin { }) } - /** 取直链 */ + /** + * 取直链 + * @param e + */ async ImageLink (e) { let img = [] if (e.source) { @@ -559,7 +598,10 @@ export class Assistant extends plugin { this.finish('_ImageLinkContext') } - /** 取Face表情 */ + /** + * 取Face表情 + * @param e + */ async Face (e) { let face = [] for (let m of e.message) { @@ -587,7 +629,10 @@ export class Assistant extends plugin { } } - /** QQ空间 说说列表 */ + /** + * QQ空间 说说列表 + * @param e + */ async Qzonelist (e) { if (!common.checkPermission(e, 'master')) return let page = e.msg.replace(/#|获?取说说列表/g, '').trim() @@ -613,7 +658,10 @@ export class Assistant extends plugin { e.reply(msg) } - /** 删除说说 */ + /** + * 删除说说 + * @param e + */ async Qzonedel (e) { if (!common.checkPermission(e, 'master')) return let pos = e.msg.match(/\d+/) @@ -636,7 +684,10 @@ export class Assistant extends plugin { e.reply(`✅ 删除说说成功:\n ${pos}.${_.truncate(domain.content, { length: 15 })} \n - [${domain.secret ? '私密' : '公开'}] | ${moment(domain.created_time * 1000).format('MM/DD HH:mm')} | ${domain.commentlist?.length || 0} 条评论`) } - /** 发说说 */ + /** + * 发说说 + * @param e + */ async Qzonesay (e) { if (!common.checkPermission(e, 'master')) return let con = e.msg.replace(/#|发说说/g, '').trim() @@ -653,7 +704,10 @@ export class Assistant extends plugin { e.reply(msg) } - /** 清空说说和留言 */ + /** + * 清空说说和留言 + * @param e + */ async QzonedelAll (e) { if (!common.checkPermission(e, 'master')) return if (/清空说说/.test(e.msg)) { @@ -784,7 +838,10 @@ export class Assistant extends plugin { e.reply(res.msg) } - /** 开关戳一戳 */ + /** + * 开关戳一戳 + * @param e + */ async Cyc (e) { if (!common.checkPermission(e, 'master')) return let result = await new QQApi(e).setcyc(/开启/.test(e.msg) ? 0 : 1) diff --git a/apps/bika.js b/apps/bika.js index 18b0900..8e84497 100644 --- a/apps/bika.js +++ b/apps/bika.js @@ -56,7 +56,10 @@ export class NewBika extends plugin { }) } - /** 搜索 */ + /** + * 搜索 + * @param e + */ async search (e) { if (!await this._Authentication(e)) return e.reply(Pixiv.startMsg) @@ -67,7 +70,10 @@ export class NewBika extends plugin { .catch(err => common.handleException(e, err)) } - /** 漫画页面 */ + /** + * 漫画页面 + * @param e + */ async comicPage (e) { if (!await this._Authentication(e)) return e.reply(Pixiv.startMsg) @@ -79,7 +85,10 @@ export class NewBika extends plugin { .catch(err => common.handleException(e, err)) } - /** 快速查看 */ + /** + * 快速查看 + * @param e + */ async viewComicPage (e) { if (!await this._Authentication(e)) return let number = e.msg.match(/\d+/) - 1 @@ -88,7 +97,10 @@ export class NewBika extends plugin { .catch(err => common.handleException(e, err)) } - /** 下一页 */ + /** + * 下一页 + * @param e + */ async nextComicPage (e) { if (!await this._Authentication(e)) return await Bika.next() @@ -96,7 +108,10 @@ export class NewBika extends plugin { .catch(err => common.handleException(e, err)) } - /** 下一话 */ + /** + * 下一话 + * @param e + */ async nextChapter (e) { if (!await this._Authentication(e)) return await Bika.next('chapter') @@ -104,7 +119,10 @@ export class NewBika extends plugin { .catch(err => common.handleException(e, err)) } - /** 类别列表 */ + /** + * 类别列表 + * @param e + */ async categories (e) { if (!await this._Authentication(e)) return e.reply(Pixiv.startMsg) @@ -113,7 +131,10 @@ export class NewBika extends plugin { .catch(err => common.handleException(e, err)) } - /** 漫画细节 */ + /** + * 漫画细节 + * @param e + */ async comicDetail (e) { if (!await this._Authentication(e)) return e.reply(Pixiv.startMsg) @@ -123,7 +144,10 @@ export class NewBika extends plugin { .catch(err => common.handleException(e, err)) } - /** 图片质量 */ + /** + * 图片质量 + * @param e + */ async imageQuality (e) { let quality = e.msg.match(new RegExp(`#?${Prefix}修改图片质量(.*)`))[2] let imageQualityType = { @@ -138,7 +162,10 @@ export class NewBika extends plugin { new Admin().SeSe_Settings(e) } - /** 图片直连 */ + /** + * 图片直连 + * @param e + */ async directConnection (e) { if (!this.e.isMaster) { return true } let now = Config.bika.bikaDirectConnection diff --git a/apps/events/message.js b/apps/events/message.js index 2ec62a1..1cd8173 100644 --- a/apps/events/message.js +++ b/apps/events/message.js @@ -174,6 +174,10 @@ Bot.on?.('message', async (e) => { if (forwardMsg) await common.sendMasterMsg(forwardMsg) }) // 特殊消息处理 +/** + * + * @param msg + */ function getMsgType (msg) { const msgType = { record: { diff --git a/apps/events/notice_friend.js b/apps/events/notice_friend.js index 25cf2dc..6b7492d 100644 --- a/apps/events/notice_friend.js +++ b/apps/events/notice_friend.js @@ -91,7 +91,10 @@ Bot.on?.('notice.friend', async (e) => { } ) -/** 时间转换 */ +/** + * 时间转换 + * @param time + */ function formatDate (time) { let now = new Date(parseFloat(time) * 1000) // 月 diff --git a/apps/groupAdmin/groupAdmin.js b/apps/groupAdmin/groupAdmin.js index 52db0b8..0362c00 100644 --- a/apps/groupAdmin/groupAdmin.js +++ b/apps/groupAdmin/groupAdmin.js @@ -160,7 +160,10 @@ export class GroupAdmin extends plugin { return this.e.bot ?? Bot } - /** 禁言 */ + /** + * 禁言 + * @param e + */ async muteMember (e) { if (!common.checkPermission(e, 'admin', 'admin')) { return true } let qq = e.message.find(item => item.type == 'at')?.qq @@ -173,7 +176,10 @@ export class GroupAdmin extends plugin { .catch(err => common.handleException(e, err)) } - /** 解禁 */ + /** + * 解禁 + * @param e + */ async noMuteMember (e) { if (!common.checkPermission(e, 'admin', 'admin')) { return true } let qq = e.message.find(item => item.type == 'at')?.qq @@ -184,7 +190,10 @@ export class GroupAdmin extends plugin { .catch(err => common.handleException(e, err)) } - /** 全体禁言 */ + /** + * 全体禁言 + * @param e + */ async muteAll (e) { if (!common.checkPermission(e, 'admin', 'admin')) { return true } let type = /全体禁言/.test(e.msg) @@ -548,7 +557,10 @@ export class GroupAdmin extends plugin { ]) } - /** 群星级 */ + /** + * 群星级 + * @param e + */ async Group_xj (e) { let screenshot = await puppeteer.Webpage({ url: `https://qqweb.qq.com/m/business/qunlevel/index.html?gc=${e.group_id}&from=0&_wv=1027`, @@ -683,7 +695,10 @@ export class GroupAdmin extends plugin { ) } - /** 开启或关闭加群通知 */ + /** + * 开启或关闭加群通知 + * @param e + */ async handleGroupAdd (e) { if (!common.checkPermission(e, 'admin', 'admin')) return let type = /开启/.test(e.msg) ? 'add' : 'del' @@ -694,7 +709,10 @@ export class GroupAdmin extends plugin { e.reply(`✅ 已${type == 'add' ? '开启' : '关闭'}「${e.group_id}」的加群申请通知`) } - /** 加精 */ + /** + * 加精 + * @param e + */ async essenceMessage (e) { if (!common.checkPermission(e, 'admin', 'admin')) return if (!e.source) return e.reply('请对要加精的消息进行引用') diff --git a/apps/groupAdmin/groupBannedWords.js b/apps/groupAdmin/groupBannedWords.js index e535bbf..b85fe7b 100644 --- a/apps/groupAdmin/groupBannedWords.js +++ b/apps/groupAdmin/groupBannedWords.js @@ -103,7 +103,10 @@ export class NewGroupBannedWords extends plugin { } } - /** 禁言 */ + /** + * 禁言 + * @param time + */ #mute (time) { const e = this.e if (e.anonymous) { @@ -113,7 +116,10 @@ export class NewGroupBannedWords extends plugin { } } - /** 过滤别名 */ + /** + * 过滤别名 + * @param msg + */ #trimAlias (msg) { let groupCfg = this.e.runtime.cfg.getGroup(this.group_id) let alias = groupCfg.botAlias diff --git a/apps/groupAdmin/groupVerify.js b/apps/groupAdmin/groupVerify.js index 4a75816..1a6fa57 100644 --- a/apps/groupAdmin/groupVerify.js +++ b/apps/groupAdmin/groupVerify.js @@ -201,6 +201,12 @@ Bot.on?.('notice.group.decrease', async (e) => { }) // 发送验证信息 +/** + * + * @param user_id + * @param group_id + * @param e + */ async function verify (user_id, group_id, e) { if (!e.group.is_admin && !e.group.is_owner) return user_id = Number(user_id) diff --git a/apps/handle.js b/apps/handle.js index 2081572..a14b22f 100644 --- a/apps/handle.js +++ b/apps/handle.js @@ -49,7 +49,10 @@ export class NewHandle extends plugin { }) } - /** 同意拒绝好友申请 */ + /** + * 同意拒绝好友申请 + * @param e + */ async PrivateAdd (e) { if (!e.isMaster) return false let yes = !!/同意/.test(e.msg) @@ -117,7 +120,10 @@ export class NewHandle extends plugin { } } - /** 引用同意好友申请和群邀请 */ + /** + * 引用同意好友申请和群邀请 + * @param e + */ async Handle (e) { if (!e.source) return false if (e.source.user_id != (e.bot ?? Bot).uin) return false diff --git a/apps/help.js b/apps/help.js index 81866f0..8c6da12 100644 --- a/apps/help.js +++ b/apps/help.js @@ -30,6 +30,10 @@ export class YenaiHelp extends plugin { } } +/** + * + * @param e + */ async function help (e) { let custom = {} // let help = {} diff --git a/apps/pixiv.js b/apps/pixiv.js index 04f81be..56e282a 100644 --- a/apps/pixiv.js +++ b/apps/pixiv.js @@ -112,7 +112,10 @@ export class NewPixiv extends plugin { .catch(err => common.handleException(e, err)) } - /** 关键词搜图 */ + /** + * 关键词搜图 + * @param e + */ async searchTags (e) { let regRet = tagReg.exec(e.msg) if (!await this._Authentication(e, 'sese')) return @@ -126,7 +129,10 @@ export class NewPixiv extends plugin { .catch(err => common.handleException(e, err)) } - /** 获取热门tag */ + /** + * 获取热门tag + * @param e + */ async popularTags (e) { if (!await this._Authentication(e, 'sese')) return e.reply(Pixiv.startMsg) @@ -135,7 +141,10 @@ export class NewPixiv extends plugin { .catch(err => common.handleException(e, err)) } - /** 以uid搜图**/ + /** + * 以uid搜图 + * @param e + */ async searchUid (e) { if (!await this._Authentication(e, 'sese')) return @@ -189,7 +198,10 @@ export class NewPixiv extends plugin { .catch(err => common.handleException(e, err)) } - /** 搜索用户 */ + /** + * 搜索用户 + * @param e + */ async searchUser (e) { if (!await this._Authentication(e, 'sese')) return @@ -201,7 +213,10 @@ export class NewPixiv extends plugin { .catch(err => common.handleException(e, err)) } - /** 推荐作品 */ + /** + * 推荐作品 + * @param e + */ async illustRecommended (e) { if (!await this._Authentication(e, 'sese')) return e.reply(Pixiv.startMsg) @@ -228,14 +243,20 @@ export class NewPixiv extends plugin { new Admin().SeSe_Settings(e) } - /** 图片直连 */ + /** + * 图片直连 + * @param e + */ async directConnection (e) { let isSwitch = /开启/.test(e.msg) Config.modify('pixiv', 'pixivDirectConnection', isSwitch) new Admin().SeSe_Settings(e) } - /** 登录信息 */ + /** + * 登录信息 + * @param e + */ async loginInfo (e) { await Pixiv.loginInfo() .then(res => e.reply(res)) diff --git a/apps/update.js b/apps/update.js index 5828111..3f6edc0 100644 --- a/apps/update.js +++ b/apps/update.js @@ -30,7 +30,7 @@ export class Update extends plugin { /** * rule - 更新椰奶插件 - * @returns + * @param e */ async update (e) { if (!common.checkPermission(e, 'master')) return true @@ -63,7 +63,6 @@ export class Update extends plugin { /** * 椰奶插件更新函数 * @param {boolean} isForce 是否为强制更新 - * @returns */ async runUpdate (isForce) { const _path = './plugins/yenai-plugin/' @@ -107,7 +106,6 @@ export class Update extends plugin { /** * 获取椰奶插件的更新日志 * @param {string} plugin 插件名称 - * @returns */ async getLog (plugin = '') { let cm = `cd ./plugins/${plugin}/ && git log -20 --oneline --pretty=format:"%h||[%cd] %s" --date=format:"%m-%d %H:%M"` @@ -152,7 +150,6 @@ export class Update extends plugin { /** * 获取上次提交的commitId * @param {string} plugin 插件名称 - * @returns */ async getcommitId (plugin = '') { let cm = `git -C ./plugins/${plugin}/ rev-parse --short HEAD` @@ -166,7 +163,6 @@ export class Update extends plugin { /** * 获取本次更新插件的最后一次提交时间 * @param {string} plugin 插件名称 - * @returns */ async getTime (plugin = '') { let cm = `cd ./plugins/${plugin}/ && git log -1 --oneline --pretty=format:"%cd" --date=format:"%m-%d %H:%M"` @@ -186,7 +182,6 @@ export class Update extends plugin { * 处理更新失败的相关函数 * @param {string} err * @param {string} stdout - * @returns */ async gitErr (err, stdout) { let msg = '更新失败!' @@ -230,7 +225,6 @@ export class Update extends plugin { /** * 异步执行git相关命令 * @param {string} cmd git命令 - * @returns */ async execSync (cmd) { return new Promise((resolve, reject) => { @@ -242,7 +236,6 @@ export class Update extends plugin { /** * 检查git是否安装 - * @returns */ async checkGit () { let ret = await execSync('git --version', { encoding: 'utf-8' }) diff --git a/apps/version.js b/apps/version.js index 537ab16..f344a77 100644 --- a/apps/version.js +++ b/apps/version.js @@ -39,6 +39,10 @@ export class NewVersion extends plugin { } } +/** + * + * @param e + */ async function versionInfo (e) { return await puppeteer.render( 'help/version-info', diff --git a/components/Config.js b/components/Config.js index 7ca9b0b..38dbb0d 100644 --- a/components/Config.js +++ b/components/Config.js @@ -33,7 +33,10 @@ class Config { } } - /** 群配置 */ + /** + * 群配置 + * @param groupId + */ getGroup (groupId = '') { let config = this.getConfig('whole') let group = this.getConfig('group') @@ -100,19 +103,28 @@ class Config { return this.getDefOrConfig('state') } - /** 默认配置和用户配置 */ + /** + * 默认配置和用户配置 + * @param name + */ getDefOrConfig (name) { let def = this.getdefSet(name) let config = this.getConfig(name) return { ...def, ...config } } - /** 默认配置 */ + /** + * 默认配置 + * @param name + */ getdefSet (name) { return this.getYaml('default_config', name) } - /** 用户配置 */ + /** + * 用户配置 + * @param name + */ getConfig (name) { return this.getYaml('config', name) } @@ -137,7 +149,12 @@ class Config { return this.config[key] } - /** 监听配置文件 */ + /** + * 监听配置文件 + * @param file + * @param name + * @param type + */ watch (file, name, type = 'default_config') { let key = `${type}.${name}` @@ -157,10 +174,10 @@ class Config { } /** - * @description: 修改设置 - * @param {String} name 文件名 - * @param {String} key 修改的key值 - * @param {String|Number} value 修改的value值 + * 修改设置 + * @param {string} name 文件名 + * @param {string} key 修改的key值 + * @param {string | number} value 修改的value值 * @param {'config'|'default_config'} type 配置文件或默认 */ modify (name, key, value, type = 'config') { @@ -170,10 +187,11 @@ class Config { } /** - * @description: 群单独设置 - * @param {String|Number} groupId 群号 - * @param {String} key 设置项 + * 群单独设置 + * @param {string | number} groupId 群号 + * @param {string} key 设置项 * @param {unknown} value + * @param isDel */ aloneModify (groupId, key, value, isDel) { let path = `${Plugin_Path}/config/config/group.yaml` @@ -185,10 +203,10 @@ class Config { } /** - * @description: 修改配置数组 - * @param {String} name 文件名 - * @param {String|Number} key key值 - * @param {String|Number} value value + * 修改配置数组 + * @param {string} name 文件名 + * @param {string | number} key key值 + * @param {string | number} value value * @param {'add'|'del'} category 类别 add or del * @param {'config'|'default_config'} type 配置文件或默认 */ diff --git a/components/Data.js b/components/Data.js index be0c44f..a337221 100644 --- a/components/Data.js +++ b/components/Data.js @@ -35,7 +35,11 @@ let Data = { }) }, - /** 读取json */ + /** + * 读取json + * @param file + * @param root + */ readJSON (file = '', root = '') { root = getRoot(root) if (fs.existsSync(`${root}/${file}`)) { @@ -48,7 +52,13 @@ let Data = { return {} }, - /** 写JSON */ + /** + * 写JSON + * @param file + * @param data + * @param root + * @param space + */ writeJSON (file, data, root = '', space = '\t') { // 检查并创建目录 Data.createDir(file, root, true) @@ -222,7 +232,12 @@ let Data = { } return false }, - /** 读取文件夹和子文件夹指定后缀文件名 */ + /** + * 读取文件夹和子文件夹指定后缀文件名 + * @param directory + * @param extension + * @param excludeDir + */ readDirRecursive (directory, extension, excludeDir) { let files = fs.readdirSync(directory) diff --git a/components/YamlReader.js b/components/YamlReader.js index b5b7578..3cfb057 100644 --- a/components/YamlReader.js +++ b/components/YamlReader.js @@ -7,7 +7,6 @@ import chokidar from 'chokidar' export default class YamlReader { /** * 读写yaml文件 - * * @param yamlPath yaml文件绝对路径 * @param isWatch 是否监听文件变化 */ diff --git a/guoba.support.js b/guoba.support.js index 898540e..4a19975 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -8,6 +8,9 @@ import { Config } from './components/index.js' const Path = process.cwd() const Plugin_Path = `${Path}/plugins/yenai-plugin` +/** + * + */ export function supportGuoba () { return { pluginInfo: { diff --git a/lib/puppeteer/puppeteer.js b/lib/puppeteer/puppeteer.js index 04d4f80..0b1ec11 100644 --- a/lib/puppeteer/puppeteer.js +++ b/lib/puppeteer/puppeteer.js @@ -27,17 +27,16 @@ class NewPuppeteer { /** * 截取网页截图 - * * @async - * @param {Object} options - 参数选项对象 + * @param {object} options - 参数选项对象 * @param {string} options.url - 网页URL地址 - * @param {Object|false} [options.headers=false] - 请求头信息 - * @param {Object|false} [options.setViewport=false] - 设置浏览器视窗大小 - * @param {boolean} [options.font=false] - 是否设置字体样式 - * @param {Object|false} [options.cookie=false] - 设置cookie信息 - * @param {boolean} [options.fullPage=true] - 是否截取整个网页 - * @param {string|boolean} [options.emulate=false] - 模拟设备信息 - * @param {Array|false} [options.click=false] - 点击事件 + * @param {object | false} [options.headers] - 请求头信息 + * @param {object | false} [options.setViewport] - 设置浏览器视窗大小 + * @param {boolean} [options.font] - 是否设置字体样式 + * @param {object | false} [options.cookie] - 设置cookie信息 + * @param {boolean} [options.fullPage] - 是否截取整个网页 + * @param {string|boolean} [options.emulate] - 模拟设备信息 + * @param {Array|false} [options.click] - 点击事件 * @returns {Promise} Promise对象,如果截图成功返回构造图片消息,否则返回false */ async Webpage ({ @@ -157,7 +156,7 @@ class NewPuppeteer { * @async * @param {string} url - 要跳转的 URL。 * @param {string} waitSelector - 等待页面渲染的选择器。 - * @returns {Object} - 包含 URL 和页面数据的对象。 + * @returns {object} - 包含 URL 和页面数据的对象。 * @throws 如果导航或页面数据检索失败,将抛出错误。 */ async get (url, waitSelector) { diff --git a/lib/puppeteer/render.js b/lib/puppeteer/render.js index 68bd31b..ef8cc7f 100644 --- a/lib/puppeteer/render.js +++ b/lib/puppeteer/render.js @@ -5,11 +5,11 @@ const _path = process.cwd() export default new class { /** - * @description: 渲染HTML - * @param {String} path 文件路径 - * @param {Object} params 参数 - * @param {Object} cfg - */ + * 渲染HTML + * @param {string} path 文件路径 + * @param {object} params 参数 + * @param {object} cfg + */ async render (path, params, cfg) { let [app, tpl] = path.split('/') let { e } = cfg diff --git a/lib/request/request.js b/lib/request/request.js index a0b9839..34a8eb5 100644 --- a/lib/request/request.js +++ b/lib/request/request.js @@ -35,10 +35,10 @@ export default new class { * @async * @function * @param {string} url - 请求的URL - * @param {Object} [options={}] - 请求的配置项 - * @param {Object} [options.params] - 请求的参数 - * @param {Object} [options.headers] - 请求的HTTP头部 - * @param {boolean} [options.closeCheckStatus=false] - 是否关闭状态检查 + * @param {object} [options] - 请求的配置项 + * @param {object} [options.params] - 请求的参数 + * @param {object} [options.headers] - 请求的HTTP头部 + * @param {boolean} [options.closeCheckStatus] - 是否关闭状态检查 * @param {'buffer'|'json'|'text'|'arrayBuffer'|'formData'|'blob'}[options.statusCode] - 期望的返回数据,如果设置了该值,则返回响应数据的特定的方法(如json()、text()等) * @returns {Promise} - HTTP响应或响应数据 * @throws {Error} - 如果请求失败,则抛出错误 @@ -76,11 +76,11 @@ export default new class { * @async * @function * @param {string} url - 请求的URL - * @param {object} [options={}] - 请求的配置项 + * @param {object} [options] - 请求的配置项 * @param {object} [options.params] - 请求的参数 * @param {object} [options.headers] - 请求的HTTP头部 * @param {object} [options.data] - 请求的数据 - * @param {boolean} [options.closeCheckStatus=false] - 是否关闭状态检查 + * @param {boolean} [options.closeCheckStatus] - 是否关闭状态检查 * @param {'buffer'|'json'|'text'|'arrayBuffer'|'formData'|'blob'} [options.statusCode] - 期望的返回数据,如果设置了该值,则返回响应数据的特定的方法(如json()、text()等) * @returns {Promise} - HTTP响应或响应数据 * @throws {Error} - 如果请求失败,则抛出错误 @@ -127,11 +127,11 @@ export default new class { } /** - * @description: 绕cf Get请求 - * @param {String} url - * @param {Object} options 同fetch第二参数 - * @param {Object} options.params 请求参数 - * @return {FetchObject} + * 绕cf Get请求 + * @param {string} url + * @param {object} options 同fetch第二参数 + * @param {object} options.params 请求参数 + * @returns {Promise} */ async cfGet (url, options = {}) { options.agent = this.getAgent(true) @@ -143,11 +143,11 @@ export default new class { } /** - * @description: 绕cf Post请求 - * @param {String} url - * @param {Object} options 同fetch第二参数 - * @param {Object|String} options.data 请求参数 - * @return {FetchObject} + * 绕cf Post请求 + * @param {string} url + * @param {object} options 同fetch第二参数 + * @param {object | string} options.data 请求参数 + * @returns {Promise} */ async cfPost (url, options = {}) { options.agent = this.getAgent(true) @@ -198,12 +198,13 @@ export default new class { } /** - * @description: 代理请求图片 - * @param {String} url 图片链接 - * @param {Boolean} cache 是否缓存 - * @param {Number} timeout 超时时间 - * @param {Object} headers 请求头 - * @return {Porimes} 构造图片消息 + * 代理请求图片 + * @param {string} url 图片链接 + * @param {object} options 配置 + * @param {boolean} options.cache 是否缓存 + * @param {number} options.timeout 超时时间 + * @param {object} options.headers 请求头 + * @returns {Promise} 构造图片消息 */ async proxyRequestImg (url, { cache, timeout, headers } = {}) { if (!this.getAgent()) return segment.image(url, cache, timeout, headers) diff --git a/model/Bika.js b/model/Bika.js index a0fcfdf..de3a236 100644 --- a/model/Bika.js +++ b/model/Bika.js @@ -21,9 +21,9 @@ export default new (class { /** * 关键词搜索作品 * @param {string} keyword - 搜索关键词 - * @param {number} [page=1] - 页码,默认为1 - * @param {'dd'|'da'|'ld'|'vd'} [sort='ld'] - 排序方式:dd(最新发布)、da(最早发布)、ld(最多喜欢)、vd(最多浏览),默认为'ld' - * @param {string} [type='advanced'] - 搜索类型:advanced(高级)、category(类别)、author(作者),默认为'advanced' + * @param {number} [page] - 页码,默认为1 + * @param {string} [type] - 搜索类型:advanced(高级)、category(类别)、author(作者),默认为'advanced' + * @param {'dd'|'da'|'ld'|'vd'} [sort] - 排序方式:dd(最新发布)、da(最早发布)、ld(最多喜欢)、vd(最多浏览),默认为'ld' * @throws {Error} 当未找到作品时,会抛出异常 * @returns {Array} 返回搜索结果信息数组 */ @@ -77,8 +77,8 @@ export default new (class { * 获取漫画某一话某一页的信息及图片列表 * @async * @param {string} id - 漫画id - * @param {number} [page=1] - 页码,默认为1 - * @param {number} [order=1] - 话数,默认为1 + * @param {number} [page] - 页码,默认为1 + * @param {number} [order] - 话数,默认为1 * @returns {Promise} - 返回一个数组,包含漫画某一话某一页的信息及图片列表 * @throws {Error} - 如果返回结果中包含error,则抛出异常 */ @@ -112,7 +112,7 @@ export default new (class { /** * 获取下一个漫画页面或漫画章节的信息及图片列表 * @async - * @param {string} [type='comicPage'] - 请求的类型,可选值为'comicPage'或'chapter',默认为'comicPage' + * @param {string} [type] - 请求的类型,可选值为'comicPage'或'chapter',默认为'comicPage' * @returns {Promise} - 返回一个数组,包含下一个漫画页面或漫画章节的信息及图片列表 * @throws {Error} - 如果未找到上一个id,则抛出异常 */ diff --git a/model/GroupBannedWords.js b/model/GroupBannedWords.js index 2829542..4c61a36 100644 --- a/model/GroupBannedWords.js +++ b/model/GroupBannedWords.js @@ -82,7 +82,10 @@ export default new class { return data.muteTime ?? 300 } - /** 关键词转换成可发送消息 */ + /** + * 关键词转换成可发送消息 + * @param msg + */ async keyWordTran (msg) { /** 图片 */ if (msg.includes('{image')) { @@ -116,7 +119,10 @@ export default new class { return msg } - /** 初始化已添加内容 */ + /** + * 初始化已添加内容 + * @param groupId + */ initTextArr (groupId) { if (this.dataCach.get(groupId)) return this.dataCach.get(groupId) diff --git a/model/PicSearch/ascii2d.js b/model/PicSearch/ascii2d.js index 0196b04..6aa0fb9 100644 --- a/model/PicSearch/ascii2d.js +++ b/model/PicSearch/ascii2d.js @@ -7,6 +7,9 @@ let cheerio = '' let domain = 'https://ascii2d.net/' +/** + * + */ async function importCheerio () { if (cheerio) return cheerio try { @@ -16,6 +19,10 @@ async function importCheerio () { } } +/** + * + * @param url + */ export default async function doSearch (url) { await importCheerio() const { ascii2dUsePuppeteer, ascii2dResultMaxQuantity } = Config.picSearch @@ -76,9 +83,17 @@ const callAscii2dUrlApi = async (imgUrl) => { data: await res.text() } } +/** + * + * @param url + */ async function getAscii2dWithPuppeteer (url) { return await puppeteer.get(url, 'body > .container') } +/** + * + * @param body + */ async function parse (body) { const $ = cheerio.load(body, { decodeEntities: true }) return _.map($('.item-box'), (item) => { diff --git a/model/PicSearch/saucenao.js b/model/PicSearch/saucenao.js index 5d4c856..9e909ae 100644 --- a/model/PicSearch/saucenao.js +++ b/model/PicSearch/saucenao.js @@ -3,6 +3,10 @@ import { Config } from '../../components/index.js' import sagiri from '../../tools/sagiri.js' import request from '../../lib/request/request.js' import Ascii2D from './ascii2d.js' +/** + * + * @param url + */ export default async function doSearch (url) { let res = await getSearchResult(url) logger.debug('SauceNAO result:', res) @@ -49,6 +53,11 @@ export default async function doSearch (url) { return message } +/** + * + * @param imgURL + * @param db + */ async function getSearchResult (imgURL, db = 999) { logger.debug(`saucenao [${imgURL}]}`) let api_key = Config.picSearch.SauceNAOApiKey diff --git a/model/PicSearch/whatanime.js b/model/PicSearch/whatanime.js index efd10dc..e9ead79 100644 --- a/model/PicSearch/whatanime.js +++ b/model/PicSearch/whatanime.js @@ -2,6 +2,11 @@ import request from '../../lib/request/request.js' import { Config, Plugin_Path } from '../../components/index.js' import common from '../../../../lib/common/common.js' import _ from 'lodash' + +/** + * + * @param imgURL + */ export default async function doSearch (imgURL) { let result = await getSearchResult(imgURL) if (result.error) throw Error(result.error) @@ -47,11 +52,9 @@ export default async function doSearch (imgURL) { const date2str = ({ year, month, day }) => [year, month, day].join('-') /** * 取得搜番结果 - * - * @param {string} host 自定义 whatanime 的 host - * @param {string} key whatanime token * @param {string} url 图片地址 - * @returns Prased JSON + * @param {string} key whatanime token + * @returns {Promise} Prased JSON */ async function getSearchResult (url, key = '') { let host = 'https://api.trace.moe' @@ -90,9 +93,8 @@ query ($id: Int) { }` /** * 取得番剧信息 - * * @param {number} id - * @returns Prased JSON + * @returns {Promise} Prased JSON */ async function getAnimeInfo (id) { return await request.post('https://trace.moe/anilist/', { @@ -103,6 +105,10 @@ async function getAnimeInfo (id) { }).then(res => res.json()) } +/** + * + * @param url + */ async function downFile (url) { let path = `${Plugin_Path}/temp/whatanime/1.mp4` logger.mark('[Yenai-Plugin][whatanime]下载预览视频') diff --git a/model/Pixiv.js b/model/Pixiv.js index 0ffe86e..6502519 100644 --- a/model/Pixiv.js +++ b/model/Pixiv.js @@ -54,10 +54,11 @@ export default new class Pixiv { } /** - * @description: 获取插画信息 - * @param {String} ids 插画ID - * @return {Object} - */ + * 获取插画信息 + * @param {string} ids 插画ID + * @param filter + * @returns {object} + */ async illust (ids, filter = false) { const params = { id: ids } let res = null @@ -96,13 +97,13 @@ export default new class Pixiv { } /** - * @description: 获取Pixiv榜单 - * @param {Number} page 页数 - * @param {Date} date 时间YYYY-MM-DD - * @param {String} mode 榜单类型 - * @param {Boolean} r18 是否为R18榜单 - * @return {Array} - */ + * 获取Pixiv榜单 + * @param {number} page 页数 + * @param {Date} date 时间YYYY-MM-DD + * @param {string} mode 榜单类型 + * @param {boolean} r18 是否为R18榜单 + * @returns {Array} + */ async Rank (page = 1, date = '', mode = '周', r18 = false) { // 转为大写 mode = _.toUpper(mode) @@ -171,11 +172,11 @@ export default new class Pixiv { } /** - * @description: 根据关键词搜图 - * @param {String} tag 关键词 - * @param {String} page 页数 - * @return {Array} - */ + * 根据关键词搜图 + * @param {string} tag 关键词 + * @param {string} page 页数 + * @returns {Array} + */ async vilipixSearchTags (tag, page = 1) { const api = 'https://www.vilipix.com/api/v1/picture/public' const params = { @@ -211,11 +212,12 @@ export default new class Pixiv { } /** - * @description: tag搜图pro - * @param {String} tag 关键词 - * @param {String} page 页数 - * @return {*} - */ + * tag搜图pro + * @param {string} tag 关键词 + * @param {string} page 页数 + * @param isfilter + * @returns {*} + */ async searchTags (tag, page = 1, isfilter = true) { const params = { word: tag, @@ -259,9 +261,9 @@ export default new class Pixiv { } /** - * @description: 获取热门tag - * @return {Array} - */ + * 获取热门tag + * @returns {Array} + */ async PopularTags () { let res = null if (this.PixivClient.auth) { @@ -289,12 +291,12 @@ export default new class Pixiv { } /** - * @description: 搜索用户插画 - * @param {Number|String} keyword 用户uid或名称 - * @param {Number|String} page 页数 - * @param {Boolean} isfilter 是否过滤敏感内容 - * @return {Array} - */ + * 搜索用户插画 + * @param {number | string} keyword 用户uid或名称 + * @param {number | string} page 页数 + * @param {boolean} isfilter 是否过滤敏感内容 + * @returns {Array} + */ async userIllust (keyword, page = 1, isfilter = true) { // 关键词搜索 if (!/^\d+$/.test(keyword)) { @@ -358,11 +360,11 @@ export default new class Pixiv { } /** - * @description:搜索用户 - * @param {String} word 用户name - * @param {Number} page 页数 - * @param {Boolean} isfilter 是否过滤敏感内容 - * @return {Array} 可直接发送的消息数组 + * 搜索用户 + * @param {string} word 用户name + * @param {number} page 页数 + * @param {boolean} isfilter 是否过滤敏感内容 + * @returns {Array} 可直接发送的消息数组 */ async searchUser (word, page = 1, isfilter = true) { let params = { @@ -401,9 +403,10 @@ export default new class Pixiv { } /** - * @description: vilipix随机图片 - * @return {Array} - */ + * @param limit + * vilipix随机图片 + * @returns {Array} + */ async vilipixRandomImg (limit) { let api = `https://www.vilipix.com/api/v1/picture/recommand?limit=${limit}&offset=${_.random(1, 700)}` let res = await request.get(api).then(res => res.json()) @@ -421,10 +424,11 @@ export default new class Pixiv { } /** - * @description: 相关作品 - * @param {String} pid - * @return {*} - */ + * 相关作品 + * @param {string} pid + * @param isfilter + * @returns {*} + */ async relatedIllust (pid, isfilter = true) { let params = { id: pid } let res = null @@ -462,7 +466,10 @@ export default new class Pixiv { ] } - /** p站单图 */ + /** + * p站单图 + * @param pro + */ async pximg (pro) { let url = 'https://image.anosu.top/pixiv/json' const params = { @@ -487,9 +494,9 @@ export default new class Pixiv { } /** - * @description: 推荐作品 - * @param {Number} num 数量 - * @return {Promise} + * 推荐作品 + * @param {number} num 数量 + * @returns {Promise} */ async illustRecommended (num) { let list = await this.PixivClient.illustRecommended() @@ -508,9 +515,9 @@ export default new class Pixiv { } /** - * @description: 请求p站图片 - * @param {String} url - * @return {Promise} + * 请求p站图片 + * @param {string} url + * @returns {Promise} */ async _requestPixivImg (url) { url = url.replace('i.pximg.net', this.proxy) @@ -520,22 +527,22 @@ export default new class Pixiv { } /** - * @description: 格式化 - * @param {Object} illusts 处format理对象 - * @return {Object} - * title 标题 - * id pid - * total_bookmarks 点赞 - * total_view 访问量 - * tags 标签 - * url 图片链接 - * user 作者信息 - * image_urls 单张图片 - * x_restrict 是否为全年龄 - * create_date 发布时间 - * illust_ai_type 是否为AI作品 - * visible 是否为可见作品 - */ + * 格式化 + * @param {object} illusts 处format理对象 + * @returns {object} + * title 标题 + * id pid + * total_bookmarks 点赞 + * total_view 访问量 + * tags 标签 + * url 图片链接 + * user 作者信息 + * image_urls 单张图片 + * x_restrict 是否为全年龄 + * create_date 发布时间 + * illust_ai_type 是否为AI作品 + * visible 是否为可见作品 + */ _format (illusts) { let url = [] let { tags, meta_single_page, meta_pages } = illusts diff --git a/model/Pixiv/api.js b/model/Pixiv/api.js index e8d9c33..90df257 100644 --- a/model/Pixiv/api.js +++ b/model/Pixiv/api.js @@ -201,6 +201,10 @@ export default class PixivApi { return await this.request('v1/illust/recommended', params) } } +/** + * + * @param time + */ function timeToSeconds (time) { let seconds = 0 let timeArray = time.split(' ') @@ -227,6 +231,9 @@ function timeToSeconds (time) { return seconds } +/** + * + */ function getNoonTomorrow () { const now = moment() // 获取当前时间 const noonToday = moment().startOf('day').add(12, 'hours') // 获取今天中午12点的时间 diff --git a/model/State.js b/model/State.js index 413c57c..19ccdbc 100644 --- a/model/State.js +++ b/model/State.js @@ -138,10 +138,9 @@ export default new class { /** * 向数组中添加数据,如果数组长度超过允许的最大值,则删除最早添加的数据 - * * @param {Array} arr - 要添加数据的数组 * @param {*} data - 要添加的新数据 - * @param {number} [maxLen=60] - 数组允许的最大长度,默认值为60 + * @param {number} [maxLen] - 数组允许的最大长度,默认值为60 * @returns {void} */ addData (arr, data, maxLen = 60) { @@ -155,14 +154,14 @@ export default new class { } /** - * 重试获取数据,直到成功或达到最大重试次数。 - * @param {Function} fetchFunc 获取数据的函数,返回一个Promise对象。 - * @param {Array} [params=[]] 需要执行函数的参数数组 - * @param {Number} [timerId] 定时器的id,用于在获取数据失败时停止定时器 - * @param {Number} [maxRetryCount=3] 最大重试次数。 - * @param {Number} [retryInterval=1000] 两次重试之间的等待时间,单位为毫秒。。 - * @return {Promise} 获取到的数据。如果达到最大重试次数且获取失败,则返回null。 - */ + * 重试获取数据,直到成功或达到最大重试次数。 + * @param {Function} fetchFunc 获取数据的函数,返回一个Promise对象。 + * @param {Array} [params] 需要执行函数的参数数组 + * @param {number} [timerId] 定时器的id,用于在获取数据失败时停止定时器 + * @param {number} [maxRetryCount] 最大重试次数。 + * @param {number} [retryInterval] 两次重试之间的等待时间,单位为毫秒。。 + * @returns {Promise} 获取到的数据。如果达到最大重试次数且获取失败,则返回null。 + */ async fetchDataWithRetry (fetchFunc, params = [], timerId, maxRetryCount = 3, retryInterval = 1000) { let retryCount = 0 let data = null @@ -183,13 +182,12 @@ export default new class { } /** - * 将文件大小从字节转化为可读性更好的格式,例如B、KB、MB、GB、TB。 - * - * @param {number} size - 带转化的字节数。 - * @param {boolean} [isByte=true] - 如果为 true,则最终的文件大小显示保留 B 的后缀. - * @param {boolean} [isSuffix=true] - 如果为 true,则在所得到的大小后面加上 kb、mb、gb、tb 等后缀. - * @returns {string} 文件大小格式转换后的字符串. - */ + * 将文件大小从字节转化为可读性更好的格式,例如B、KB、MB、GB、TB。 + * @param {number} size - 带转化的字节数。 + * @param {boolean} [isByte] - 如果为 true,则最终的文件大小显示保留 B 的后缀. + * @param {boolean} [isSuffix] - 如果为 true,则在所得到的大小后面加上 kb、mb、gb、tb 等后缀. + * @returns {string} 文件大小格式转换后的字符串. + */ getFileSize (size, isByte = true, isSuffix = true) { // 把字节转换成正常文件大小 if (size == null || size == undefined) return 0 let num = 1024.00 // byte @@ -209,10 +207,10 @@ export default new class { } /** - * @description: 圆形进度条渲染 - * @param {Number} res 百分比小数 - * @return {*} css样式 - */ + * 圆形进度条渲染 + * @param {number} res 百分比小数 + * @returns {*} css样式 + */ Circle (res) { let num = (res * 360).toFixed(0) let color = 'var(--low-color)' @@ -336,8 +334,8 @@ export default new class { } /** - * @description: 获取硬盘 - * @return {*} + * 获取硬盘 + * @returns {*} */ async getFsSize () { // 去重 @@ -363,7 +361,10 @@ export default new class { }) } - /** 获取FastFetch */ + /** + * 获取FastFetch + * @param e + */ async getFastFetch (e) { if (process.platform == 'win32' && !/pro/.test(e.msg)) return '' let ret = await common.execSync('bash plugins/yenai-plugin/resources/state/state.sh') @@ -389,8 +390,8 @@ export default new class { } /** - * @description: 获取网速 - * @return {object} + * 获取网速 + * @returns {object} */ get getnetwork () { let network = _.cloneDeep(this.network)?.[0] @@ -407,9 +408,9 @@ export default new class { } /** - * @description: 取插件包 - * @return {*} 插件包数量 - */ + * 取插件包 + * @returns {*} 插件包数量 + */ get getPluginNum () { let str = './plugins' let arr = fs.readdirSync(str) diff --git a/model/api/QQApi.js b/model/api/QQApi.js index f072107..4e8f132 100644 --- a/model/api/QQApi.js +++ b/model/api/QQApi.js @@ -26,12 +26,11 @@ export default class { } /** - * @description: 取说说列表 - * @param {*} e oicq - * @param {Number} num 数量 - * @param {Number} pos 偏移量 - * @return {Object} QQ空间数据 - */ + * 取说说列表 + * @param {number} num 数量 + * @param {number} pos 偏移量 + * @returns {object} QQ空间数据 + */ async getQzone (num = 20, pos = 0) { let url = `https://user.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin=${this.Bot.uin}&ftype=0&sort=0&pos=${pos}&num=${num}&replynum=100&g_tk=${this.Bot.bkn}&code_version=1&format=json&need_private_comment=1` return await fetch(url, { @@ -42,10 +41,10 @@ export default class { } /** - * @description: 删除说说 - * @param {String} tid tid参数 - * @param {String} t1_source t1_source参数 - */ + * 删除说说 + * @param {string} tid tid参数 + * @param {string} t1_source t1_source参数 + */ async delQzone (tid, t1_source) { let url = `https://user.qzone.qq.com/proxy/domain/taotao.qzone.qq.com/cgi-bin/emotion_cgi_delete_v6?&g_tk=${this.Bot.bkn}` // 发送请求 @@ -74,7 +73,11 @@ export default class { // } } - /** 发送说说 */ + /** + * 发送说说 + * @param con + * @param img + */ async setQzone (con, img) { let ck = common.getck('qzone.qq.com', this.Bot) @@ -94,11 +97,11 @@ export default class { } /** - * @description: 获取留言 - * @param {Number} num 数量为0时返回为全部 - * @param {Number} start 偏移量/开始的位置 - * @return {*} - */ + * 获取留言 + * @param {number} num 数量为0时返回为全部 + * @param {number} start 偏移量/开始的位置 + * @returns {*} + */ async getQzoneMsgb (num = 0, start = 0) { let url = `https://user.qzone.qq.com/proxy/domain/m.qzone.qq.com/cgi-bin/new/get_msgb?uin=${this.Bot.uin}&hostUin=${this.Bot.uin}&start=${start}&s=0.45779069937151884&format=json&num=${num}&inCharset=utf-8&outCharset=utf-8&g_tk=${this.Bot.bkn}` return await fetch(url, { @@ -109,11 +112,11 @@ export default class { } /** - * @description: 删除留言 - * @param {*} id 留言id - * @param {*} uinId - * @return {*} - */ + * 删除留言 + * @param {*} id 留言id + * @param {*} uinId + * @returns {*} + */ async delQzoneMsgb (id, uinId) { let delurl = `https://h5.qzone.qq.com/proxy/domain/m.qzone.qq.com/cgi-bin/new/del_msgb?&g_tk=${this.Bot.bkn}` return await fetch(delurl, { @@ -144,11 +147,11 @@ export default class { // ----------------------------------------------------公告--------------------------------------------- /** - * @description: 获取群公告 - * @param {String} group 群号 - * @param {String} item 序号 - * @return {Object} - */ + * 获取群公告 + * @param group_id + * @param s + * @returns {object} + */ async getAnnouncelist (group_id, s = 0) { let n = s ? 1 : 20 let url = `https://web.qun.qq.com/cgi-bin/announce/get_t_list?bkn=${this.Bot.bkn}&qid=${group_id}&ft=23&s=${s - 1}&n=${n}` @@ -165,10 +168,10 @@ export default class { } /** - * @description: 发送群公告 - * @param {Number} group_id 发送群号 - * @param {String} msg 发送内容 - */ + * 发送群公告 + * @param {number} group_id 发送群号 + * @param {string} msg 发送内容 + */ async setAnnounce (group_id, msg) { let url = `https://web.qun.qq.com/cgi-bin/announce/add_qun_notice?bkn=${this.Bot.bkn}` return await fetch(url, { @@ -181,10 +184,10 @@ export default class { } /** - * @description: 删群公告 - * @param {Number} group_id 群号 - * @param {Number} num 序号 - */ + * 删群公告 + * @param {number} group_id 群号 + * @param {number} num 序号 + */ async delAnnounce (group_id, num) { let fid = await this.getAnnouncelist(group_id, num) if (!fid) return false @@ -203,7 +206,10 @@ export default class { } } - /** 群星级 */ + /** + * 群星级 + * @param group_id + */ async getCreditLevelInfo (group_id) { let url = `https://qqweb.qq.com/c/activedata/get_credit_level_info?bkn=${this.Bot.bkn}&uin=${this.Bot.uin}&gc=${group_id}` return await fetch(url, { @@ -215,7 +221,10 @@ export default class { }).then(res => res.json()).catch(err => logger.error(err)) } - /** 查看本群龙王 */ + /** + * 查看本群龙王 + * @param group_id + */ async dragon (group_id) { let url = `https://qun.qq.com/interactive/honorlist?gc=${group_id}&type=1&_wv=3&_wwv=129` let res = await fetch(url, { headers: { Cookie: this.Bot.cookies['qun.qq.com'] } }) @@ -226,9 +235,9 @@ export default class { } /** - * @description: 开关好友添加 - * @param {Number} type 1关闭2开启 - */ + * 开关好友添加 + * @param {number} type 1关闭2开启 + */ async addFriendSwitch (type) { let url = `https://ti.qq.com/proxy/domain/oidb.tim.qq.com/v3/oidbinterface/oidb_0x587_75?sdkappid=39998&actype=2&bkn=${this.Bot.bkn}` return await fetch(url, { @@ -244,12 +253,12 @@ export default class { } /** - * @description: 更改好友申请方式 - * @param {*} at 类型1 - * @param {*} q - * @param {*} a - * @return {*} - */ + * 更改好友申请方式 + * @param {*} at 类型1 + * @param {*} q + * @param {*} a + * @returns {*} + */ async setFriendType (at, q = '', a = '') { const type = { 1: '0', @@ -270,10 +279,10 @@ export default class { } /** - * @description: 设置戳一戳开关 - * @param {Number} is 0为开启1为关闭 - */ - async setcyc (is) { + * 设置戳一戳开关 + * @param {number} isclose 0为开启1为关闭 + */ + async setcyc (isclose) { let url = `https://zb.vip.qq.com/srf/QC_UniBusinessLogicServer_UniBusinessLogicObj/uniSet?g_tk=${this.Bot.bkn}` return await fetch(url, { method: 'POST', @@ -292,7 +301,7 @@ export default class { }, stNudge: { ischangeswitch: 1, - isclose: is, + isclose, ischangecustomtext: 1, customtext: '' } @@ -305,7 +314,10 @@ export default class { }).then(res => res.json()).catch(err => logger.error(err)) } - /** 今日打卡 */ + /** + * 今日打卡 + * @param groupId + */ async signInToday (groupId) { let body = JSON.stringify({ dayYmd: moment().format('YYYYMMDD'), @@ -323,10 +335,10 @@ export default class { } /** - * @description: 群发言榜单 - * @param {Number} groupId 群号 - * @param {Strng} time true为7天false为昨天 - */ + * 群发言榜单 + * @param {number} groupId 群号 + * @param {string} time true为7天false为昨天 + */ async SpeakRank (groupId, time = false) { let url = `https://qun.qq.com/m/qun/activedata/proxy/domain/qun.qq.com/cgi-bin/manager/report/list?bkn=${this.Bot.bkn}&gc=${groupId}&type=0&start=0&time=${time ? 1 : 0}` return await fetch(url, { @@ -335,10 +347,10 @@ export default class { } /** - * @description: 群数据 - * @param {String} groupId 群号 - * @param {Strng} time true为7天false为昨天 - */ + * 群数据 + * @param {string} groupId 群号 + * @param {string} time true为7天false为昨天 + */ async groupData (groupId, time = false) { let url = `https://qun.qq.com/m/qun/activedata/proxy/domain/qun.qq.com/cgi-bin/manager/report/index?gc=${groupId}&time=${time ? 1 : 0}&bkn=${this.Bot.bkn}` return await fetch(url, { @@ -349,9 +361,12 @@ export default class { // ---------------------------------字符--------------------------------------------- /** - * @description: 字符列表 - * @return {*} - */ + * @param groupId + * @param start + * @param limit + * 字符列表 + * @returns {*} + */ async luckylist (groupId, start = 0, limit = 10) { let body = JSON.stringify({ group_code: groupId, @@ -368,10 +383,10 @@ export default class { } /** - * @description: 更换字符 - * @param {String} group_id 群号 - * @param {String} id 字符id - */ + * 更换字符 + * @param {string} group_id 群号 + * @param {string} id 字符id + */ async equipLucky (group_id, id) { let body = JSON.stringify({ group_code: group_id, @@ -386,10 +401,10 @@ export default class { } /** - * @description: 抽取幸运字符 - * @param {String} group_id 群号 - * @return {*} - */ + * 抽取幸运字符 + * @param {string} group_id 群号 + * @returns {*} + */ async drawLucky (group_id) { let body = JSON.stringify({ group_code: group_id @@ -403,10 +418,10 @@ export default class { } /** - * @description: 开关幸运字符 - * @param {Number} groupId 群号 - * @param {Boolean} type - */ + * 开关幸运字符 + * @param {number} groupId 群号 + * @param {boolean} type + */ async swichLucky (groupId, type) { let body = JSON.stringify({ group_code: groupId, @@ -421,10 +436,10 @@ export default class { } /** - * @description: 批量踢人 + * 批量踢人 + * @param {number} groupId 群号 * @param {Array} member 要踢的人的数组 - * @param {Number} groupId 群号 - * @return {*} + * @returns {*} */ async deleteGroupMember (groupId, member) { let res = [] @@ -451,9 +466,8 @@ export default class { /** * 获取QQ等级信息 - * * @param {string|number} userId QQ号码 - * @returns {Promise} 包含QQ等级信息的Promise对象 + * @returns {Promise} 包含QQ等级信息的Promise对象 */ async getQQLevel (userId) { const url = 'https://club.vip.qq.com/api/vip/getQQLevelInfo' @@ -479,8 +493,7 @@ export default class { /** * 自定义机型 * @param {string} modelName - * @param {string} modelShow - * @returns + * @returns {Promise} */ async setModel (modelName) { const url = 'https://proxy.vip.qq.com/cgi-bin/srfentry.fcgi' diff --git a/model/api/funApi/bgg.js b/model/api/funApi/bgg.js index df93947..e48cc91 100644 --- a/model/api/funApi/bgg.js +++ b/model/api/funApi/bgg.js @@ -2,6 +2,10 @@ import { _importDependency } from './utils.js' import request from '../../../lib/request/request.js' import { puppeteer } from '../../index.js' +/** + * + * @param keyword + */ export default async function bgg (keyword) { let cheerio = await _importDependency() let url = 'https://www.gstonegames.com/game/?hot_sort=1&keyword=' + encodeURIComponent(keyword) diff --git a/model/api/funApi/pageCrawling.js b/model/api/funApi/pageCrawling.js index 83cd4f3..67885f8 100644 --- a/model/api/funApi/pageCrawling.js +++ b/model/api/funApi/pageCrawling.js @@ -3,6 +3,11 @@ import _ from 'lodash' import { _importDependency } from './utils.js' import request from '../../../lib/request/request.js' +/** + * + * @param type + * @param keywords + */ export async function pandadiu (type = 'cos', keywords = '') { let cheerio = await _importDependency() let domain = 'https://www.pandadiu.com' @@ -29,6 +34,11 @@ export async function pandadiu (type = 'cos', keywords = '') { ..._.take(imgs, 30) ] } +/** + * + * @param keywords + * @param isSearch + */ export async function mengdui (keywords, isSearch) { let cheerio = await _importDependency() const domain = 'https://b6u8.com' @@ -63,6 +73,10 @@ export async function mengdui (keywords, isSearch) { return [title, number, ..._.take(imgs, 30)] } +/** + * + * @param type + */ export async function xiuren (type) { let cheerio = await _importDependency() // 可扩展 @@ -89,6 +103,9 @@ export async function xiuren (type) { return imgList } +/** + * + */ export async function coser () { let cheerio = await _importDependency() const domain = 'https://t2cy.com' diff --git a/model/api/funApi/thumbUp.js b/model/api/funApi/thumbUp.js index e5d77da..fe9f150 100644 --- a/model/api/funApi/thumbUp.js +++ b/model/api/funApi/thumbUp.js @@ -3,6 +3,10 @@ import { memes, common } from '../../index.js' import { Config } from '../../../components/index.js' import { successImgs, faildsImgs } from '../../../constants/fun.js' +/** + * + * @param e + */ export default async function thumbUp (e) { let _do = '赞' let userId = e.user_id @@ -73,11 +77,11 @@ class ThumbUpApi { } /** - * @description: 陌生人点赞 - * @param {Number} uid QQ号 - * @param {Number} times 数量 - * @return {Object} - */ + * 陌生人点赞 + * @param {number} uid QQ号 + * @param {number} times 数量 + * @returns {object} + */ async thumbUp (uid, times = 1) { try { let core = this.Bot.icqq?.core diff --git a/model/api/funApi/utils.js b/model/api/funApi/utils.js index ec8470d..af8a6c0 100644 --- a/model/api/funApi/utils.js +++ b/model/api/funApi/utils.js @@ -2,6 +2,9 @@ export const API_ERROR = '出了点小问题,待会再试试吧' let cheerio = null +/** + * + */ export async function _importDependency () { if (cheerio) return cheerio cheerio = await import('cheerio') diff --git a/model/api/funApi/youdao.js b/model/api/funApi/youdao.js index 2419ff2..176b5f4 100644 --- a/model/api/funApi/youdao.js +++ b/model/api/funApi/youdao.js @@ -3,7 +3,12 @@ import md5 from 'md5' import { API_ERROR } from './utils.js' import _ from 'lodash' -/** 有道翻译 */ +/** + * 有道翻译 + * @param msg + * @param to + * @param from + */ export default async function youdao (msg, to = 'auto', from = 'auto') { if (to != 'auto') to = youDaoLangType.find(item => item.label == to)?.code if (from != 'auto') from = youDaoLangType.find(item => item.label == from)?.code diff --git a/model/memes.js b/model/memes.js index 46108bc..4c72425 100644 --- a/model/memes.js +++ b/model/memes.js @@ -10,7 +10,10 @@ export default new class { this.folderPath = `${Plugin_Path}/resources/memes` } - /** 比心/赞 */ + /** + * 比心/赞 + * @param image + */ async zan (image) { if (!Jimp) return false let background = await Jimp.read(this.getRandomImagePath(`${this.folderPath}/bixin`)) @@ -24,7 +27,10 @@ export default new class { return buff } - /** 爬 */ + /** + * 爬 + * @param image + */ async crawl (image) { if (!Jimp) return false let background = await Jimp.read(this.getRandomImagePath(`${this.folderPath}/crawl`)) diff --git a/model/setu.js b/model/setu.js index 90a912d..cc1d110 100644 --- a/model/setu.js +++ b/model/setu.js @@ -34,12 +34,12 @@ export default new class setu { } /** - * @description: 请求api - * @param {String} r18 是否r18 0或1 - * @param {Number} num 数量 - * @param {String} tag 关键词 - * @return {Object} - */ + * 请求api + * @param {string} r18 是否r18 0或1 + * @param {number} num 数量 + * @param {string} tag 关键词 + * @returns {object} + */ async setuApi (r18, num = 1, tag = []) { let api = 'https://api.lolicon.app/setu/v2' const { imgSize, excludeAI } = Config.setu @@ -71,11 +71,11 @@ export default new class setu { } /** - * @description: 发送消息和写入cd - * @param {*} e oicq - * @param {Array} img 消息数组 - * @return {Boolean} - */ + * 发送消息和写入cd + * @param {*} e oicq + * @param {Array} msg 消息数组 + * @returns {boolean} + */ async sendMsgOrSetCd (e, msg) { // 发送消息 let res = await common.recallSendForwardMsg(e, msg, false) @@ -85,12 +85,12 @@ export default new class setu { } /** - * @description: 设置cd - * @param {Number} userId QQ号 - * @param {Number} groupId 群号不传为私聊CD - * @param {Number} cd cd时间 - * @return {*} - */ + * 设置cd + * @param {number} userId QQ号 + * @param {number} groupId 群号不传为私聊CD + * @param {number} cd cd时间 + * @returns {*} + */ setCdTime (userId, groupId, cd = this.getCfgCd(userId, groupId)) { let present = parseInt(Date.now() / 1000) userId = userId - 0 @@ -111,10 +111,10 @@ export default new class setu { } /** - * @description: 获取剩余CD时间 - * @param {Number} userId QQ号 - * @param {Number} groupId 群号不传则为私聊CD - * @return {String} 格式化后的时间 + * 获取剩余CD时间 + * @param {number} userId QQ号 + * @param {number} groupId 群号不传则为私聊CD + * @returns {string} 格式化后的时间 */ getRemainingCd (userId, groupId) { userId = userId - 0 @@ -134,11 +134,11 @@ export default new class setu { } /** - * @description: 获取配置cd - * @param {Number} userId QQ号 - * @param {Number} groupId 传群号为群聊配置 - * @return {*} - */ + * 获取配置cd + * @param {number} userId QQ号 + * @param {number} groupId 传群号为群聊配置 + * @returns {*} + */ getCfgCd (userId, groupId) { let data = Data.readJSON(`setu${groupId ? '' : '_s'}.json`, this.root) let CD = groupId ? data[groupId]?.cd : data[userId] @@ -147,10 +147,10 @@ export default new class setu { } /** - * @description: 获取r18 - * @param {Number} groupID 群号不传为私聊 - * @return {String} 0或1 - */ + * 获取r18 + * @param {number} groupID 群号不传为私聊 + * @returns {string} 0或1 + */ getR18 (groupID) { let data = Data.readJSON(`setu${groupID ? '' : '_s'}.json`, this.root) let R18 = groupID ? data[groupID]?.r18 : data.r18 @@ -159,10 +159,10 @@ export default new class setu { } /** - * @description: 获取群的撤回时间 - * @param {*} e oicq - * @return {Number} - */ + * 获取群的撤回时间 + * @param groupId + * @returns {number} + */ getRecallTime (groupId) { if (!groupId) return 0 let data = Data.readJSON('setu.json', this.root) @@ -172,12 +172,12 @@ export default new class setu { } /** - * @description: 设置群cd和撤回时间 - * @param {Number} groupId 群号 - * @param {Number} num 设置时间 - * @param {Boolean} type 为true设置撤回时间反之设置CD - * @return {Boolean} - */ + * 设置群cd和撤回时间 + * @param {number} groupId 群号 + * @param {number} num 设置时间 + * @param {boolean} type 为true设置撤回时间反之设置CD + * @returns {boolean} + */ setGroupRecallTimeAndCd (groupId, num, type) { let data = Data.readJSON('setu.json', this.root) @@ -189,11 +189,11 @@ export default new class setu { } /** - * @description: 设置CD - * @param {*} e oicq - * @param {String} qq 设置的qq - * @param {String} cd 设置的cd - */ + * 设置CD + * @param {*} e oicq + * @param {string} qq 设置的qq + * @param {string} cd 设置的cd + */ setUserCd (e, qq, cd) { let data = Data.readJSON('setu_s.json', this.root) @@ -209,10 +209,10 @@ export default new class setu { } /** - * @description: 设置r18 - * @param {String|Number} groupID 群聊id为假时设置私聊 - * @param {Boolean} isopen 开启或关闭 - */ + * 设置r18 + * @param {string | number} groupID 群聊id为假时设置私聊 + * @param {boolean} isopen 开启或关闭 + */ setR18 (groupID, isopen) { let data = Data.readJSON(`setu${groupID ? '' : '_s'}.json`, this.root) if (groupID) { @@ -231,10 +231,10 @@ export default new class setu { } /** - * @description: 获取现有设置 - * @param {*} e oicq - * @return {*} - */ + * 获取现有设置 + * @param {*} e oicq + * @returns {*} + */ getSeSeConfig (e) { let set = _.cloneDeep(this.def) set.cd = this.getCfgCd(e.user_id, e.group_id) diff --git a/package.json b/package.json index 75e3855..901b63f 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "eslint": "^8.57.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.29.1", + "eslint-plugin-jsdoc": "^48.2.1", "eslint-plugin-n": "^16.6.2", "eslint-plugin-promise": "^6.1.1", "husky": "^9.0.11", diff --git a/tools/cronValidate.js b/tools/cronValidate.js index 544723e..c0fc56c 100644 --- a/tools/cronValidate.js +++ b/tools/cronValidate.js @@ -7,6 +7,10 @@ cron表达式为秒,分,时,日,月,周,年 */ // 返回错误信息用 let message = '' +/** + * + * @param cronExpression + */ export default function cronValidate (cronExpression) { // 先将cron表达式进行分割 let cronParams = cronExpression.split(' ') @@ -68,21 +72,37 @@ export default function cronValidate (cronExpression) { } // 检查秒的函数方法 +/** + * + * @param secondsField + */ function checkSecondsField (secondsField) { return checkField(secondsField, 0, 59, '秒') } // 检查分的函数方法 +/** + * + * @param minutesField + */ function checkMinutesField (minutesField) { return checkField(minutesField, 0, 59, '分') } // 检查小时的函数方法 +/** + * + * @param hoursField + */ function checkHoursField (hoursField) { return checkField(hoursField, 0, 23, '时') } // 检查日期的函数方法 +/** + * + * @param dayOfMonthField + */ function checkDayOfMonthField (dayOfMonthField) { if (dayOfMonthField == '?') { return true @@ -98,6 +118,10 @@ function checkDayOfMonthField (dayOfMonthField) { } // 检查月份的函数方法 +/** + * + * @param monthsField + */ function checkMonthsField (monthsField) { // 月份简写处理 if (monthsField != '*') { @@ -120,6 +144,10 @@ function checkMonthsField (monthsField) { } // 星期验证 +/** + * + * @param dayOfWeekField + */ function checkDayOfWeekField (dayOfWeekField) { dayOfWeekField = dayOfWeekField.replace('SUN', '1') dayOfWeekField = dayOfWeekField.replace('MON', '2') @@ -143,11 +171,22 @@ function checkDayOfWeekField (dayOfWeekField) { } // 检查年份的函数方法 +/** + * + * @param yearField + */ function checkYearField (yearField) { return checkField(yearField, 1970, 2099, '年的') } // 通用的检查值的大小范围的方法( - , / *) +/** + * + * @param value + * @param minimal + * @param maximal + * @param attribute + */ function checkField (value, minimal, maximal, attribute) { // 校验值中是否有“-”,如果有“-”的话,下标会>0 if (value.indexOf('-') > -1) { @@ -168,6 +207,14 @@ function checkField (value, minimal, maximal, attribute) { } // 检测是否是整数以及是否在范围内,参数:检测的值,下限,上限,是否检查端点,检查的属性 +/** + * + * @param value + * @param minimal + * @param maximal + * @param checkExtremity + * @param attribute + */ function checkIntValue (value, minimal, maximal, checkExtremity, attribute) { try { // 用10进制犯法来进行整数转换 @@ -187,6 +234,13 @@ function checkIntValue (value, minimal, maximal, checkExtremity, attribute) { } } // 检验枚举类型的参数是否正确 +/** + * + * @param value + * @param minimal + * @param maximal + * @param attribute + */ function checkListField (value, minimal, maximal, attribute) { let st = value.split(',') let values = new Array(st.length) @@ -232,6 +286,13 @@ function checkListField (value, minimal, maximal, attribute) { } // 检验循环 +/** + * + * @param value + * @param minimal + * @param maximal + * @param attribute + */ function checkIncrementField (value, minimal, maximal, attribute) { if (value.split('/').length > 2) { return (attribute + "中的参数只能有一个'/'") @@ -257,6 +318,13 @@ function checkIncrementField (value, minimal, maximal, attribute) { } // 检验范围 +/** + * + * @param params + * @param minimal + * @param maximal + * @param attribute + */ function checkRangeAndCycle (params, minimal, maximal, attribute) { // 校验“-”符号是否只有一个 if (params.split('-').length > 2) { @@ -310,6 +378,14 @@ function checkRangeAndCycle (params, minimal, maximal, attribute) { } // 检查日中的特殊字符 +/** + * + * @param value + * @param letter + * @param minimalBefore + * @param maximalBefore + * @param attribute + */ function checkFieldWithLetter (value, letter, minimalBefore, maximalBefore, attribute) { // 判断是否只有一个字母 for (let i = 0; i < value.length; i++) { @@ -367,6 +443,14 @@ function checkFieldWithLetter (value, letter, minimalBefore, maximalBefore, attr } // 检查星期中的特殊字符 +/** + * + * @param value + * @param letter + * @param minimalBefore + * @param maximalBefore + * @param attribute + */ function checkFieldWithLetterWeek (value, letter, minimalBefore, maximalBefore, attribute) { // 判断是否只有一个字母 for (let i = 0; i < value.length; i++) { diff --git a/tools/uploadRecord.js b/tools/uploadRecord.js index 4ffc591..616da52 100644 --- a/tools/uploadRecord.js +++ b/tools/uploadRecord.js @@ -18,6 +18,12 @@ try { core = (await import('icqq').catch(() => {}))?.core } +/** + * + * @param record_url + * @param seconds + * @param transcoding + */ async function uploadRecord (record_url, seconds = 0, transcoding = true) { if (!Contactable) return segment.record(record_url) const result = await getPttBuffer(record_url, Bot.config.ffmpeg_path, transcoding) @@ -95,6 +101,12 @@ async function uploadRecord (record_url, seconds = 0, transcoding = true) { export default uploadRecord +/** + * + * @param file + * @param ffmpeg + * @param transcoding + */ async function getPttBuffer (file, ffmpeg = 'ffmpeg', transcoding = true) { let buffer let time @@ -158,6 +170,11 @@ async function getPttBuffer (file, ffmpeg = 'ffmpeg', transcoding = true) { return { buffer, time } } +/** + * + * @param file + * @param ffmpeg + */ async function getAudioTime (file, ffmpeg = 'ffmpeg') { return new Promise((resolve, _reject) => { (0, child_process.exec)(`${ffmpeg} -i "${file}"`, async (_error, _stdout, stderr) => { @@ -186,6 +203,11 @@ async function getAudioTime (file, ffmpeg = 'ffmpeg') { }) } +/** + * + * @param file + * @param ffmpeg + */ async function audioTrans (file, ffmpeg = 'ffmpeg') { return new Promise((resolve, reject) => { const tmpfile = path.join(TMP_DIR, (0, uuid)()); @@ -202,6 +224,10 @@ async function audioTrans (file, ffmpeg = 'ffmpeg') { }) } +/** + * + * @param file + */ async function read7Bytes (file) { const fd = await fs.promises.open(file, 'r') const buf = (await fd.read(Buffer.alloc(7), 0, 7, 0)).buffer @@ -209,11 +235,18 @@ async function read7Bytes (file) { return buf } +/** + * + */ function uuid () { let hex = crypto.randomBytes(16).toString('hex') return hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20) } +/** + * + * @param ip + */ function int32ip2str (ip) { if (typeof ip === 'string') { return ip } ip = ip & 0xffffffff @@ -232,7 +265,10 @@ const TMP_DIR = os.tmpdir() /** no operation */ const NOOP = () => { } -/** md5 hash */ +/** + * md5 hash + * @param data + */ const md5 = (data) => (0, crypto.createHash)('md5').update(data).digest() errors.LoginErrorCode = errors.drop = errors.ErrorCode = void 0 @@ -284,6 +320,11 @@ const ErrorMessage = { 120: '在该群被禁言', 121: 'AT全体剩余次数不足' } +/** + * + * @param code + * @param message + */ function drop (code, message) { if (!message || !message.length) { message = ErrorMessage[code] } throw new core.ApiRejection(code, message)