mirror of
https://github.com/Syping/dtranslatebot.git
synced 2025-12-14 23:56:26 +01:00
use dpp::cluster::post_rest to send Webhook request
This commit is contained in:
parent
ccd2736c63
commit
7ee916537c
5 changed files with 10 additions and 30 deletions
|
|
@ -18,8 +18,7 @@
|
|||
|
||||
#include "webhook_push.h"
|
||||
|
||||
bot::webhook_push::webhook_push(const std::string &webhook, const bot::translated_message &message, dpp::cluster *bot) :
|
||||
m_message(message)
|
||||
void bot::webhook_push::run(const dpp::webhook &webhook, const bot::translated_message &message, dpp::cluster *bot)
|
||||
{
|
||||
const dpp::json json_body = {
|
||||
{"content", message.message},
|
||||
|
|
@ -28,12 +27,10 @@ bot::webhook_push::webhook_push(const std::string &webhook, const bot::translate
|
|||
};
|
||||
|
||||
try {
|
||||
dpp::http_request webhook_request(webhook, nullptr, dpp::m_post, json_body.dump(), "application/json");
|
||||
const dpp::http_request_completion_t result = webhook_request.run(bot);
|
||||
if (result.status != 204)
|
||||
std::cerr << "Webhook push returned unexpected code " << result.status << " with response: " << result.body << std::endl;
|
||||
m_content = result.body;
|
||||
m_status = result.status;
|
||||
bot->post_rest(API_PATH "/webhooks", std::to_string(webhook.id), dpp::utility::url_encode(webhook.token), dpp::m_post, json_body.dump(), [bot](dpp::json &json, const dpp::http_request_completion_t &event) {
|
||||
if (event.status != 204)
|
||||
std::cerr << "Webhook push returned unexpected code " << event.status << " with response: " << event.body << std::endl;
|
||||
});
|
||||
}
|
||||
catch (const std::exception &exception) {
|
||||
std::cerr << "Exception thrown while Webhook push: " << exception.what() << std::endl;
|
||||
|
|
@ -42,13 +39,3 @@ bot::webhook_push::webhook_push(const std::string &webhook, const bot::translate
|
|||
std::cerr << "Exception thrown while Webhook push: unknown" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string bot::webhook_push::get_content() const
|
||||
{
|
||||
return m_content;
|
||||
}
|
||||
|
||||
uint16_t bot::webhook_push::get_status() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue