Created
January 10, 2022 15:54
-
-
Save Yoric/e39b26b620e921e8ba94112c346d91ff to your computer and use it in GitHub Desktop.
User Limits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod override_rate_limits { | |
use matrix_sdk::ruma::api::ruma_api; | |
use matrix_sdk::ruma::UserId; | |
use serde::{Deserialize, Serialize}; | |
ruma_api! { | |
metadata: { | |
description: "Override rate limits", | |
method: POST, | |
name: "override_rate_limit", | |
path: "/_synapse/admin/v1/users/:user_id/override_ratelimit", | |
rate_limited: false, | |
authentication: AccessToken, | |
} | |
request: { | |
/// user ID | |
#[ruma_api(path)] | |
pub user_id: &'a UserId, | |
/// The number of actions that can be performed in a second. Defaults to 0. | |
#[serde(default, skip_serializing_if = "Option::is_none")] | |
pub messages_per_second: Option<u32>, | |
/// How many actions that can be performed before being limited. Defaults to 0. | |
#[serde(default, skip_serializing_if = "Option::is_none")] | |
pub burst_count: Option<u32> | |
} | |
response: { | |
/// Details about the user. | |
#[ruma_api(body)] | |
pub limits: UserLimits, | |
} | |
} | |
#[derive(Serialize, Deserialize, Clone, Debug)] | |
pub struct UserLimits { | |
pub messages_per_second: u32, | |
pub burst_count: u32 | |
} | |
impl<'a> Request<'a> { | |
/// Creates an `Request` with the given user ID. | |
pub fn new(user_id: &'a UserId, messages_per_second: Option<u32>, burst_count: Option<u32>) -> Self { | |
Self { user_id, messages_per_second, burst_count } | |
} | |
} | |
impl Response { | |
/// Creates a new `Response` with all parameters defaulted. | |
pub fn new(limits: UserLimits) -> Self { | |
Self { limits } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment