Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions examples/Mute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,66 +26,78 @@ int main()

bot.On<MemberMuteEvent>([&](MemberMuteEvent e)
{
// 机器人的操作不做处理
if (e.OperatorIsBot())
{
cout << "机器人禁言操作" << endl;
return;
}
auto mc = MessageChain()
.Plain("恭喜老哥 " + e.Member.MemberName + " 喜提禁言套餐!");
bot.SendMessage(e.Member.Group.GID, mc);
});

bot.On<MemberUnmuteEvent>([&](MemberUnmuteEvent e)
{
// 机器人的操作不做处理
if (e.OperatorIsBot())
{
cout << "机器人解除禁言操作" << endl;
return;
}
auto mc = MessageChain()
.Plain("恭喜老哥 " + e.Member.MemberName + " 提前出狱!");
bot.SendMessage(e.Member.Group.GID, mc);
});

bool res = false;
res = bot.MuteAll(1029259687_gid);
if (res)
try
{
bot.MuteAll(1029259687_gid);
cout << "全体禁言成功!" << endl;
}
else
catch (const exception& ex)
{
cout << "全体禁言失败" << endl;
cout << "全体禁言失败: " << ex.what() << endl;
}


MiraiBot::SleepSeconds(5);

res = bot.UnMuteAll(1029259687_gid);
if (res)
try
{
bot.UnMuteAll(1029259687_gid);
cout << "解除全体禁言成功!" << endl;
}
else
catch (const exception& ex)
{
cout << "解除全体禁言失败" << endl;
cout << "解除全体禁言失败: " << ex.what() << endl;
}

res = bot.Mute(1029259687_gid, 211795583_qq, 60);
if (res)
try
{
cout << "禁言群员成功!" << endl;
bot.Mute(1029259687_gid, 211795583_qq, 60);
cout << "禁言群成员成功!" << endl;
}
else
catch (const exception& ex)
{
cout << "禁言群员失败" << endl;
cout << "禁言群成员失败: " << ex.what() << endl;
}


MiraiBot::SleepSeconds(5);

res = bot.UnMute(1029259687_gid, 211795583_qq);
if (res)
try
{
cout << "解除禁言群员成功!" << endl;
bot.UnMute(1029259687_gid, 211795583_qq);
cout << "解除禁言群成员成功!" << endl;
}
else
catch (const exception& ex)
{
cout << "解除禁言群员失败" << endl;
cout << "解除禁言群成员失败: " << ex.what() << endl;
}


bot.EventLoop();


return 0;
}
19 changes: 13 additions & 6 deletions examples/RecallEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ int main()


