Skip to content

Commit

Permalink
Makes bot no longer read messages from other groups
Browse files Browse the repository at this point in the history
  • Loading branch information
WitherVictor committed Aug 13, 2024
1 parent 1662698 commit 8e02982
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ if(Boost_FOUND)
target_link_libraries(${MIRAICP_TARGET_NAME} ${Boost_LIBRARIES})
endif()

add_compile_options(-std=c++23 -Wall -Wextra -Werror)

# 将 function 下的所有文件加入编译
aux_source_directory(${MIRAICP_TARGET_NAME} function)

Expand Down
2 changes: 1 addition & 1 deletion function/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ namespace function
event.group.sendMessage
(
MessageChain("更新日志列表:") +
PlainText("https://spacestation13.fandom.com/zh/wiki/%E6%9C%8D%E5%8A%A1%E5%99%A8Log%E5%88%97%E8%A1%A8")
PlainText("https://spacestation13cn.miraheze.org/wiki/%E6%9C%8D%E5%8A%A1%E5%99%A8Log%E5%88%97%E8%A1%A8")
);
}
}
Expand Down
14 changes: 9 additions & 5 deletions function/read_group_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace function
// 假设概率为 10%
static constexpr std::size_t possibility = 10;

// 如果不是主群的消息,则不记录
if (event.group.groupId() != static_cast<QQID>(884013901ULL))
return;

// 手动解析 MiraiCode, 如果消息类型不是纯文本则返回
auto message_json = json::parse(event.message.toString());
if (message_json.at(0).at("type") != "PlainText")
Expand All @@ -25,18 +29,18 @@ namespace function
// 获得信息的字符串
auto message = message_json.at(0).at("content").get<std::string>();

// 如果消息为空, 则不记录这条消息
if (message.empty())
return;

// 如果消息内容开头是 '.' 则返回, 我们不希望 Poly 读入指令类型的信息
if (message.front() == '.')
return;

// 定义表示 URL 的 regex, 如果这条消息是一条 URL, 则直接返回
boost::regex regex("^((http[s]?|ftp):\\/)?\\/?([^:\\/\\s]+)((\\/\\w+)*\\/)([\\w\\-\\.]+[^#?\\s]+)(.*)?(#[\\w\\-]+)?$");
if (boost::regex_match(message, regex))
return;

// 如果消息为空, 则不记录这条消息
if (message.empty())
return;
return;

// 如果随机数在概率区间内, 则存入这条消息
if (range(function::engine) < possibility)
Expand Down

0 comments on commit 8e02982

Please sign in to comment.