Skip to content

Commit

Permalink
优化qqbot相关功能启用逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
NIANIANKNIA committed Apr 22, 2024
1 parent b6e0712 commit 58bd74d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 62 deletions.
29 changes: 27 additions & 2 deletions NIAHttpBOT/src/NIAHttpBOT.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/*
You must accept Minecraft's End User Licence Agreement (EULA).
It means please do not use any content that violates the EULA for commercial purposes!
Accepting this licence means you also accept the Minecraft EULA(https://account.mojang.com/terms)
If you violate the EULA, the developer is not liable for any damages.
The developer is not responsible for you, and the developer is not obliged to write code for you, and is not liable for any consequences of your use.
In addition, you are required to comply with the terms of the AGPL-3.0 (https://github.com/Nia-Server/NiaServer-Core/blob/main/LICENSE) open source licence for this project, and the related open source agreements used by all sub-projects of this project.
If you do not accept these terms, please delete this project immediately.
authors: NIANIANKNIA && jiansyuan
email: [email protected]
Project address: https://github.com/Nia-Server/NiaServer-Core/
If you have any problems with this project, please contact the authors.
*/

#include <ctime>
#include <iostream>
Expand Down Expand Up @@ -121,9 +146,9 @@ signed int main(signed int argc, char** argv) {
else XINFO("语言配置已加载成功");
}

INFO(X("NiaHttp-BOT 监听服务器已在 ") + IPAddress + ":" + std::to_string(ServerPort) + X(" 上成功启动!"));
INFO(X("监听服务器已在 ") + IPAddress + ":" + std::to_string(ServerPort) + X(" 上成功启动!"));
//如果配置文件中启用使用qq机器人,则输出qq机器人的监听端口
if (UseQQBot) INFO(X("NiaHttp-BOT 客户端已在 ") + IPAddress + ":" + std::to_string(ClientPort) + Locate + X(" 上成功启动!"));
if (UseQQBot) INFO(X("客户端已在 ") + IPAddress + ":" + std::to_string(ClientPort) + Locate + X(" 上成功启动!"));
XINFO("项目地址:https://github.com/Nia-Server/NiaServer-Core/tree/main/NIAHttpBOT");
XINFO("项目作者:@NIANIANKNIA @jiansyuan");
XINFO("在使用中遇到问题请前往项目下的 issue 反馈,如果觉得本项目不错不妨点个 star!");
Expand Down
64 changes: 31 additions & 33 deletions NIAHttpBOT/src/QQBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ int ClientPort;
//声明qqbot
QQBot* qqbot;

void initialize() {
par.parFromFile("./NIAHttpBOT.cfg");
Locate = par.getString("Locate");
UseQQBot = par.getBool("UseQQBot");
OwnerQQ = par.getString("OwnerQQ");
QQGroup = par.getString("QQGroup");
IPAddress = par.getString("IPAddress");
ClientPort = par.getInt("ClientPort");

//初始化qqbot
qqbot = new QQBot(IPAddress, ClientPort);

}


std::vector<std::string> forbiddenWords;

//读取违禁词列表
Expand All @@ -47,9 +32,14 @@ void loadForbiddenWords(const std::string& filename) {
}
//文件打开成功,读取文件内容
std::string word;
//定义违禁词数量
int count = 0;
while (std::getline(file, word)) {
forbiddenWords.push_back(word);
count++;
}
//向控制台输出
INFO("已成功加载" + std::to_string(count) + "个违禁词!");
}

