Skip to content

Commit

Permalink
Merge pull request #239 from Giftia/dev
Browse files Browse the repository at this point in the history
v3.6.0-fix
  • Loading branch information
Giftia authored Jul 1, 2022
2 parents 6a546fe + 790657b commit 3646e34
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
47 changes: 22 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,13 @@ async function StartQQBot() {
Constants.approve_group_invite_reg.test(event.message)
) {
const flag = event.message.match(Constants.approve_group_invite_reg)[1];
request(
`http://${GO_CQHTTP_SERVICE_API_URL}/set_group_add_request?flag=${encodeURI(
flag,
)}&type=invite&approve=1`,
function (error, _response, _body) {
if (!error) {
logger.info(
`管理员批准了群邀请请求 ${flag}`.log,
);
res.send({ reply: "已批准" });
}
},

axios.get(`http://${GO_CQHTTP_SERVICE_API_URL}/set_group_add_request?flag=${encodeURI(flag)}&type=invite&approve=1`);

logger.info(
`管理员批准了群邀请请求 ${flag}`.log,
);
res.send({ reply: "已批准" });
return 0;
}

Expand Down Expand Up @@ -536,18 +530,16 @@ async function StartQQBot() {

// 群欢迎
if (event.notice_type === "group_increase") {
const welcomeMessage = QQ_GROUP_WELCOME_MESSAGE.replace(/@/g, `[CQ:at,qq=${event.user_id}]`);
request(
`http://${GO_CQHTTP_SERVICE_API_URL}/send_group_msg?group_id=${event.group_id
}&message=${encodeURI(welcomeMessage)}`,
function (error, _response, _body) {
if (!error) {
logger.info(
`${event.user_id} 加入了群 ${event.group_id},小夜欢迎了ta`.log,
);
}
},
console.log(
`${event.user_id} 加入了群 ${event.group_id},小夜欢迎了ta`.log,
);

const welcomeMessage = QQ_GROUP_WELCOME_MESSAGE.replace(/@/g, `[CQ:at,qq=${event.user_id}]`);

axios.get(`http://${GO_CQHTTP_SERVICE_API_URL}/send_group_msg?group_id=${event.group_id}&message=${encodeURI(welcomeMessage)}`);

// 在小夜加入新群后,将新群写入群服务表
await utils.AddNewGroup(event.group_id);
return 0;
}

Expand Down Expand Up @@ -1839,11 +1831,16 @@ function StartHttpServer() {
};

/**
* 异步结巴 by@ssp97
* 异步结巴 thanks@ssp97
*/
async function ChatJiebaFuzzy(msg) {
msg = msg.replace("/", "");
msg = jieba.extract(msg, CHAT_JIEBA_LIMIT); // 按权重分词

if (msg.length === 0) {
return [];
}

let candidate = [];
let candidateNextList = [];
let candidateNextGrand = 0;
Expand Down Expand Up @@ -1907,7 +1904,7 @@ async function ChatProcess(ask) {
// 最后是分词模糊搜索
console.log("没有匹配到模糊回复,开始分词模糊搜索".log);
const jiebaCandidateList = await ChatJiebaFuzzy(ask);
if (jiebaCandidateList.length > 0) {
if (jiebaCandidateList.length > 0 && !jiebaCandidateList[0]) {
const candidateListAnswer = jiebaCandidateList[
Math.floor(Math.random() * jiebaCandidateList.length)
];
Expand Down
14 changes: 13 additions & 1 deletion plugins/system/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @name 系统工具类
* @description 各种公用函数和系统底层函数
* @version 2.0
* @version 2.1
*/
module.exports = {
/**
Expand Down Expand Up @@ -261,6 +261,18 @@ module.exports = {
}
},

/**
* 初始化小夜新加入的群的群服务
* @param {string} groupId 群id
* @returns {Promise<void>} void
*/
async AddNewGroup(groupId) {
const group = await QQGroupModel.findOne({ where: { groupId } });
if (!group) {
await QQGroupModel.create({ groupId });
}
},

/**
* 启用群服务开关
* @param {number} groupId 群id
Expand Down

0 comments on commit 3646e34

Please sign in to comment.