add open dm to user menu

This commit is contained in:
ouwou
2020-11-08 01:23:50 -05:00
parent f124626a6d
commit 67ee799f04
6 changed files with 45 additions and 0 deletions

View File

@@ -404,6 +404,23 @@ void DiscordClient::UpdateStatus(const std::string &status, bool is_afk, const A
m_websocket.Send(nlohmann::json(msg));
}
void DiscordClient::CreateDM(Snowflake user_id) {
// actual client uses an array called recipients
CreateDMObject obj;
obj.Recipients.push_back(user_id);
m_http.MakePOST("/users/@me/channels", nlohmann::json(obj).dump(), [](auto) {});
}
std::optional<Snowflake> DiscordClient::FindDM(Snowflake user_id) {
const auto &channels = m_store.GetChannels();
for (const auto &[id, channel] : channels) {
if (channel.Recipients.size() == 1 && channel.Recipients[0].ID == user_id)
return id;
}
return std::nullopt;
}
void DiscordClient::UpdateToken(std::string token) {
if (!IsStarted()) {
m_token = token;