Restrict bots from creating servers, groups, acking messages, and making friends.
This commit is contained in:
@@ -7,6 +7,10 @@ use mongodb::options::UpdateOptions;
|
|||||||
|
|
||||||
#[put("/<target>/ack/<message>")]
|
#[put("/<target>/ack/<message>")]
|
||||||
pub async fn req(user: User, target: Ref, message: Ref) -> Result<()> {
|
pub async fn req(user: User, target: Ref, message: Ref) -> Result<()> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let target = target.fetch_channel().await?;
|
let target = target.fetch_channel().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ pub struct Data {
|
|||||||
|
|
||||||
#[post("/create", data = "<info>")]
|
#[post("/create", data = "<info>")]
|
||||||
pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let info = info.into_inner();
|
let info = info.into_inner();
|
||||||
info.validate()
|
info.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::Result;
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use rocket::serde::json::Value;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[post("/<target>")]
|
#[post("/<target>")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let target = target.fetch_invite().await?;
|
let target = target.fetch_invite().await?;
|
||||||
|
|
||||||
match target {
|
match target {
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ use crate::util::result::{Error, Result};
|
|||||||
|
|
||||||
#[put("/<target>/ack")]
|
#[put("/<target>/ack")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<()> {
|
pub async fn req(user: User, target: Ref) -> Result<()> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let target = target.fetch_server().await?;
|
let target = target.fetch_server().await?;
|
||||||
|
|
||||||
let perm = permissions::PermissionCalculator::new(&user)
|
let perm = permissions::PermissionCalculator::new(&user)
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ pub struct Data {
|
|||||||
|
|
||||||
#[post("/create", data = "<info>")]
|
#[post("/create", data = "<info>")]
|
||||||
pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
pub async fn req(user: User, info: Json<Data>) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let info = info.into_inner();
|
let info = info.into_inner();
|
||||||
info.validate()
|
info.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ pub struct Options {
|
|||||||
|
|
||||||
#[post("/settings/fetch", data = "<options>")]
|
#[post("/settings/fetch", data = "<options>")]
|
||||||
pub async fn req(user: User, options: Json<Options>) -> Result<Value> {
|
pub async fn req(user: User, options: Json<Options>) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let options = options.into_inner();
|
let options = options.into_inner();
|
||||||
let mut projection = doc! {
|
let mut projection = doc! {
|
||||||
"_id": 0,
|
"_id": 0,
|
||||||
|
|||||||
@@ -6,5 +6,9 @@ use rocket::serde::json::Value;
|
|||||||
|
|
||||||
#[get("/unreads")]
|
#[get("/unreads")]
|
||||||
pub async fn req(user: User) -> Result<Value> {
|
pub async fn req(user: User) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
Ok(json!(User::fetch_unreads(&user.id).await?))
|
Ok(json!(User::fetch_unreads(&user.id).await?))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ pub struct Options {
|
|||||||
|
|
||||||
#[post("/settings/set?<options..>", data = "<data>")]
|
#[post("/settings/set?<options..>", data = "<data>")]
|
||||||
pub async fn req(user: User, data: Json<Data>, options: Options) -> Result<()> {
|
pub async fn req(user: User, data: Json<Data>, options: Options) -> Result<()> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
let current_time = Utc::now().timestamp_millis();
|
let current_time = Utc::now().timestamp_millis();
|
||||||
let timestamp = if let Some(timestamp) = options.timestamp {
|
let timestamp = if let Some(timestamp) = options.timestamp {
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ use rocket::serde::json::Value;
|
|||||||
|
|
||||||
#[put("/<username>/friend")]
|
#[put("/<username>/friend")]
|
||||||
pub async fn req(user: User, username: String) -> Result<Value> {
|
pub async fn req(user: User, username: String) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let col = get_collection("users");
|
let col = get_collection("users");
|
||||||
let doc = col
|
let doc = col
|
||||||
.find_one(
|
.find_one(
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ use rocket::serde::json::Value;
|
|||||||
|
|
||||||
#[put("/<target>/block")]
|
#[put("/<target>/block")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let col = get_collection("users");
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
|
let col = get_collection("users");
|
||||||
let target = target.fetch_user().await?;
|
let target = target.fetch_user().await?;
|
||||||
|
|
||||||
match get_relationship(&user, &target.id) {
|
match get_relationship(&user, &target.id) {
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ pub async fn req(
|
|||||||
data: Json<Data>,
|
data: Json<Data>,
|
||||||
_ignore_id: String,
|
_ignore_id: String,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
data.validate()
|
data.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::Result;
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use rocket::serde::json::Value;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/<target>/relationship")]
|
#[get("/<target>/relationship")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
Ok(json!({ "status": get_relationship(&user, &target.id) }))
|
Ok(json!({ "status": get_relationship(&user, &target.id) }))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use crate::util::result::Result;
|
use crate::util::result::{Error, Result};
|
||||||
|
|
||||||
use rocket::serde::json::Value;
|
use rocket::serde::json::Value;
|
||||||
|
|
||||||
#[get("/relationships")]
|
#[get("/relationships")]
|
||||||
pub async fn req(user: User) -> Result<Value> {
|
pub async fn req(user: User) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
Ok(if let Some(vec) = user.relations {
|
Ok(if let Some(vec) = user.relations {
|
||||||
json!(vec)
|
json!(vec)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ use rocket::serde::json::Value;
|
|||||||
|
|
||||||
#[delete("/<target>/friend")]
|
#[delete("/<target>/friend")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
let col = get_collection("users");
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
|
let col = get_collection("users");
|
||||||
let target = target.fetch_user().await?;
|
let target = target.fetch_user().await?;
|
||||||
|
|
||||||
match get_relationship(&user, &target.id) {
|
match get_relationship(&user, &target.id) {
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ use rocket::serde::json::Value;
|
|||||||
|
|
||||||
#[delete("/<target>/block")]
|
#[delete("/<target>/block")]
|
||||||
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot)
|
||||||
|
}
|
||||||
|
|
||||||
let col = get_collection("users");
|
let col = get_collection("users");
|
||||||
let target = target.fetch_user().await?;
|
let target = target.fetch_user().await?;
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ pub enum Error {
|
|||||||
|
|
||||||
// ? Bot related errors.
|
// ? Bot related errors.
|
||||||
ReachedMaximumBots,
|
ReachedMaximumBots,
|
||||||
|
IsBot,
|
||||||
|
|
||||||
// ? General errors.
|
// ? General errors.
|
||||||
TooManyIds,
|
TooManyIds,
|
||||||
@@ -102,6 +103,7 @@ impl<'r> Responder<'r, 'static> for Error {
|
|||||||
Error::Banned => Status::Forbidden,
|
Error::Banned => Status::Forbidden,
|
||||||
|
|
||||||
Error::ReachedMaximumBots => Status::BadRequest,
|
Error::ReachedMaximumBots => Status::BadRequest,
|
||||||
|
Error::IsBot => Status::BadRequest,
|
||||||
|
|
||||||
Error::FailedValidation { .. } => Status::UnprocessableEntity,
|
Error::FailedValidation { .. } => Status::UnprocessableEntity,
|
||||||
Error::DatabaseError { .. } => Status::InternalServerError,
|
Error::DatabaseError { .. } => Status::InternalServerError,
|
||||||
|
|||||||
Reference in New Issue
Block a user