Skip to content

Commit

Permalink
feat(event): BlackInfoWarned
Browse files Browse the repository at this point in the history
新增监听事件接收warning
  • Loading branch information
mystringEmpty committed Jul 10, 2024
1 parent 51482e7 commit 29f065a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 47 deletions.
45 changes: 25 additions & 20 deletions Dice/BlackListManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,21 @@ void checkGroupWithBlackQQ(const DDBlackMark& mark, long long llQQ)
}

// warning处理队列
std::queue<fromMsg> warningQueue;
std::queue<ptr<AnysTable>> warningQueue;
// 消息发送队列锁
mutex warningMutex;

bool isLoadingExtern = false;

void AddWarning(const string& msg, long long DiceQQ, long long fromGID)
void AddWarning(const ptr<AnysTable>& warning)
{
lock_guard<std::mutex> lock_queue(warningMutex);
warningQueue.emplace(msg, DiceQQ, fromGID);
warningQueue.emplace(warning);
}

void warningHandler()
{
fromMsg warning;
ptr<AnysTable> warning;
while (Enabled)
{
if (!warningQueue.empty())
Expand All @@ -122,28 +122,33 @@ void warningHandler()
warning = warningQueue.front();
warningQueue.pop();
}
if (warning.strMsg.empty())continue;
if (warning.fromUID)console.log("接收来自" + printUser(warning.fromUID) + "的warning:" + warning.strMsg, 0,
printSTNow());
try
{
fifo_json j = fifo_json::parse(GBKtoUTF8(warning.strMsg));
if (j.is_array())
string strWarning{ warning->get_str("strWarning") };
if (!strWarning.empty()) {
long long uid = warning->get_ll("uid");
if (uid)console.log("接收来自" + printUser(uid) + "的warning:" + strWarning, 0,
printSTNow());
try
{
for (auto& it : j)
fifo_json j = fifo_json::parse(GBKtoUTF8(strWarning));
warning->set("hook", "BlackInfoWarned");
if (j.is_array())
{
for (auto& it : j){
warning->set("warning", it);
if (!fmt->call_hook_event(warning))blacklist->verify(it, uid);
}
}
else
{
blacklist->verify(it, warning.fromUID);
warning->set("warning", j);
if (!fmt->call_hook_event(warning))blacklist->verify(j, uid);
}
std::this_thread::sleep_for(100ms);
}
else
catch (...)
{
blacklist->verify(j, warning.fromUID);
console.log("warning解析失败×", 0);
}
std::this_thread::sleep_for(100ms);
}
catch (...)
{
console.log("warning解析失败×", 0);
}
}
else std::this_thread::sleep_for(200ms);
Expand Down
22 changes: 3 additions & 19 deletions Dice/BlackListManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,13 @@
/**
* 黑名单明细
* 更数据库式的管理
* Copyright (C) 2019-2023 String.Empty
* Copyright (C) 2019-2024 String.Empty
*/

#include <string>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include "filesystem.hpp"
#include "fifo_json.hpp"
#include "DiceAttrVar.h"

using std::pair;
using std::string;
using std::to_string;
using std::vector;
using std::map;
using std::multimap;
using std::set;
using std::unordered_map;
using std::unordered_set;

class DiceEvent;

Expand Down Expand Up @@ -199,5 +183,5 @@ class DDBlackMarkFactory
}
};

