mirror of
https://github.com/uowuo/abaddon.git
synced 2024-11-10 22:20:09 +00:00
add open dm to user menu
This commit is contained in:
parent
f124626a6d
commit
67ee799f04
11
abaddon.cpp
11
abaddon.cpp
@ -64,13 +64,16 @@ int Abaddon::StartGTK() {
|
|||||||
m_user_menu_ban = Gtk::manage(new Gtk::MenuItem("Ban"));
|
m_user_menu_ban = Gtk::manage(new Gtk::MenuItem("Ban"));
|
||||||
m_user_menu_kick = Gtk::manage(new Gtk::MenuItem("Kick"));
|
m_user_menu_kick = Gtk::manage(new Gtk::MenuItem("Kick"));
|
||||||
m_user_menu_copy_id = Gtk::manage(new Gtk::MenuItem("Copy ID"));
|
m_user_menu_copy_id = Gtk::manage(new Gtk::MenuItem("Copy ID"));
|
||||||
|
m_user_menu_open_dm = Gtk::manage(new Gtk::MenuItem("Open DM"));
|
||||||
m_user_menu_insert_mention->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_insert_mention));
|
m_user_menu_insert_mention->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_insert_mention));
|
||||||
m_user_menu_ban->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_ban));
|
m_user_menu_ban->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_ban));
|
||||||
m_user_menu_kick->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_kick));
|
m_user_menu_kick->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_kick));
|
||||||
m_user_menu_copy_id->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_copy_id));
|
m_user_menu_copy_id->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_copy_id));
|
||||||
|
m_user_menu_open_dm->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_user_menu_open_dm));
|
||||||
m_user_menu->append(*m_user_menu_insert_mention);
|
m_user_menu->append(*m_user_menu_insert_mention);
|
||||||
m_user_menu->append(*m_user_menu_ban);
|
m_user_menu->append(*m_user_menu_ban);
|
||||||
m_user_menu->append(*m_user_menu_kick);
|
m_user_menu->append(*m_user_menu_kick);
|
||||||
|
m_user_menu->append(*m_user_menu_open_dm);
|
||||||
m_user_menu->append(*m_user_menu_copy_id);
|
m_user_menu->append(*m_user_menu_copy_id);
|
||||||
m_user_menu->show_all();
|
m_user_menu->show_all();
|
||||||
|
|
||||||
@ -231,6 +234,14 @@ void Abaddon::on_user_menu_copy_id() {
|
|||||||
Gtk::Clipboard::get()->set_text(std::to_string(m_shown_user_menu_id));
|
Gtk::Clipboard::get()->set_text(std::to_string(m_shown_user_menu_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Abaddon::on_user_menu_open_dm() {
|
||||||
|
const auto existing = m_discord.FindDM(m_shown_user_menu_id);
|
||||||
|
if (existing.has_value())
|
||||||
|
ActionChannelOpened(*existing);
|
||||||
|
else
|
||||||
|
m_discord.CreateDM(m_shown_user_menu_id);
|
||||||
|
}
|
||||||
|
|
||||||
void Abaddon::ActionConnect() {
|
void Abaddon::ActionConnect() {
|
||||||
if (!m_discord.IsStarted())
|
if (!m_discord.IsStarted())
|
||||||
StartDiscord();
|
StartDiscord();
|
||||||
|
@ -81,11 +81,13 @@ protected:
|
|||||||
Gtk::MenuItem *m_user_menu_ban;
|
Gtk::MenuItem *m_user_menu_ban;
|
||||||
Gtk::MenuItem *m_user_menu_kick;
|
Gtk::MenuItem *m_user_menu_kick;
|
||||||
Gtk::MenuItem *m_user_menu_copy_id;
|
Gtk::MenuItem *m_user_menu_copy_id;
|
||||||
|
Gtk::MenuItem *m_user_menu_open_dm;
|
||||||
|
|
||||||
void on_user_menu_insert_mention();
|
void on_user_menu_insert_mention();
|
||||||
void on_user_menu_ban();
|
void on_user_menu_ban();
|
||||||
void on_user_menu_kick();
|
void on_user_menu_kick();
|
||||||
void on_user_menu_copy_id();
|
void on_user_menu_copy_id();
|
||||||
|
void on_user_menu_open_dm();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DiscordClient m_discord;
|
DiscordClient m_discord;
|
||||||
|
@ -404,6 +404,23 @@ void DiscordClient::UpdateStatus(const std::string &status, bool is_afk, const A
|
|||||||
m_websocket.Send(nlohmann::json(msg));
|
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) {
|
void DiscordClient::UpdateToken(std::string token) {
|
||||||
if (!IsStarted()) {
|
if (!IsStarted()) {
|
||||||
m_token = token;
|
m_token = token;
|
||||||
|
@ -104,6 +104,8 @@ public:
|
|||||||
void KickUser(Snowflake user_id, Snowflake guild_id);
|
void KickUser(Snowflake user_id, Snowflake guild_id);
|
||||||
void BanUser(Snowflake user_id, Snowflake guild_id); // todo: reason, delete messages
|
void BanUser(Snowflake user_id, Snowflake guild_id); // todo: reason, delete messages
|
||||||
void UpdateStatus(const std::string &status, bool is_afk, const Activity &obj);
|
void UpdateStatus(const std::string &status, bool is_afk, const Activity &obj);
|
||||||
|
void CreateDM(Snowflake user_id);
|
||||||
|
std::optional<Snowflake> FindDM(Snowflake user_id); // wont find group dms
|
||||||
|
|
||||||
void UpdateToken(std::string token);
|
void UpdateToken(std::string token);
|
||||||
|
|
||||||
|
@ -164,3 +164,10 @@ void from_json(const nlohmann::json &j, PresenceUpdateMessage &m) {
|
|||||||
// JS_D("activities", m.Activities);
|
// JS_D("activities", m.Activities);
|
||||||
JS_D("client_status", m.ClientStatus);
|
JS_D("client_status", m.ClientStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json &j, const CreateDMObject &m) {
|
||||||
|
std::vector<std::string> conv;
|
||||||
|
for (const auto &id : m.Recipients)
|
||||||
|
conv.push_back(std::to_string(id));
|
||||||
|
j["recipients"] = conv;
|
||||||
|
}
|
||||||
|
@ -235,3 +235,9 @@ struct PresenceUpdateMessage {
|
|||||||
|
|
||||||
friend void from_json(const nlohmann::json &j, PresenceUpdateMessage &m);
|
friend void from_json(const nlohmann::json &j, PresenceUpdateMessage &m);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CreateDMObject {
|
||||||
|
std::vector<Snowflake> Recipients;
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json &j, const CreateDMObject &m);
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user