fix: 依赖

This commit is contained in:
ikechan8370 2023-04-20 17:10:18 +08:00
parent 3cfbe9eae7
commit e0d3395a77
2 changed files with 15 additions and 2 deletions

View file

@ -64,7 +64,11 @@ export class Entertainment extends plugin {
} }
await e.reply('在统计啦,请稍等...') await e.reply('在统计啦,请稍等...')
await redis.set('CHATGPT:WORDCLOUD:ALL', '1', { EX: 600 }) await redis.set('CHATGPT:WORDCLOUD:ALL', '1', { EX: 600 })
await makeWordcloud(e, e.group_id) try {
await makeWordcloud(e, e.group_id)
} catch (err) {
await e.reply(err)
}
await redis.del('CHATGPT:WORDCLOUD:ALL') await redis.del('CHATGPT:WORDCLOUD:ALL')
} else { } else {
await e.reply('请在群里发送此命令') await e.reply('请在群里发送此命令')

View file

@ -1,6 +1,12 @@
import nodejieba from 'nodejieba'
import { Config } from '../config.js' import { Config } from '../config.js'
let nodejieba
try {
nodejieba = await import('nodejieba').default
} catch (err) {
logger.info('未安装nodejieba娱乐功能-词云统计不可用')
}
export class Tokenizer { export class Tokenizer {
async getTodayHistory (groupId, date = new Date()) { async getTodayHistory (groupId, date = new Date()) {
if (!groupId) { if (!groupId) {
@ -32,6 +38,9 @@ export class Tokenizer {
} }
async getTodayKeywordTopK (groupId, topK = 100) { async getTodayKeywordTopK (groupId, topK = 100) {
if (!nodejieba) {
throw new Error('未安装nodejieba娱乐功能-词云统计不可用')
}
let chats = await this.getTodayHistory(groupId) let chats = await this.getTodayHistory(groupId)
let chatContent = chats let chatContent = chats
.map(c => c.raw_message .map(c => c.raw_message