From 9733ae54c386f347e338c7854869ba2e57b113cb Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 14 Apr 2021 02:11:36 -0400 Subject: update rate limit indicator on failed message send this happens when you start the client while already rate-limited --- components/ratelimitindicator.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'components/ratelimitindicator.cpp') diff --git a/components/ratelimitindicator.cpp b/components/ratelimitindicator.cpp index 8f867ec..4d8afdc 100644 --- a/components/ratelimitindicator.cpp +++ b/components/ratelimitindicator.cpp @@ -25,6 +25,7 @@ RateLimitIndicator::RateLimitIndicator() } Abaddon::Get().GetDiscordClient().signal_message_create().connect(sigc::mem_fun(*this, &RateLimitIndicator::OnMessageCreate)); + Abaddon::Get().GetDiscordClient().signal_message_send_fail().connect(sigc::mem_fun(*this, &RateLimitIndicator::OnMessageSendFail)); } void RateLimitIndicator::SetActiveChannel(Snowflake id) { @@ -109,3 +110,15 @@ void RateLimitIndicator::OnMessageCreate(const Message &message) { UpdateIndicator(); } } + +void RateLimitIndicator::OnMessageSendFail(const std::string &nonce, float retry_after) { + if (retry_after != 0) { // failed to rate limit + const auto msg = Abaddon::Get().GetDiscordClient().GetMessage(nonce); + const auto channel_id = msg->ChannelID; + const auto channel = *Abaddon::Get().GetDiscordClient().GetChannel(channel_id); + const auto rate_limit = *channel.RateLimitPerUser; + const auto sent_time = std::chrono::steady_clock::now() - std::chrono::duration(rate_limit - std::lroundf(retry_after + 0.5f)); // + 0.5 will ceil it + m_times[channel_id] = sent_time; + UpdateIndicator(); + } +} -- cgit v1.2.3