48 lines
1.9 KiB
C++
48 lines
1.9 KiB
C++
#include "global.h"
|
|
#include "api/util.h"
|
|
|
|
void global::send(const std::string& url, dpp::cluster &bot, const dpp::message_create_t &event) {
|
|
dpp::webhook wh(url);
|
|
|
|
wh.name = event.msg.author.username;
|
|
wh.avatar = event.msg.author.get_avatar_url();
|
|
|
|
dpp::guild *g = dpp::find_guild(event.msg.guild_id);
|
|
|
|
dpp::embed msg;
|
|
msg.set_color(0xcc0887);
|
|
msg.set_author(event.msg.author.username, "", event.msg.author.get_avatar_url());
|
|
msg.set_footer("Sent by " + g->name, "");
|
|
msg.add_field("",
|
|
"[Support Server](https://discord.gg/jbne9JTJtU) ║ [Bot Invite](https://discord.com/api/oauth2/authorize?client_id=772513556116930580&permissions=321536&scope=bot)",
|
|
false);
|
|
msg.set_thumbnail("https://cdn.discordapp.com/icons/" + std::to_string(g->id) + "/" + g->icon.to_string() + ".png");
|
|
msg.set_timestamp(time(0));
|
|
msg.set_description(event.msg.content);
|
|
|
|
bot.execute_webhook(wh, dpp::message().add_embed(msg));
|
|
std::cout << "Sent message to " << wh.name;
|
|
}
|
|
|
|
void global::execute(sql::Connection &con, dpp::cluster &bot, const dpp::message_create_t &event) {
|
|
if (event.msg.author.is_bot()) return;
|
|
|
|
sql::ResultSet *res = util::getResultSet(con, "SELECT * FROM `channels` WHERE `channelId` = ?",
|
|
{event.msg.channel_id.str()});
|
|
if (!res->next()) return;
|
|
|
|
sql::ResultSet *res2 = util::getResultSet(con, "SELECT * FROM `channels` WHERE `langCode` = ? AND `roomId` = ?",
|
|
{res->getString("langCode").c_str(), res->getString("roomId").c_str()});
|
|
|
|
bot.message_delete(event.msg.id, event.msg.channel_id);
|
|
|
|
send(res->getString("webhookToken").c_str(), bot, event);
|
|
|
|
while (res2->next()) {
|
|
if (res2->getString("channelId") == res->getString("channelId")) continue;
|
|
send(res2->getString("webhookToken").c_str(), bot, event);
|
|
}
|
|
|
|
delete res;
|
|
delete res2;
|
|
} |