mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 13:36:59 +00:00
feat: add basic server limit via env var
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::variables::MAX_SERVER_COUNT;
|
||||
|
||||
use rocket::serde::json::Value;
|
||||
|
||||
@@ -8,6 +9,12 @@ pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot)
|
||||
}
|
||||
|
||||
if !User::can_acquire_server(&user.id).await? {
|
||||
Err(Error::TooManyServers {
|
||||
max: *MAX_SERVER_COUNT,
|
||||
})?
|
||||
}
|
||||
|
||||
let target = target.fetch_invite().await?;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::collections::HashMap;
|
||||
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::variables::MAX_SERVER_COUNT;
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rocket::serde::json::{Json, Value};
|
||||
@@ -27,6 +28,12 @@ pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot)
|
||||
}
|
||||
|
||||
if !User::can_acquire_server(&user.id).await? {
|
||||
Err(Error::TooManyServers {
|
||||
max: *MAX_SERVER_COUNT,
|
||||
})?
|
||||
}
|
||||
|
||||
let info = info.into_inner();
|
||||
info.validate()
|
||||
|
||||
Reference in New Issue
Block a user