feat: add discoverability and analytics flags (#130)
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -2852,7 +2852,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rmp"
|
name = "rmp"
|
||||||
version = "0.8.10"
|
version = "0.8.10"
|
||||||
source = "git+https://github.com/3Hren/msgpack-rust?rev=5bf2c24203ad422233cf35b7b7bfad9f7e811814#5bf2c24203ad422233cf35b7b7bfad9f7e811814"
|
source = "git+https://github.com/insertish/msgpack-rust?rev=5bf2c24203ad422233cf35b7b7bfad9f7e811814#5bf2c24203ad422233cf35b7b7bfad9f7e811814"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
@@ -2861,7 +2861,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rmp-serde"
|
name = "rmp-serde"
|
||||||
version = "0.15.5"
|
version = "0.15.5"
|
||||||
source = "git+https://github.com/3Hren/msgpack-rust?rev=5bf2c24203ad422233cf35b7b7bfad9f7e811814#5bf2c24203ad422233cf35b7b7bfad9f7e811814"
|
source = "git+https://github.com/insertish/msgpack-rust?rev=5bf2c24203ad422233cf35b7b7bfad9f7e811814#5bf2c24203ad422233cf35b7b7bfad9f7e811814"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"rmp",
|
"rmp",
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ base64 = "0.13.0"
|
|||||||
serde_json = "1.0.57"
|
serde_json = "1.0.57"
|
||||||
serde = { version = "1.0.115", features = ["derive"] }
|
serde = { version = "1.0.115", features = ["derive"] }
|
||||||
validator = { version = "0.11", features = ["derive"] }
|
validator = { version = "0.11", features = ["derive"] }
|
||||||
rmp-serde = { git = "https://github.com/3Hren/msgpack-rust", rev = "5bf2c24203ad422233cf35b7b7bfad9f7e811814" }
|
rmp-serde = { git = "https://github.com/insertish/msgpack-rust", rev = "5bf2c24203ad422233cf35b7b7bfad9f7e811814" }
|
||||||
|
|
||||||
# async
|
# async
|
||||||
futures = "0.3.8"
|
futures = "0.3.8"
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export version=0.5.3-alpha.11
|
export version=0.5.3-alpha.12
|
||||||
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
pub fn if_false(t: &bool) -> bool {
|
||||||
|
!t
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Bot {
|
pub struct Bot {
|
||||||
#[serde(rename = "_id")]
|
#[serde(rename = "_id")]
|
||||||
@@ -7,6 +11,10 @@ pub struct Bot {
|
|||||||
pub owner: String,
|
pub owner: String,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
pub public: bool,
|
pub public: bool,
|
||||||
|
#[serde(skip_serializing_if = "if_false", default)]
|
||||||
|
pub analytics: bool,
|
||||||
|
#[serde(skip_serializing_if = "if_false", default)]
|
||||||
|
pub discoverable: bool,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub interactions_url: Option<String>,
|
pub interactions_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,11 @@ pub struct Server {
|
|||||||
pub flags: Option<i32>,
|
pub flags: Option<i32>,
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "if_false", default)]
|
#[serde(skip_serializing_if = "if_false", default)]
|
||||||
pub nsfw: bool
|
pub nsfw: bool,
|
||||||
|
#[serde(skip_serializing_if = "if_false", default)]
|
||||||
|
pub analytics: bool,
|
||||||
|
#[serde(skip_serializing_if = "if_false", default)]
|
||||||
|
pub discoverable: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
impl Server {
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ pub async fn create_bot(user: User, info: Json<Data>) -> Result<Value> {
|
|||||||
owner: user.id.clone(),
|
owner: user.id.clone(),
|
||||||
token,
|
token,
|
||||||
public: false,
|
public: false,
|
||||||
|
analytics: false,
|
||||||
|
discoverable: false,
|
||||||
interactions_url: None
|
interactions_url: None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ pub struct Data {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
public: Option<bool>,
|
public: Option<bool>,
|
||||||
|
analytics: Option<bool>,
|
||||||
interactions_url: Option<String>,
|
interactions_url: Option<String>,
|
||||||
remove: Option<RemoveBotField>,
|
remove: Option<RemoveBotField>,
|
||||||
}
|
}
|
||||||
@@ -30,6 +31,7 @@ pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<Empty
|
|||||||
|
|
||||||
if data.name.is_none()
|
if data.name.is_none()
|
||||||
&& data.public.is_none()
|
&& data.public.is_none()
|
||||||
|
&& data.analytics.is_none()
|
||||||
&& data.interactions_url.is_none()
|
&& data.interactions_url.is_none()
|
||||||
&& data.remove.is_none()
|
&& data.remove.is_none()
|
||||||
{
|
{
|
||||||
@@ -87,6 +89,10 @@ pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<Empty
|
|||||||
set.insert("public", public);
|
set.insert("public", public);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(analytics) = &data.analytics {
|
||||||
|
set.insert("analytics", analytics);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(interactions_url) = &data.interactions_url {
|
if let Some(interactions_url) = &data.interactions_url {
|
||||||
set.insert("interactions_url", interactions_url);
|
set.insert("interactions_url", interactions_url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ pub async fn req(_idempotency: IdempotencyKey, user: User, info: Json<Data>) ->
|
|||||||
banner: None,
|
banner: None,
|
||||||
|
|
||||||
flags: None,
|
flags: None,
|
||||||
nsfw: info.nsfw.unwrap_or_default()
|
nsfw: info.nsfw.unwrap_or_default(),
|
||||||
|
analytics: false,
|
||||||
|
discoverable: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Channel::TextChannel {
|
Channel::TextChannel {
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ pub struct Data {
|
|||||||
categories: Option<Vec<Category>>,
|
categories: Option<Vec<Category>>,
|
||||||
system_messages: Option<SystemMessageChannels>,
|
system_messages: Option<SystemMessageChannels>,
|
||||||
remove: Option<RemoveServerField>,
|
remove: Option<RemoveServerField>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
nsfw: Option<bool>,
|
||||||
nsfw: Option<bool>
|
analytics: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[patch("/<target>", data = "<data>")]
|
#[patch("/<target>", data = "<data>")]
|
||||||
@@ -28,7 +28,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyRespo
|
|||||||
data.validate()
|
data.validate()
|
||||||
.map_err(|error| Error::FailedValidation { error })?;
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|
||||||
if data.name.is_none() && data.description.is_none() && data.icon.is_none() && data.banner.is_none() && data.remove.is_none() && data.categories.is_none() && data.system_messages.is_none()
|
if data.name.is_none() && data.description.is_none() && data.icon.is_none() && data.banner.is_none() && data.remove.is_none() && data.categories.is_none() && data.system_messages.is_none() && data.nsfw.is_none() && data.analytics.is_none()
|
||||||
{
|
{
|
||||||
return Ok(EmptyResponse {});
|
return Ok(EmptyResponse {});
|
||||||
}
|
}
|
||||||
@@ -111,6 +111,10 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyRespo
|
|||||||
set.insert("nsfw", nsfw);
|
set.insert("nsfw", nsfw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(analytics) = &data.analytics {
|
||||||
|
set.insert("analytics", analytics);
|
||||||
|
}
|
||||||
|
|
||||||
let mut operations = doc! {};
|
let mut operations = doc! {};
|
||||||
if set.len() > 0 {
|
if set.len() > 0 {
|
||||||
operations.insert("$set", &set);
|
operations.insert("$set", &set);
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
pub const VERSION: &str = "0.5.3-alpha.11";
|
pub const VERSION: &str = "0.5.3-alpha.12";
|
||||||
|
|||||||
Reference in New Issue
Block a user