Skip to content

Commit

Permalink
address reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
luan committed Dec 28, 2023
1 parent be7c607 commit 61b4ed0
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
1 change: 1 addition & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ location = "South America"
-- The URL layout is https://discord.com/api/webhooks/:id/:token
-- Leave empty if you wish to disable.
discordWebhookURL = ""
discordSendFooter = true

-- Vip System (Get more info in: https://github.com/opentibiabr/canary/pull/1063)
-- NOTE: set vipSystemEnabled to true to enable the vip system functionalities (this overrides premium checks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ function playerDeath.onDeath(player, corpse, killer, mostDamageKiller, unjustifi
-- Start Webhook Player Death
local playerName = player:getName()
local playerLevel = player:getLevel()
if not player:hasFeature(Features.DisableDiscordEvents) then
local vocation = player:vocationAbbrev()
Webhook.sendMessage(":skull_crossbones: " .. player:getMarkdownLink() .. " has died. Killed at level _" .. playerLevel .. "_ by **" .. killerName .. "**.", announcementChannels["player-kills"])
end
local vocation = player:vocationAbbrev()
Webhook.sendMessage(":skull_crossbones: " .. player:getMarkdownLink() .. " has died. Killed at level _" .. playerLevel .. "_ by **" .. killerName .. "**.", announcementChannels["player-kills"])
-- End Webhook Player Death

local deathRecords = 0
Expand Down
10 changes: 0 additions & 10 deletions data/scripts/talkactions/gm/broadcast.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
local broadcast = TalkAction("/b")

function Broadcast(text, filter)
for _, targetPlayer in ipairs(Game.getPlayers()) do
if filter and not filter(targetPlayer) then
goto continue
end
targetPlayer:sendTextMessage(MESSAGE_ADMINISTRADOR, text)
::continue::
end
end

function broadcast.onSay(player, words, param)
-- create log
logCommand(player, words, param)
Expand Down
8 changes: 4 additions & 4 deletions src/server/network/webhook/webhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ void Webhook::run() {
);
}

void Webhook::sendPayload(const std::string payload, std::string url) {
void Webhook::sendPayload(const std::string &payload, std::string url) {
std::scoped_lock lock { taskLock };
webhooks.push_back(std::make_shared<WebhookTask>(payload, url));
}

void Webhook::sendMessage(const std::string title, const std::string message, int color, std::string url, bool embed) {
void Webhook::sendMessage(const std::string &title, const std::string &message, int color, std::string url, bool embed) {
if (url.empty()) {
url = g_configManager().getString(DISCORD_WEBHOOK_URL, __FUNCTION__);
}
Expand All @@ -60,7 +60,7 @@ void Webhook::sendMessage(const std::string title, const std::string message, in
sendPayload(getPayload(title, message, color, embed), url);
}

void Webhook::sendMessage(const std::string message, std::string url) {
void Webhook::sendMessage(const std::string &message, std::string url) {
if (url.empty()) {
url = g_configManager().getString(DISCORD_WEBHOOK_URL, __FUNCTION__);
}
Expand Down Expand Up @@ -112,7 +112,7 @@ size_t Webhook::writeCallback(void* contents, size_t size, size_t nmemb, void* u
return real_size;
}

std::string Webhook::getPayload(const std::string title, const std::string message, int color, bool embed) const {
std::string Webhook::getPayload(const std::string &title, const std::string &message, int color, bool embed) const {
std::time_t now = getTimeNow();
std::string time_buf = formatDate(now);

Expand Down
8 changes: 4 additions & 4 deletions src/server/network/webhook/webhook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class Webhook {

void run();

void sendPayload(const std::string payload, std::string url);
void sendMessage(const std::string title, const std::string message, int color, std::string url = "", bool embed = true);
void sendMessage(const std::string message, std::string url = "");
void sendPayload(const std::string &payload, std::string url);
void sendMessage(const std::string &title, const std::string &message, int color, std::string url = "", bool embed = true);
void sendMessage(const std::string &message, std::string url = "");

private:
std::mutex taskLock;
Expand All @@ -44,7 +44,7 @@ class Webhook {

int sendRequest(const char* url, const char* payload, std::string* response_body) const;
static size_t writeCallback(void* contents, size_t size, size_t nmemb, void* userp);
std::string getPayload(const std::string title, const std::string message, int color, bool embed = true) const;
std::string getPayload(const std::string &title, const std::string &message, int color, bool embed = true) const;
};

constexpr auto g_webhook = Webhook::getInstance;

0 comments on commit 61b4ed0

Please sign in to comment.