forked from OpenGamers/abaddon
show slash command/APPLICATION_COMMAND messages
This commit is contained in:
@@ -221,6 +221,17 @@ void ChatMessageItemContainer::UpdateTextComponent(Gtk::TextView *tv) {
|
|||||||
case MessageType::CHANNEL_PINNED_MESSAGE:
|
case MessageType::CHANNEL_PINNED_MESSAGE:
|
||||||
b->insert_markup(s, "<span color='#999999'><i>[message pinned]</i></span>");
|
b->insert_markup(s, "<span color='#999999'><i>[message pinned]</i></span>");
|
||||||
break;
|
break;
|
||||||
|
case MessageType::APPLICATION_COMMAND: {
|
||||||
|
if (data->Application.has_value()) {
|
||||||
|
static const auto regex = Glib::Regex::create(R"(</(.*?):(\d+)>)");
|
||||||
|
Glib::MatchInfo match;
|
||||||
|
if (regex->match(data->Content, match)) {
|
||||||
|
const auto cmd = match.fetch(1);
|
||||||
|
const auto app = data->Application->Name;
|
||||||
|
b->insert_markup(s, "<i>used <span color='#697ec4'>" + cmd + "</span> with " + app + "</i>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -945,23 +956,18 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) {
|
|||||||
|
|
||||||
m_meta_ev->signal_button_press_event().connect(sigc::mem_fun(*this, &ChatMessageHeader::on_author_button_press));
|
m_meta_ev->signal_button_press_event().connect(sigc::mem_fun(*this, &ChatMessageHeader::on_author_button_press));
|
||||||
|
|
||||||
if (data->WebhookID.has_value()) {
|
if (author->IsBot || data->WebhookID.has_value()) {
|
||||||
m_extra = Gtk::manage(new Gtk::Label);
|
m_extra = Gtk::manage(new Gtk::Label);
|
||||||
m_extra->get_style_context()->add_class("message-container-extra");
|
m_extra->get_style_context()->add_class("message-container-extra");
|
||||||
m_extra->set_single_line_mode(true);
|
m_extra->set_single_line_mode(true);
|
||||||
m_extra->set_margin_start(12);
|
m_extra->set_margin_start(12);
|
||||||
m_extra->set_can_focus(false);
|
m_extra->set_can_focus(false);
|
||||||
m_extra->set_use_markup(true);
|
m_extra->set_use_markup(true);
|
||||||
m_extra->set_markup("<b>Webhook</b>");
|
|
||||||
} else if (data->Author.IsBot) {
|
|
||||||
m_extra = Gtk::manage(new Gtk::Label);
|
|
||||||
m_extra->get_style_context()->add_class("message-container-extra");
|
|
||||||
m_extra->set_single_line_mode(true);
|
|
||||||
m_extra->set_margin_start(12);
|
|
||||||
m_extra->set_can_focus(false);
|
|
||||||
m_extra->set_use_markup(true);
|
|
||||||
m_extra->set_markup("<b>BOT</b>");
|
|
||||||
}
|
}
|
||||||
|
if (author->IsBot)
|
||||||
|
m_extra->set_markup("<b>BOT</b>");
|
||||||
|
else if (data->WebhookID.has_value())
|
||||||
|
m_extra->set_markup("<b>Webhook</b>");
|
||||||
|
|
||||||
m_timestamp->set_text(data->Timestamp);
|
m_timestamp->set_text(data->Timestamp);
|
||||||
m_timestamp->set_opacity(0.5);
|
m_timestamp->set_opacity(0.5);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class DiscordClient {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static const constexpr char *DiscordGateway = "wss://gateway.discord.gg/?v=8&encoding=json&compress=zlib-stream";
|
static const constexpr char *DiscordGateway = "wss://gateway.discord.gg/?v=8&encoding=json&compress=zlib-stream";
|
||||||
static const constexpr char *DiscordAPI = "https://discord.com/api";
|
static const constexpr char *DiscordAPI = "https://discord.com/api/v8";
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DiscordClient(bool mem_store = false);
|
DiscordClient(bool mem_store = false);
|
||||||
|
|||||||
@@ -164,6 +164,25 @@ void to_json(nlohmann::json &j, const ReactionData &m) {
|
|||||||
j["emoji"] = m.Emoji;
|
j["emoji"] = m.Emoji;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json &j, MessageApplicationData &m) {
|
||||||
|
JS_D("id", m.ID);
|
||||||
|
JS_O("cover_image", m.CoverImage);
|
||||||
|
JS_D("description", m.Description);
|
||||||
|
JS_N("icon", m.Icon);
|
||||||
|
JS_D("name", m.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json &j, const MessageApplicationData &m) {
|
||||||
|
j["id"] = m.ID;
|
||||||
|
JS_IF("cover_image", m.CoverImage);
|
||||||
|
j["description"] = m.Description;
|
||||||
|
if (m.Icon == "")
|
||||||
|
j["icon"] = nullptr;
|
||||||
|
else
|
||||||
|
j["icon"] = m.Icon;
|
||||||
|
j["name"] = m.Name;
|
||||||
|
}
|
||||||
|
|
||||||
void from_json(const nlohmann::json &j, Message &m) {
|
void from_json(const nlohmann::json &j, Message &m) {
|
||||||
JS_D("id", m.ID);
|
JS_D("id", m.ID);
|
||||||
JS_D("channel_id", m.ChannelID);
|
JS_D("channel_id", m.ChannelID);
|
||||||
@@ -188,7 +207,7 @@ void from_json(const nlohmann::json &j, Message &m) {
|
|||||||
JS_O("webhook_id", m.WebhookID);
|
JS_O("webhook_id", m.WebhookID);
|
||||||
JS_D("type", m.Type);
|
JS_D("type", m.Type);
|
||||||
// JS_O("activity", m.Activity);
|
// JS_O("activity", m.Activity);
|
||||||
// JS_O("application", m.Application);
|
JS_O("application", m.Application);
|
||||||
JS_O("message_reference", m.MessageReference);
|
JS_O("message_reference", m.MessageReference);
|
||||||
JS_O("flags", m.Flags);
|
JS_O("flags", m.Flags);
|
||||||
JS_O("stickers", m.Stickers);
|
JS_O("stickers", m.Stickers);
|
||||||
@@ -212,6 +231,8 @@ void Message::from_json_edited(const nlohmann::json &j) {
|
|||||||
JS_O("pinned", IsPinned);
|
JS_O("pinned", IsPinned);
|
||||||
JS_O("webhook_id", WebhookID);
|
JS_O("webhook_id", WebhookID);
|
||||||
JS_O("type", Type);
|
JS_O("type", Type);
|
||||||
|
JS_O("application", Application);
|
||||||
|
JS_O("message_reference", MessageReference);
|
||||||
JS_O("flags", Flags);
|
JS_O("flags", Flags);
|
||||||
JS_O("stickers", Stickers);
|
JS_O("stickers", Stickers);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ enum class MessageType {
|
|||||||
GUILD_DISCOVERY_DISQUALIFIED = 14, // nope
|
GUILD_DISCOVERY_DISQUALIFIED = 14, // nope
|
||||||
GUILD_DISCOVERY_REQUALIFIED = 15, // nope
|
GUILD_DISCOVERY_REQUALIFIED = 15, // nope
|
||||||
INLINE_REPLY = 19, // kinda
|
INLINE_REPLY = 19, // kinda
|
||||||
APPLICATION_COMMAND, // nope
|
APPLICATION_COMMAND = 20, // yep
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class MessageFlags {
|
enum class MessageFlags {
|
||||||
@@ -151,6 +151,17 @@ struct ReactionData {
|
|||||||
friend void to_json(nlohmann::json &j, const ReactionData &m);
|
friend void to_json(nlohmann::json &j, const ReactionData &m);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MessageApplicationData {
|
||||||
|
Snowflake ID;
|
||||||
|
std::optional<std::string> CoverImage;
|
||||||
|
std::string Description;
|
||||||
|
std::string Icon; // null
|
||||||
|
std::string Name;
|
||||||
|
|
||||||
|
friend void from_json(const nlohmann::json &j, MessageApplicationData &m);
|
||||||
|
friend void to_json(nlohmann::json &j, const MessageApplicationData &m);
|
||||||
|
};
|
||||||
|
|
||||||
struct Message {
|
struct Message {
|
||||||
Snowflake ID;
|
Snowflake ID;
|
||||||
Snowflake ChannelID;
|
Snowflake ChannelID;
|
||||||
@@ -173,7 +184,7 @@ struct Message {
|
|||||||
std::optional<Snowflake> WebhookID;
|
std::optional<Snowflake> WebhookID;
|
||||||
MessageType Type;
|
MessageType Type;
|
||||||
// std::optional<MessageActivityData> Activity;
|
// std::optional<MessageActivityData> Activity;
|
||||||
// std::optional<MessageApplicationData> Application;
|
std::optional<MessageApplicationData> Application;
|
||||||
std::optional<MessageReferenceData> MessageReference;
|
std::optional<MessageReferenceData> MessageReference;
|
||||||
std::optional<MessageFlags> Flags = MessageFlags::NONE;
|
std::optional<MessageFlags> Flags = MessageFlags::NONE;
|
||||||
std::optional<std::vector<Sticker>> Stickers;
|
std::optional<std::vector<Sticker>> Stickers;
|
||||||
|
|||||||
@@ -203,29 +203,33 @@ void Store::SetMessage(Snowflake id, const Message &message) {
|
|||||||
Bind(m_set_msg_stmt, 14, message.WebhookID);
|
Bind(m_set_msg_stmt, 14, message.WebhookID);
|
||||||
Bind(m_set_msg_stmt, 15, static_cast<uint64_t>(message.Type));
|
Bind(m_set_msg_stmt, 15, static_cast<uint64_t>(message.Type));
|
||||||
|
|
||||||
if (message.MessageReference.has_value()) {
|
if (message.Application.has_value())
|
||||||
std::string tmp = nlohmann::json(*message.MessageReference).dump();
|
Bind(m_set_msg_stmt, 16, nlohmann::json(*message.Application).dump());
|
||||||
Bind(m_set_msg_stmt, 16, tmp);
|
else
|
||||||
} else
|
|
||||||
Bind(m_set_msg_stmt, 16, nullptr);
|
Bind(m_set_msg_stmt, 16, nullptr);
|
||||||
|
|
||||||
if (message.Flags.has_value())
|
if (message.MessageReference.has_value())
|
||||||
Bind(m_set_msg_stmt, 17, static_cast<uint64_t>(*message.Flags));
|
Bind(m_set_msg_stmt, 17, nlohmann::json(*message.MessageReference).dump());
|
||||||
else
|
else
|
||||||
Bind(m_set_msg_stmt, 17, nullptr);
|
Bind(m_set_msg_stmt, 17, nullptr);
|
||||||
|
|
||||||
if (message.Stickers.has_value()) {
|
if (message.Flags.has_value())
|
||||||
std::string tmp = nlohmann::json(*message.Stickers).dump();
|
Bind(m_set_msg_stmt, 18, static_cast<uint64_t>(*message.Flags));
|
||||||
Bind(m_set_msg_stmt, 18, tmp);
|
else
|
||||||
} else
|
|
||||||
Bind(m_set_msg_stmt, 18, nullptr);
|
Bind(m_set_msg_stmt, 18, nullptr);
|
||||||
|
|
||||||
|
if (message.Stickers.has_value())
|
||||||
|
Bind(m_set_msg_stmt, 19, nlohmann::json(*message.Stickers).dump());
|
||||||
|
else
|
||||||
|
Bind(m_set_msg_stmt, 19, nullptr);
|
||||||
|
|
||||||
if (message.Reactions.has_value()) {
|
if (message.Reactions.has_value()) {
|
||||||
std::string tmp = nlohmann::json(*message.Reactions).dump();
|
std::string tmp = nlohmann::json(*message.Reactions).dump();
|
||||||
Bind(m_set_msg_stmt, 19, tmp);
|
Bind(m_set_msg_stmt, 20, tmp);
|
||||||
} else
|
} else
|
||||||
Bind(m_set_msg_stmt, 19, nullptr);
|
Bind(m_set_msg_stmt, 20, nullptr);
|
||||||
Bind(m_set_msg_stmt, 20, message.IsDeleted());
|
Bind(m_set_msg_stmt, 21, message.IsDeleted());
|
||||||
Bind(m_set_msg_stmt, 21, message.IsEdited());
|
Bind(m_set_msg_stmt, 22, message.IsEdited());
|
||||||
|
|
||||||
if (!RunInsert(m_set_msg_stmt))
|
if (!RunInsert(m_set_msg_stmt))
|
||||||
fprintf(stderr, "message insert failed: %s\n", sqlite3_errstr(m_db_err));
|
fprintf(stderr, "message insert failed: %s\n", sqlite3_errstr(m_db_err));
|
||||||
@@ -470,21 +474,31 @@ std::optional<Message> Store::GetMessage(Snowflake id) const {
|
|||||||
uint64_t tmpi;
|
uint64_t tmpi;
|
||||||
Get(m_get_msg_stmt, 14, tmpi);
|
Get(m_get_msg_stmt, 14, tmpi);
|
||||||
ret.Type = static_cast<MessageType>(tmpi);
|
ret.Type = static_cast<MessageType>(tmpi);
|
||||||
|
|
||||||
Get(m_get_msg_stmt, 15, tmps);
|
Get(m_get_msg_stmt, 15, tmps);
|
||||||
if (tmps != "")
|
if (tmps != "")
|
||||||
ret.MessageReference = nlohmann::json::parse(tmps).get<MessageReferenceData>();
|
ret.Application = nlohmann::json::parse(tmps).get<MessageApplicationData>();
|
||||||
Get(m_get_msg_stmt, 16, tmpi);
|
|
||||||
ret.Flags = static_cast<MessageFlags>(tmpi);
|
Get(m_get_msg_stmt, 16, tmps);
|
||||||
Get(m_get_msg_stmt, 17, tmps);
|
|
||||||
if (tmps != "")
|
if (tmps != "")
|
||||||
ret.Stickers = nlohmann::json::parse(tmps).get<std::vector<Sticker>>();
|
ret.MessageReference = nlohmann::json::parse(tmps).get<MessageReferenceData>();
|
||||||
|
|
||||||
|
Get(m_get_msg_stmt, 17, tmpi);
|
||||||
|
ret.Flags = static_cast<MessageFlags>(tmpi);
|
||||||
|
|
||||||
Get(m_get_msg_stmt, 18, tmps);
|
Get(m_get_msg_stmt, 18, tmps);
|
||||||
|
if (tmps != "")
|
||||||
|
ret.Stickers = nlohmann::json::parse(tmps).get<std::vector<Sticker>>();
|
||||||
|
|
||||||
|
Get(m_get_msg_stmt, 19, tmps);
|
||||||
if (tmps != "")
|
if (tmps != "")
|
||||||
ret.Reactions = nlohmann::json::parse(tmps).get<std::vector<ReactionData>>();
|
ret.Reactions = nlohmann::json::parse(tmps).get<std::vector<ReactionData>>();
|
||||||
|
|
||||||
bool tmpb = false;
|
bool tmpb = false;
|
||||||
Get(m_get_msg_stmt, 19, tmpb);
|
|
||||||
if (tmpb) ret.SetDeleted();
|
|
||||||
Get(m_get_msg_stmt, 20, tmpb);
|
Get(m_get_msg_stmt, 20, tmpb);
|
||||||
|
if (tmpb) ret.SetDeleted();
|
||||||
|
|
||||||
|
Get(m_get_msg_stmt, 21, tmpb);
|
||||||
if (tmpb) ret.SetEdited();
|
if (tmpb) ret.SetEdited();
|
||||||
|
|
||||||
Reset(m_get_msg_stmt);
|
Reset(m_get_msg_stmt);
|
||||||
@@ -646,6 +660,7 @@ bool Store::CreateTables() {
|
|||||||
pinned BOOL,
|
pinned BOOL,
|
||||||
webhook_id INTEGER,
|
webhook_id INTEGER,
|
||||||
type INTEGER,
|
type INTEGER,
|
||||||
|
application TEXT, /* json */
|
||||||
reference TEXT, /* json */
|
reference TEXT, /* json */
|
||||||
flags INTEGER,
|
flags INTEGER,
|
||||||
stickers TEXT, /* json */
|
stickers TEXT, /* json */
|
||||||
@@ -836,7 +851,7 @@ bool Store::CreateStatements() {
|
|||||||
|
|
||||||
constexpr const char *set_msg = R"(
|
constexpr const char *set_msg = R"(
|
||||||
REPLACE INTO messages VALUES (
|
REPLACE INTO messages VALUES (
|
||||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||||
)
|
)
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user