Skip to content

Commit

Permalink
tg_cpphost: delay: Add testing for msg sending delays
Browse files Browse the repository at this point in the history
  • Loading branch information
Royna2544 committed Oct 18, 2023
1 parent d7e75bb commit b71a5aa
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,20 @@ int main(void) {
bot_sendReplyMessage(bot, message, out.str());
});
bot_AddCommandPermissive(gbot, "delay", [](const Bot &bot, const Message::Ptr &message) {
using std::chrono::seconds;
using std::chrono::high_resolution_clock;
using std::chrono::duration;
Message::Ptr sentMsg;
union time now {
.val = time(0)
}, msg{.val = message->date};
std::ostringstream ss;
ss << "Message sent at: " << msg << std::endl;
ss << "Bot processed message at: " << now << std::endl;
ss << "Diff: " << now - msg << 's';
bot_sendReplyMessage(bot, message, ss.str());
ss << "Request message sent at: " << msg << std::endl;
ss << "Received at: " << now << " Diff: " << now - msg << 's' << std::endl;
auto beforeSend = high_resolution_clock::now();
sentMsg = bot_sendReplyMessage(bot, message, ss.str());
auto afterSend = high_resolution_clock::now();
ss << "Sending reply message took: " << duration<double, std::milli>(afterSend - beforeSend).count() << "ms" << std::endl;
bot.getApi().editMessageText(ss.str(), message->chat->id, sentMsg->messageId);
});
bot_AddCommandEnforced(gbot, "starttimer", [](const Bot &bot, const Message::Ptr &message) {
enum InputState {
Expand Down

0 comments on commit b71a5aa

Please sign in to comment.