bool containsForbiddenWords(const std::string& input) {
Expand All @@ -66,28 +56,37 @@ bool containsForbiddenWords(const std::string& input) {
void main_qqbot(httplib::Server &svr)
{
//初始化变量
initialize();
par.parFromFile("./NIAHttpBOT.cfg");
//获取配置文件中的UseQQBot
UseQQBot = par.getBool("UseQQBot");
if (!UseQQBot) {
WARN("未启用QQ机器人相关功能!");
return;
};
INFO("已启用QQ机器人相关功能!");
//获取配置文件中的Locate,OwnerQQ,QQGroup,IPAddress,ClientPort
Locate = par.getString("Locate");
OwnerQQ = par.getString("OwnerQQ");
QQGroup = par.getString("QQGroup");
IPAddress = par.getString("IPAddress");
ClientPort = par.getInt("ClientPort");

//检查是否启用QQ机器人相关功能
if (UseQQBot) {
INFO("已启用QQ机器人相关功能!");
//尝试与QQ机器人建立连接
auto get_status_res = qqbot->get_status();
//检查是否成功连接到QQ机器人
if (get_status_res.status && get_status_res.good && get_status_res.online) {
INFO("已成功连接到QQ机器人!");
qqbot->send_group_message(QQGroup, "NIAHttpBOT已成功连接到QQ机器人!");
loadForbiddenWords("ForbiddenWords.txt");
} else {
WARN("QQ机器人连接失败!请检查QQ机器人是否已启动&&配置是否正确!");
WARN("如需更多帮助请前往 https://docs.mcnia.com/dev/Http-Bot.html 查看!");
return;
}
//初始化qqbot
qqbot = new QQBot(IPAddress, ClientPort);
//尝试与QQ机器人建立连接
auto get_status_res = qqbot->get_status();
//检查是否成功连接到QQ机器人
if (get_status_res.status && get_status_res.good && get_status_res.online) {
INFO("已成功连接到QQ机器人!");
qqbot->send_group_message(QQGroup, "NIAHttpBOT已成功连接到QQ机器人!");
loadForbiddenWords("ForbiddenWords.txt");
} else {
WARN("未启用QQ机器人相关功能!");
WARN("QQ机器人连接失败!请检查QQ机器人是否已启动&&配置是否正确!");
WARN("如需更多帮助请前往 https://docs.mcnia.com/dev/Http-Bot.html 查看!");
return;
}


//检查player_data.json文件是否存在,不存在则创建
std::ifstream player_data_file("player_data.json");
if (!player_data_file) {
Expand Down Expand Up @@ -241,7 +240,6 @@ void main_qqbot(httplib::Server &svr)
helpMenu += "例:#封禁 @NIANIANKNIA 1d\\n";
helpMenu += "#解封 @要解封的人: 解封指定群成员账号\\n";
helpMenu += "#改权限 @要改权限的人 <权限>: 改变指定群成员的权限\\n";
helpMenu += "power by Nia-Http-Bot";
qqbot->send_group_message(group_id, helpMenu);
return;
}
Expand Down
54 changes: 27 additions & 27 deletions development_behavior_packs/NIA_V4.0_BP/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
////////////////////////////////////////////////////////////////////////////
//您必须接受 Minecraft 的最终用户许可协议(EULA).
//它意味着请勿将任何违反 EULA 的内容用于商业用途
//接受这个许可证意味着您也接受了[Minecraft EULA](https://account.mojang.com/terms)
//如果您违反了 EULA,任何法律责任都与开发者无关
//开发者不对您负责,开发者没有义务为你编写代码、为你使用造成的任何后果负责
//另外,您需要遵守本项目的AGPL-3.0(https://github.com/Nia-Server/NiaServer-Core/blob/main/LICENSE)开源许可证条款, 以及本项目所有子项目使用的相关开源协议
//如果您不接受这些条款,请立即删除本项目
////////////////////////////////////////////////////////////////////////////
//You must accept Minecraft's End User Licence Agreement (EULA).
//It means please do not use any content that violates the EULA for commercial purposes!
//Accepting this licence means you also accept the [Minecraft EULA](https://account.mojang.com/terms)
//If you violate the EULA, the developer is not liable for any damages.
//The developer is not responsible for you, and the developer is not obliged to write code for you, and is not liable for any consequences of your use.
//In addition, you are required to comply with the terms of the AGPL-3.0 (https://github.com/Nia-Server/NiaServer-Core/blob/main/LICENSE) open source licence for this project, and the related open source agreements used by all sub-projects of this project.
//If you do not accept these terms, please delete this project immediately.
////////////////////////////////////////////////////////////////////////////
//作者: NIANIANKNIA && jiansyuan
//email: [email protected]
//项目地址:https://github.com/Nia-Server/NiaServer-Core/
//如果您在使用本项目时遇到任何问题,请联系作者
////////////////////////////////////////////////////////////////////////////
//authors: NIANIANKNIA && jiansyuan
//email: [email protected]
//Project address: https://github.com/Nia-Server/NiaServer-Core/
///If you have any problems with this project, please contact the authors
////////////////////////////////////////////////////////////////////////////
/*
Copyright (C) 2024 Nia-Server
You must accept Minecraft's End User Licence Agreement (EULA).
It means please do not use any content that violates the EULA for commercial purposes!
Accepting this licence means you also accept the Minecraft EULA(https://account.mojang.com/terms)
If you violate the EULA, the developer is not liable for any damages.
The developer is not responsible for you, and the developer is not obliged to write code for you, and is not liable for any consequences of your use.
In addition, you are required to comply with the terms of the AGPL-3.0 (https://github.com/Nia-Server/NiaServer-Core/blob/main/LICENSE) open source licence for this project, and the related open source agreements used by all sub-projects of this project.
If you do not accept these terms, please delete this project immediately.
authors: NIANIANKNIA && jiansyuan
email: [email protected]
Project address: https://github.com/Nia-Server/NiaServer-Core/
If you have any problems with this project, please contact the authors.
*/

import './chat.js'
import './menu/main.js'
Expand Down

0 comments on commit 58bd74d

Please sign in to comment.