fix: remove useless thing

This commit is contained in:
ikechan8370 2024-03-09 23:37:47 +08:00
parent 5c544a5ca7
commit bd7aac0517
53 changed files with 350 additions and 2639 deletions

View file

@ -1,15 +1,8 @@
import { Config } from '../config.js'
import fs from 'fs'
import nodejieba from '@node-rs/jieba'
let nodejieba
try {
nodejieba = (await import('@node-rs/jieba')).default
nodejieba.load()
} catch (err) {
logger.info('未安装@node-rs/jieba娱乐功能-词云统计不可用')
}
export class Tokenizer {
class Tokenizer {
async getHistory (e, groupId, date = new Date(), duration = 0, userId) {
if (!groupId) {
throw new Error('no valid group id')
@ -78,6 +71,10 @@ export class Tokenizer {
if (!nodejieba) {
throw new Error('未安装node-rs/jieba娱乐功能-词云统计不可用')
}
if (!this.loaded) {
nodejieba.load()
this.loaded = true
}
// duration represents the number of hours to go back, should in range [0, 24]
let chats = await this.getHistory(e, groupId, new Date(), duration, userId)
let durationStr = duration > 0 ? `${duration}小时` : '今日'
@ -139,7 +136,7 @@ export class Tokenizer {
}
}
export class ShamrockTokenizer extends Tokenizer {
class ShamrockTokenizer extends Tokenizer {
async getHistory (e, groupId, date = new Date(), duration = 0, userId) {
logger.mark('当前使用Shamrock适配器')
if (!groupId) {
@ -227,3 +224,8 @@ function isTimestampInDateRange (timestamp, startOfSpecifiedDate, endOfSpecified
// Step 5: Compare the given timestamp with the start and end of the specified date
return timestamp >= startOfSpecifiedDate && timestamp < endOfSpecifiedDate
}
export default {
default: new Tokenizer(),
shamrock: new ShamrockTokenizer()
}

View file

@ -1,4 +1,4 @@
import { ShamrockTokenizer, Tokenizer } from './tokenizer.js'
import Tokenizer from './tokenizer.js'
import { render } from '../common.js'
export async function makeWordcloud (e, groupId, duration = 0, userId) {
@ -12,8 +12,8 @@ export async function makeWordcloud (e, groupId, duration = 0, userId) {
function getTokenizer (e) {
if (e.adapter === 'shamrock') {
return new ShamrockTokenizer()
return Tokenizer.shamrock
} else {
return new Tokenizer()
return Tokenizer.default
}
}