bot.On<GroupRecallEvent>(
[&](GroupRecallEvent gm)
[&](GroupRecallEvent e)
{
try
{
auto mc = "刚刚有人撤回了: " + bot.GetGroupMessageFromId(gm.MessageId).MessageChain;
bot.SendMessage(gm.Group.GID, mc);
if(e.OperatorIsBot())
{
cout << "不处理原因:bot 撤回了一条消息" << endl;
return;
}
auto mc = "刚刚有人撤回了: " + bot.GetGroupMessageFromId(e.MessageId).MessageChain;
auto mid = bot.SendMessage(e.Group.GID, mc);
MiraiBot::SleepSeconds(5);
bot.Recall(mid);
}
catch (const std::exception& ex)
{
Expand All @@ -40,12 +47,12 @@ int main()
});

bot.On<FriendRecallEvent>(
[&](FriendRecallEvent gm)
[&](FriendRecallEvent e)
{
try
{
auto mc = "刚刚有人撤回了: " + bot.GetFriendMessageFromId(gm.MessageId).MessageChain;
bot.SendMessage(gm.AuthorQQ, mc);
auto mc = "刚刚有人撤回了: " + bot.GetFriendMessageFromId(e.MessageId).MessageChain;
bot.SendMessage(e.AuthorQQ, mc);
}
catch (const std::exception& ex)
{
Expand Down
8 changes: 5 additions & 3 deletions include/events/group_name_change.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#define mirai_cpp_events_group_name_change_hpp_H_

#include <nlohmann/json.hpp>
#include "defs/qq_types.hpp"
#include "event_interface.hpp"
#include "defs/group.hpp"
#include "defs/group_member.hpp"
#include "event_interface.hpp"

namespace Cyan
{
Expand Down Expand Up @@ -48,7 +47,10 @@ namespace Cyan
j["origin"] = this->OriginName;
j["current"] = this->CurrentName;
j["group"] = this->Group.ToJson();
j["operator"] = this->Operator.ToJson();
if (!operator_is_null_)
j["operator"] = this->Operator.ToJson();
else
j["operator"] = nullptr;
return j;
}

Expand Down
23 changes: 18 additions & 5 deletions include/events/group_recall_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#define mirai_cpp_events_group_recall_event_hpp_H_

#include <nlohmann/json.hpp>
#include "defs/qq_types.hpp"
#include "defs/serializable.hpp"
#include "defs/group_member.hpp"
#include "event_interface.hpp"
#include "defs/group_member.hpp"
#include "defs/qq_types.hpp"

namespace Cyan
{
Expand All @@ -25,13 +24,22 @@ namespace Cyan
return MiraiEvent::GroupRecallEvent;
}

bool OperatorIsBot() const
{
return operator_is_null_;
}

virtual bool Set(const json& j) override
{
this->Time = j["time"].get<int64_t>();
this->AuthorQQ = (QQ_t)j["authorId"].get<int64_t>();
this->MessageId = j["messageId"].get<int64_t>();
this->Group.Set(j["group"]);
this->Operator.Set(j["operator"]);
if (!j["operator"].is_null())
{
this->Operator.Set(j["operator"]);
this->operator_is_null_ = false;
}
return true;
}
virtual json ToJson() const override
Expand All @@ -42,9 +50,14 @@ namespace Cyan
j["authorId"] = (int64_t)this->AuthorQQ;
j["messageId"] = this->MessageId;
j["group"] = this->Group.ToJson();
j["operator"] = this->Operator.ToJson();
if (!operator_is_null_)
j["operator"] = this->Operator.ToJson();
else
j["operator"] = nullptr;
return j;
}
private:
bool operator_is_null_ = true;
};

}
Expand Down
23 changes: 17 additions & 6 deletions include/events/member_leave_kick.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#define mirai_cpp_events_member_leave_kick_event_hpp_H_

#include <nlohmann/json.hpp>
#include "defs/qq_types.hpp"
#include "defs/serializable.hpp"
#include "defs/group_member.hpp"
#include "event_interface.hpp"
#include "defs/group_member.hpp"

namespace Cyan
{
Expand All @@ -22,21 +20,34 @@ namespace Cyan
return MiraiEvent::MemberLeaveEventKick;
}

bool OperatorIsBot() const
{
return operator_is_null_;
}

virtual bool Set(const json& j) override
{
this->Member.Set(j["member"]);
this->Operator.Set(j["operator"]);
if (!j["operator"].is_null())
{
this->Operator.Set(j["operator"]);
this->operator_is_null_ = false;
}
return true;
}
virtual json ToJson() const override
{
json j = json::object();
j["type"] = "MemberLeaveEventKick";
j["member"] = this->Member.ToJson();
j["operator"] = this->Operator.ToJson();
if (!operator_is_null_)
j["operator"] = this->Operator.ToJson();
else
j["operator"] = nullptr;
return j;
}

private:
bool operator_is_null_ = true;
};

}
Expand Down
9 changes: 5 additions & 4 deletions include/events/member_mute_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#define mirai_cpp_events_member_mute_event_hpp_H_

#include <nlohmann/json.hpp>
#include "defs/qq_types.hpp"
#include "defs/serializable.hpp"
#include "defs/group_member.hpp"
#include "event_interface.hpp"
#include "defs/group_member.hpp"

namespace Cyan
{
Expand Down Expand Up @@ -45,7 +43,10 @@ namespace Cyan
j["type"] = "MemberMuteEvent";
j["durationSeconds"] = this->DurationSeconds;
j["member"] = this->Member.ToJson();
j["operator"] = this->Operator.ToJson();
if (!operator_is_null_)
j["operator"] = this->Operator.ToJson();
else
j["operator"] = nullptr;
return j;
}

Expand Down
9 changes: 5 additions & 4 deletions include/events/member_unmute_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#define mirai_cpp_events_member_unmute_event_hpp_H_

#include <nlohmann/json.hpp>
#include "defs/qq_types.hpp"
#include "defs/serializable.hpp"
#include "defs/group_member.hpp"
#include "event_interface.hpp"
#include "defs/group_member.hpp"

namespace Cyan
{
Expand Down Expand Up @@ -42,7 +40,10 @@ namespace Cyan
json j = json::object();
j["type"] = "MemberUnmuteEvent";
j["member"] = this->Member.ToJson();
j["operator"] = this->Operator.ToJson();
if (!operator_is_null_)
j["operator"] = this->Operator.ToJson();
else
j["operator"] = nullptr;
return j;
}

Expand Down