forked from jmug/stoatchat
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]]
|
||||
name = "rmp"
|
||||
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 = [
|
||||
"byteorder",
|
||||
"num-traits",
|
||||
@@ -2861,7 +2861,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rmp-serde"
|
||||
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 = [
|
||||
"byteorder",
|
||||
"rmp",
|
||||
|
||||
@@ -37,7 +37,7 @@ base64 = "0.13.0"
|
||||
serde_json = "1.0.57"
|
||||
serde = { version = "1.0.115", 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
|
||||
futures = "0.3.8"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#!/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
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
pub fn if_false(t: &bool) -> bool {
|
||||
!t
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Bot {
|
||||
#[serde(rename = "_id")]
|
||||
@@ -7,6 +11,10 @@ pub struct Bot {
|
||||
pub owner: String,
|
||||
pub token: String,
|
||||
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")]
|
||||
pub interactions_url: Option<String>,
|
||||
}
|
||||
|
||||
@@ -110,7 +110,11 @@ pub struct Server {
|
||||
pub flags: Option<i32>,
|
||||
|
||||
#[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 {
|
||||
|
||||
@@ -48,6 +48,8 @@ pub async fn create_bot(user: User, info: Json<Data>) -> Result<Value> {
|
||||
owner: user.id.clone(),
|
||||
token,
|
||||
public: false,
|
||||
analytics: false,
|
||||
discoverable: false,
|
||||
interactions_url: None
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ pub struct Data {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
name: Option<String>,
|
||||
public: Option<bool>,
|
||||
analytics: Option<bool>,
|
||||
interactions_url: Option<String>,
|
||||
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()
|
||||
&& data.public.is_none()
|
||||
&& data.analytics.is_none()
|
||||
&& data.interactions_url.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);
|
||||
}
|
||||
|
||||
if let Some(analytics) = &data.analytics {
|
||||
set.insert("analytics", analytics);
|
||||
}
|
||||
|
||||
if let Some(interactions_url) = &data.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,
|
||||
|
||||
flags: None,
|
||||
nsfw: info.nsfw.unwrap_or_default()
|
||||
nsfw: info.nsfw.unwrap_or_default(),
|
||||
analytics: false,
|
||||
discoverable: false,
|
||||
};
|
||||
|
||||
Channel::TextChannel {
|
||||
|
||||
@@ -18,8 +18,8 @@ pub struct Data {
|
||||
categories: Option<Vec<Category>>,
|
||||
system_messages: Option<SystemMessageChannels>,
|
||||
remove: Option<RemoveServerField>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nsfw: Option<bool>
|
||||
nsfw: Option<bool>,
|
||||
analytics: Option<bool>,
|
||||
}
|
||||
|
||||
#[patch("/<target>", data = "<data>")]
|
||||
@@ -28,7 +28,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyRespo
|
||||
data.validate()
|
||||
.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 {});
|
||||
}
|
||||
@@ -111,6 +111,10 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyRespo
|
||||
set.insert("nsfw", nsfw);
|
||||
}
|
||||
|
||||
if let Some(analytics) = &data.analytics {
|
||||
set.insert("analytics", analytics);
|
||||
}
|
||||
|
||||
let mut operations = doc! {};
|
||||
if set.len() > 0 {
|
||||
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