mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-12-05 15:41:56 +00:00
feat:完善关键词匹配模式
This commit is contained in:
parent
93aae10411
commit
92bfe8087c
@ -39,15 +39,13 @@ export class crystelfAI extends plugin {
|
|||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
logger.info('[crystelf-ai] 初始化完成');
|
logger.info('[crystelf-ai] 初始化完成');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.err(`[crystelf-ai] 初始化失败: ${error.message}`);
|
logger.error(`[crystelf-ai] 初始化失败: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async index(e) {
|
async index(e) {
|
||||||
try {
|
try {
|
||||||
if (!this.isInitialized) {
|
//logger.info('111')
|
||||||
await this.init();
|
|
||||||
}
|
|
||||||
const config = await ConfigControl.get();
|
const config = await ConfigControl.get();
|
||||||
const aiConfig = config?.ai;
|
const aiConfig = config?.ai;
|
||||||
if (!config?.config?.ai) {
|
if (!config?.config?.ai) {
|
||||||
@ -102,7 +100,7 @@ export class crystelfAI extends plugin {
|
|||||||
*/
|
*/
|
||||||
async processMessage(userMessage, e, aiConfig) {
|
async processMessage(userMessage, e, aiConfig) {
|
||||||
const mode = aiConfig?.mode || 'mix';
|
const mode = aiConfig?.mode || 'mix';
|
||||||
|
logger.info(`[crystelf-ai] 群${e.group_id} 用户${e.user_id}使用${mode}进行回复..`)
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'keyword':
|
case 'keyword':
|
||||||
return await this.handleKeywordMode(userMessage, e);
|
return await this.handleKeywordMode(userMessage, e);
|
||||||
|
|||||||
@ -81,10 +81,12 @@ class KeywordMatcher {
|
|||||||
*/
|
*/
|
||||||
async matchKeywords(message, type = 'ai') {
|
async matchKeywords(message, type = 'ai') {
|
||||||
if (!message || !this.isInitialized) {
|
if (!message || !this.isInitialized) {
|
||||||
|
logger.warn('[crystelf-ai] 关键词回复出现问题,请检查消息或联系帮助..')
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const keywords = await this.getKeywordsList(type);
|
const keywords = await this.getKeywordsList(type);
|
||||||
|
//logger.info(keywords);
|
||||||
if (!keywords || keywords.length === 0) {
|
if (!keywords || keywords.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,18 +10,18 @@ const Words = {
|
|||||||
async getWordsList(type){
|
async getWordsList(type){
|
||||||
const coreConfig = await ConfigControl.get()?.coreConfig;
|
const coreConfig = await ConfigControl.get()?.coreConfig;
|
||||||
const coreUrl = coreConfig.coreUrl;
|
const coreUrl = coreConfig.coreUrl;
|
||||||
return await axios.post(`${coreUrl}/api/words/list`, {
|
return await (await axios.post(`${coreUrl}/api/words/list`, {
|
||||||
type: type,
|
type: type,
|
||||||
})?.data?.data;
|
}))?.data?.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async getWord(type,name){
|
async getWord(type,name){
|
||||||
const coreConfig = await ConfigControl.get()?.coreConfig;
|
const coreConfig = await ConfigControl.get()?.coreConfig;
|
||||||
const coreUrl = coreConfig.coreUrl;
|
const coreUrl = coreConfig.coreUrl;
|
||||||
return await axios.post(`${coreUrl}/api/words/getText`, {
|
return await (await axios.post(`${coreUrl}/api/words/getText`, {
|
||||||
type: type,
|
type: type,
|
||||||
id: name
|
id: name
|
||||||
})?.data?.data;
|
}))?.data?.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user