diff --git a/apps/draw.js b/apps/draw.js index 3341ad0..1539c97 100644 --- a/apps/draw.js +++ b/apps/draw.js @@ -21,6 +21,11 @@ export class dalle extends plugin { } async draw (e) { + let ttl = await redis.ttl(`CHATGPT:DRAW:${e.sender.user_id}`) + if (ttl > 0 && !e.isMaster) { + this.reply(`冷却中,请${ttl}秒后再试`) + return false + } let splits = _.split(e.msg, '图', 2) if (splits.length < 2) { this.reply('请带上绘图要求') @@ -32,6 +37,7 @@ export class dalle extends plugin { this.reply('大小不符合要求,必须是256x256/512x512/1024x1024中的一个') return false } + await redis.set(`CHATGPT:DRAW:${e.sender.user_id}`, 'c', {EX: 30}) let priceMap = { '1024x1024': 0.02, '512x512': 0.018, @@ -48,6 +54,7 @@ export class dalle extends plugin { } } catch (err) { this.reply(`绘图失败: err`, true) + await redis.del(`CHATGPT:DRAW:${e.sender.user_id}`) } diff --git a/config/config.example.js b/config/config.example.js index a24d6ae..c462d85 100644 --- a/config/config.example.js +++ b/config/config.example.js @@ -28,6 +28,8 @@ export default { // cacheUrl: 'https://content.alcedogroup.com', // 图片内容渲染服务器开启预制访问代码,当渲染服务器访问较慢时可以开启,但无法保证远程渲染是否成功 // cacheEntry: false, + // 绘图指令的CD时间,主人不受限制 + // drawCD: 30, // *********************************************************************************************************************************** // 以下为API方式(默认)的配置 * // *********************************************************************************************************************************** diff --git a/utils/config.js b/utils/config.js index 554a3ad..97b280e 100644 --- a/utils/config.js +++ b/utils/config.js @@ -13,6 +13,7 @@ const defaultConfig = { cacheUrl: 'https://content.alcedogroup.com', cacheEntry: false, apiKey: '', + drawCD: 30, model: '', api: 'https://chatgpt.duti.tech/api/conversation', apiBaseUrl: 'https://chatgpt.duti.tech/api', @@ -35,28 +36,28 @@ const defaultConfig = { const _path = process.cwd() let config = {} if (fs.existsSync(`${_path}/plugins/chatgpt-plugin/config/config.js`)) { - const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/config/config.js`); - config = (await import(`file://${fullPath}`)).default; + const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/config/config.js`) + config = (await import(`file://${fullPath}`)).default } else if (fs.existsSync(`${_path}/plugins/chatgpt-plugin/config/index.js`)) { // 兼容旧版本 - const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/config/index.js`); - config = (await import(`file://${fullPath}`)).Config; + const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/config/index.js`) + config = (await import(`file://${fullPath}`)).Config } config = Object.assign({}, defaultConfig, config) export const Config = new Proxy(config, { - set(target, property, value) { - target[property] = value; - const change = lodash.transform(target, function(result, value, key) { - if (!lodash.isEqual(value, defaultConfig[key])) { - result[key] = value; - } - }); + set (target, property, value) { + target[property] = value + const change = lodash.transform(target, function (result, value, key) { + if (!lodash.isEqual(value, defaultConfig[key])) { + result[key] = value + } + }) try { fs.writeFileSync(`${_path}/plugins/chatgpt-plugin/config/config.js`, `export default ${JSON.stringify(change, '', '\t')}`, { flag: 'w' }) } catch (err) { console.error(err) - return false; + return false } - return true; - }, -}); \ No newline at end of file + return true + } +})