Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 99519d0

Browse files
committed
Fixed core not creating users and members on message create
1 parent d09298d commit 99519d0

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

include/aegis/gateway/objects/impl/message.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ AEGIS_DECL void message::populate_self()
150150
#if !defined(AEGIS_DISABLE_ALL_CACHE)
151151
if (!is_webhook())
152152
{
153-
if ((_user == nullptr) && (_author_id > 0))
153+
if (_user == nullptr)
154154
_user = _core->find_user(_author_id);
155155
if (_user == nullptr)
156156
{

include/aegis/gateway/objects/member.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "aegis/config.hpp"
1313
#include "aegis/snowflake.hpp"
1414
#include "aegis/gateway/objects/role.hpp"
15+
#include "aegis/gateway/objects/user.hpp"
1516
#include <nlohmann/json.hpp>
1617

1718
namespace aegis
@@ -51,6 +52,7 @@ struct member
5152
std::vector<objects::role> roles;
5253
std::string nick; /**< nick of user */
5354
std::string joined_at;
55+
std::optional<user> _user;
5456
bool mute = false;
5557
bool deaf = false;
5658
};
@@ -69,6 +71,8 @@ inline void from_json(const nlohmann::json& j, member& m)
6971
m.mute = j["mute"];
7072
if (j.count("deaf") && !j["deaf"].is_null())
7173
m.deaf = j["deaf"];
74+
if (j.count("user") && !j["user"].is_null())
75+
m._user = j["user"];
7276
}
7377

7478
inline void to_json(nlohmann::json& j, const member& m)
@@ -79,6 +83,8 @@ inline void to_json(nlohmann::json& j, const member& m)
7983
j["joined_at"] = m.joined_at;
8084
j["mute"] = m.mute;
8185
j["deaf"] = m.deaf;
86+
if (m._user.has_value())
87+
j["user"] = m._user.value();
8288
}
8389
/// \endcond
8490

include/aegis/impl/core.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,19 +1276,41 @@ AEGIS_DECL void core::ws_message_create(const json & result, shards::shard * _sh
12761276
}
12771277
else
12781278
{
1279-
//todo: nullptr should result in nullopt so optional can return has_value correctly
1280-
auto m = find_user(result["d"]["author"]["id"]);
1281-
auto g = &c->get_guild();
1282-
gateway::events::message_create obj{ *_shard, std::ref(*m), std::ref(*c)/*, std::make_optional(std::ref(*g))*/ };
1279+
if (!result["d"].count("webhook_id"))
1280+
{
1281+
auto g = &c->get_guild();
1282+
auto m = find_user(result["d"]["author"]["id"]);
1283+
if (m == nullptr)
1284+
{
1285+
if (result["d"].count("member") && !result["d"]["member"].is_null())
1286+
{
1287+
gateway::objects::member u = result["d"]["member"];
1288+
u._user = result["d"]["author"];
1289+
int64_t author_id = u._user->id;
1290+
m = user_create(author_id);
1291+
m->_load_nolock(g, u, _shard);
1292+
}
1293+
}
12831294

1284-
obj.msg = result["d"];
1285-
obj.msg._core = this;
1295+
//user was previously created via presence update, but presence update only contains id
1296+
if (m->get_username().empty())
1297+
{
1298+
gateway::objects::member u = result["d"]["member"];
1299+
u._user = result["d"]["author"];
1300+
m->_load_nolock(g, u, _shard);
1301+
}
12861302

1287-
if (i_message_create_raw)
1288-
i_message_create_raw(result, _shard);
1303+
gateway::events::message_create obj{ *_shard, std::ref(*m), std::ref(*c) };
12891304

1290-
if (i_message_create)
1291-
i_message_create(obj);
1305+
obj.msg = result["d"];
1306+
obj.msg._core = this;
1307+
1308+
if (i_message_create_raw)
1309+
i_message_create_raw(result, _shard);
1310+
1311+
if (i_message_create)
1312+
i_message_create(obj);
1313+
}
12921314
}
12931315
}
12941316

include/aegis/impl/user.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ AEGIS_DECL void user::_load_nolock(guild * _guild, const json & obj, shards::sha
8080

8181
json roles = obj["roles"];
8282
for (auto & r : roles)
83-
g_info->roles.emplace_back(std::stoull(r.get<std::string>()));
83+
{
84+
if (r.is_object())
85+
g_info->roles.emplace_back(std::stoull(r["id"].get<std::string>()));
86+
else if (r.is_string())
87+
g_info->roles.emplace_back(std::stoull(r.get<std::string>()));
88+
}
8489
}
8590

8691
if (obj.count("nick") && !obj["nick"].is_null())

0 commit comments

Comments
 (0)