MCPcopy Create free account
hub / github.com/Botloader/botloader / check_bad_request

Function check_bad_request

components/runtime/src/extensions/discord.rs:327–351  ·  view source on GitHub ↗
(state: &Rc<RefCell<OpState>>, code: u16)

Source from the content-addressed store, hash-verified

325}
326
327fn check_bad_request(state: &Rc<RefCell<OpState>>, code: u16) -> Result<(), ()> {
328 if code == 401 || code == 403 || code == 429 {
329 let mut rc = state.borrow_mut();
330 let dstate = rc.borrow_mut::<DiscordOpsState>();
331 dstate.add_failed_req();
332 if dstate.should_suspend_guild() {
333 let handle = rc.borrow::<vm::vm::VmShutdownHandle>().clone();
334 let rt_ctx = rc.borrow::<RuntimeContext>().clone();
335 drop(rc);
336
337 warn!(
338 guild_id = rt_ctx.guild_id.get(),
339 "guild hit >30 invalid requests within 60s, suspending it"
340 );
341 handle.shutdown_vm(
342 vm::vm::ShutdownReason::DiscordInvalidRequestsRatelimit,
343 false,
344 );
345
346 return Err(());
347 }
348 }
349
350 Ok(())
351}
352
353pub fn handle_discord_error(state: &Rc<RefCell<OpState>>, err: twilight_http::Error) -> AnyError {
354 let kind = err.kind();

Callers 2

discord_request_retryFunction · 0.85
handle_discord_errorFunction · 0.85

Calls 3

add_failed_reqMethod · 0.80
should_suspend_guildMethod · 0.80
shutdown_vmMethod · 0.80

Tested by

no test coverage detected