mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-06 20:15:19 +03:00
modify role color
This commit is contained in:
@@ -315,3 +315,7 @@ radio:checked {
|
||||
box-shadow: 0 1px rgba(0, 0, 0, 0);
|
||||
color: #dddddd;
|
||||
}
|
||||
|
||||
colorswatch {
|
||||
box-shadow: 0 1px rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@@ -555,6 +555,22 @@ void DiscordClient::ModifyRoleName(Snowflake guild_id, Snowflake role_id, const
|
||||
});
|
||||
}
|
||||
|
||||
void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint32_t color, sigc::slot<void(bool success)> callback) {
|
||||
ModifyGuildRoleObject obj;
|
||||
obj.Color = color;
|
||||
m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) {
|
||||
callback(CheckCode(response));
|
||||
});
|
||||
}
|
||||
|
||||
void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk::RGBA color, sigc::slot<void(bool success)> callback) {
|
||||
uint32_t int_color = 0;
|
||||
int_color |= static_cast<uint32_t>(color.get_blue() * 255.0) << 0;
|
||||
int_color |= static_cast<uint32_t>(color.get_green() * 255.0) << 8;
|
||||
int_color |= static_cast<uint32_t>(color.get_red() * 255.0) << 16;
|
||||
ModifyRoleColor(guild_id, role_id, int_color, callback);
|
||||
}
|
||||
|
||||
std::vector<BanData> DiscordClient::GetBansInGuild(Snowflake guild_id) {
|
||||
return m_store.GetBans(guild_id);
|
||||
}
|
||||
|
||||
@@ -125,6 +125,9 @@ public:
|
||||
void RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_id);
|
||||
void ModifyRolePermissions(Snowflake guild_id, Snowflake role_id, Permission permissions, sigc::slot<void(bool success)> callback);
|
||||
void ModifyRoleName(Snowflake guild_id, Snowflake role_id, const Glib::ustring &name, sigc::slot<void(bool success)> callback);
|
||||
void ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint32_t color, sigc::slot<void(bool success)> callback);
|
||||
void ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk::RGBA color, sigc::slot<void(bool success)> callback);
|
||||
|
||||
|
||||
// real client doesn't seem to use the single role endpoints so neither do we
|
||||
template<typename Iter>
|
||||
|
||||
@@ -518,7 +518,7 @@ struct ModifyGuildMemberObject {
|
||||
struct ModifyGuildRoleObject {
|
||||
std::optional<std::string> Name;
|
||||
std::optional<Permission> Permissions;
|
||||
std::optional<int> Color;
|
||||
std::optional<uint32_t> Color;
|
||||
std::optional<bool> IsHoisted;
|
||||
std::optional<bool> Mentionable;
|
||||
|
||||
|
||||
@@ -170,11 +170,13 @@ void GuildSettingsRolesPaneRolesListItem::UpdateItem(const RoleData &role) {
|
||||
|
||||
GuildSettingsRolesPaneInfo::GuildSettingsRolesPaneInfo(Snowflake guild_id)
|
||||
: GuildID(guild_id)
|
||||
, m_layout(Gtk::ORIENTATION_VERTICAL) {
|
||||
, m_layout(Gtk::ORIENTATION_VERTICAL)
|
||||
, m_meta(Gtk::ORIENTATION_HORIZONTAL) {
|
||||
set_propagate_natural_height(true);
|
||||
set_propagate_natural_width(true);
|
||||
|
||||
Abaddon::Get().GetDiscordClient().signal_role_update().connect(sigc::mem_fun(*this, &GuildSettingsRolesPaneInfo::OnRoleUpdate));
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
discord.signal_role_update().connect(sigc::mem_fun(*this, &GuildSettingsRolesPaneInfo::OnRoleUpdate));
|
||||
|
||||
const auto cb = [this](GdkEventKey *e) -> bool {
|
||||
if (e->keyval == GDK_KEY_Return)
|
||||
@@ -192,6 +194,23 @@ GuildSettingsRolesPaneInfo::GuildSettingsRolesPaneInfo(Snowflake guild_id)
|
||||
m_role_name.set_margin_start(5);
|
||||
m_role_name.set_margin_end(5);
|
||||
|
||||
m_color_button.set_margin_top(5);
|
||||
m_color_button.set_margin_bottom(5);
|
||||
m_color_button.set_margin_start(5);
|
||||
m_color_button.set_margin_end(5);
|
||||
|
||||
m_color_button.signal_color_set().connect([this, &discord]() {
|
||||
const auto color = m_color_button.get_rgba();
|
||||
const auto cb = [this, &discord](bool success) {
|
||||
if (!success) {
|
||||
m_color_button.set_rgba(IntToRGBA(discord.GetRole(RoleID)->Color));
|
||||
Gtk::MessageDialog dlg("Failed to set role color", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
|
||||
dlg.run();
|
||||
}
|
||||
};
|
||||
discord.ModifyRoleColor(GuildID, RoleID, color, cb);
|
||||
});
|
||||
|
||||
int left_ypos = 0;
|
||||
int right_ypos = 0;
|
||||
|
||||
@@ -257,9 +276,13 @@ GuildSettingsRolesPaneInfo::GuildSettingsRolesPaneInfo(Snowflake guild_id)
|
||||
|
||||
// clang-format on
|
||||
|
||||
m_layout.add(m_role_name);
|
||||
m_meta.add(m_role_name);
|
||||
m_meta.add(m_color_button);
|
||||
m_layout.add(m_meta);
|
||||
m_layout.add(m_grid);
|
||||
add(m_layout);
|
||||
m_meta.show();
|
||||
m_color_button.show();
|
||||
m_role_name.show();
|
||||
m_layout.show();
|
||||
m_grid.show();
|
||||
@@ -271,6 +294,14 @@ void GuildSettingsRolesPaneInfo::SetRole(const RoleData &role) {
|
||||
it = m_update_connections.erase(it);
|
||||
}
|
||||
|
||||
if (role.Color != 0) {
|
||||
m_color_button.set_rgba(IntToRGBA(role.Color));
|
||||
} else {
|
||||
static Gdk::RGBA trans;
|
||||
trans.set_alpha(0.0);
|
||||
m_color_button.set_rgba(trans);
|
||||
}
|
||||
|
||||
m_role_name.set_text(role.Name);
|
||||
|
||||
RoleID = role.ID;
|
||||
@@ -285,6 +316,15 @@ void GuildSettingsRolesPaneInfo::OnRoleUpdate(Snowflake guild_id, Snowflake role
|
||||
if (guild_id != GuildID || role_id != RoleID) return;
|
||||
const auto role = *Abaddon::Get().GetDiscordClient().GetRole(RoleID);
|
||||
m_role_name.set_text(role.Name);
|
||||
|
||||
if (role.Color != 0) {
|
||||
m_color_button.set_rgba(IntToRGBA(role.Color));
|
||||
} else {
|
||||
static Gdk::RGBA trans;
|
||||
trans.set_alpha(0.0);
|
||||
m_color_button.set_rgba(trans);
|
||||
}
|
||||
|
||||
m_perms = role.Permissions;
|
||||
for (const auto [perm, btn] : m_perm_items)
|
||||
btn->set_active((role.Permissions & perm) == perm);
|
||||
|
||||
@@ -77,7 +77,9 @@ private:
|
||||
std::vector<sigc::connection> m_update_connections;
|
||||
|
||||
Gtk::Box m_layout;
|
||||
Gtk::Box m_meta;
|
||||
Gtk::Entry m_role_name;
|
||||
Gtk::ColorButton m_color_button;
|
||||
Gtk::Grid m_grid;
|
||||
|
||||
std::unordered_map<Permission, GuildSettingsRolesPanePermItem *> m_perm_items;
|
||||
|
||||
Reference in New Issue
Block a user