void AddWarning(const std::string& msg, long long DiceQQ, long long fromGID);
void AddWarning(const ptr<AnysTable>& warning);
void warningHandler();
4 changes: 2 additions & 2 deletions Dice/DiceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,8 @@ int DiceEvent::BasicOrder()
else if (strLowerMessage.substr(intMsgCnt, 7) == "warning")
{
intMsgCnt += 7;
string strWarning = readRest();
AddWarning(strWarning, fromChat.uid, fromChat.gid);
set("strWarning", readRest());
AddWarning(shared_from_this());
return 1;
}
else if (strLowerMessage.substr(intMsgCnt, 6) == "master")
Expand Down
10 changes: 6 additions & 4 deletions Dice/GlobalVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ const dict_ci<string> GlobalComment{
};
const dict_ci<> HelpDoc = {
{"更新",R"(
664:新增监听BlackInfoWarned
663:新增.rule set
662:先攻批量生成
661:优化game指令触发机制
660:优化sample嵌套
Expand Down Expand Up @@ -608,7 +610,7 @@ const dict_ci<> HelpDoc = {
.mod 模块操作)"
R"(跑团指令
.game 游戏领域
.rules 规则速查
.rule 规则设置/速查
.r 掷骰
.log 日志记录
.ob 旁观模式
Expand Down Expand Up @@ -681,9 +683,9 @@ const dict_ci<> HelpDoc = {
{"authorize","授权许可(非信任用户使用时转为向管理申请许可)\n!authorize (+[群号]) ([申请理由])\n群内原地发送可省略群号,无法自动授权时会连同理由发给管理\n默认格式为:!authorize 申请用途:[ **请写入理由** ] 我已了解Dice!基本用法,仔细阅读并保证遵守{strSelfName}的用户协议,如需停用指令使用[ **请写入指令** ],用后使用[ **请写入指令** ]送出群"},
{"开关","&bot"},
{"bot",".bot on/off开启/静默骰子(限群管理)\n.bot无视静默状态,只要插件开启且不在黑名单总是有效"},
{"规则速查","&rules"},
{"规则","&rules"},
{"rule","规则速查:.rules ([规则]):[待查词条] 或.rule set [规则]\n.rules 跳跃 //复数规则有相同词条时,择一返回\n.rules COC:大失败 //coc默认搜寻coc7的词条,dnd默认搜寻3r\n.rules dnd:语言\n.ruleset dnd //设置后优先查询dnd同名词条,无参数则清除设置"},
{"规则速查","&rule"},
{"规则","&rule"},
{"rule","规则设置/速查:.rule set [规则] 或.rules ([规则]):[待查词条]\n.ruleset dnd //设置房间规则书\n.rules 跳跃 //优先检索房间规则书,否则复数规则有相同词条时,择一返回\n.rules COC:大失败 //coc默认搜寻coc7的词条,dnd默认搜寻3r\n.rules dnd:语言"},
{"掷骰","&r"},
{"rd","&r"},
{"r","掷骰:.r [掷骰表达式] ([掷骰原因]) [掷骰表达式]:([掷骰轮数]#)[骰子个数]d骰子面数(p[惩罚骰个数])(k[取点数最大的骰子数])不带参数时视为掷一个默认骰\n合法参数要求掷骰轮数1-10,奖惩骰个数1-9,个数范围1-100,面数范围1-1000\n.r3#d\t//3轮掷骰\n.rh心理学 暗骰\n.rs1D10+1D6+3 沙鹰伤害\t//rs省略单个骰子的点数,直接给结果"},
Expand Down
4 changes: 2 additions & 2 deletions Dice/GlobalVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
* Please Do not modify Dice_Build, Dice_Ver_Without_Build, DiceRequestHeader or Dice_Ver
* To costum version info, please modify const Dice_Short_Ver or Dice_Full_Ver
*/
constexpr unsigned short Dice_Build = 662u;
inline const std::string Dice_Ver_Without_Build = "2.7.0beta8";
constexpr unsigned short Dice_Build = 664u;
inline const std::string Dice_Ver_Without_Build = "2.7.0beta9";
constexpr auto DiceRequestHeader = "Dice/2.7.0";
inline const std::string Dice_Ver = Dice_Ver_Without_Build + "(" + std::to_string(Dice_Build) + ")";
extern std::string Dice_Short_Ver;
Expand Down

0 comments on commit 29f065a

Please sign in to comment.