diff --git a/lib/DiscordAPI/include/DiscordAPI.h b/lib/DiscordAPI/include/DiscordAPI.h index 824b898..dd29aa6 100644 --- a/lib/DiscordAPI/include/DiscordAPI.h +++ b/lib/DiscordAPI/include/DiscordAPI.h @@ -15,7 +15,24 @@ public: */ DiscordAPI(String hookUrl); - bool sendMessage(String message); + /** + * @brief send a message to the discord webhook + * @param trame trame a envoyer + * @return true la trame est bien envoyée + * @return false la trame n'est pas envoyée + */ + bool sendMessage(String trame); + + /** + * @brief envoie un embed discord avec les horaires d'ouverture et de fermeture du lab + * + * @param hStart heure d'ouverture + * @param hEnd heure de fermeture + * @return true la trame est bien envoyée + * @return false la trame n'est pas envoyée + */ + bool sendheure(String hStart, String hEnd); + private: /** diff --git a/lib/DiscordAPI/src/DiscordAPI.cpp b/lib/DiscordAPI/src/DiscordAPI.cpp index fec6ff7..86a28b7 100644 --- a/lib/DiscordAPI/src/DiscordAPI.cpp +++ b/lib/DiscordAPI/src/DiscordAPI.cpp @@ -6,9 +6,11 @@ DiscordAPI::DiscordAPI(String hookUrl){ this->httpClient = new HTTPClient(); this->wifiClient = new BearSSL::WiFiClientSecure; this->wifiClient->setInsecure(); + + randomSeed(analogRead(A0)); } -bool DiscordAPI::sendMessage(String message){ +bool DiscordAPI::sendMessage(String trame){ bool sortie = true; if(WiFi.status() != WL_CONNECTED){ @@ -18,7 +20,7 @@ bool DiscordAPI::sendMessage(String message){ this->httpClient->begin(*this->wifiClient, this->hookUrl); this->httpClient->addHeader("Content-Type", "application/json"); - int resp = this->httpClient->POST("{\"content\":\""+ message +"\"}"); + int resp = this->httpClient->POST(trame); if(resp != 204){ sortie = false; Serial.print("sending message error code : "); @@ -27,3 +29,10 @@ bool DiscordAPI::sendMessage(String message){ this->httpClient->end(); return sortie; } + + +bool DiscordAPI::sendheure(String hStart, String hEnd){ + int color = random(16777215); + String trame = "{\"embeds\": [{\"title\": \"Le Lab est ouvert !\",\"description\": \"Le Lab est ouvert de **"+ hStart +"** à **"+ hEnd +"**\",\"color\": \"" + color + "\"}]}"; + return this->sendMessage(trame); +}