Update and add some types in support of the backend (#507)
This commit is contained in:
parent
a7fc00df29
commit
b4a8082f29
|
@ -8,8 +8,8 @@ use serde_aux::prelude::deserialize_string_from_number;
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use crate::types::Shared;
|
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
|
PermissionFlags, Shared,
|
||||||
entities::{GuildMember, User},
|
entities::{GuildMember, User},
|
||||||
utils::Snowflake,
|
utils::Snowflake,
|
||||||
};
|
};
|
||||||
|
@ -148,14 +148,20 @@ pub struct Tag {
|
||||||
pub struct PermissionOverwrite {
|
pub struct PermissionOverwrite {
|
||||||
pub id: Snowflake,
|
pub id: Snowflake,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
#[serde(deserialize_with = "deserialize_string_from_number")]
|
pub overwrite_type: PermissionOverwriteType,
|
||||||
pub overwrite_type: String,
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[serde(deserialize_with = "deserialize_string_from_number")]
|
pub allow: PermissionFlags,
|
||||||
pub allow: String,
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[serde(deserialize_with = "deserialize_string_from_number")]
|
pub deny: PermissionFlags,
|
||||||
pub deny: String,
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize_repr, Deserialize_repr, Clone, PartialEq, Eq, PartialOrd)]
|
||||||
|
#[repr(u8)]
|
||||||
|
/// # Reference
|
||||||
|
pub enum PermissionOverwriteType {
|
||||||
|
Role = 0,
|
||||||
|
Member = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||||
|
@ -260,3 +266,12 @@ pub enum ChannelType {
|
||||||
// TODO: Couldn't find reference
|
// TODO: Couldn't find reference
|
||||||
Unhandled = 255,
|
Unhandled = 255,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// # Reference
|
||||||
|
/// See <https://docs.discord.sex/resources/message#followed-channel-object>
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
|
||||||
|
pub struct FollowedChannel {
|
||||||
|
pub channel_id: Snowflake,
|
||||||
|
pub webhook_id: Snowflake
|
||||||
|
}
|
|
@ -71,7 +71,7 @@ pub struct RoleTags {
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Debug, Default, Clone, Hash, PartialEq, Eq, chorus_macros::SerdeBitFlags)]
|
#[derive(Debug, Default, Clone, Hash, PartialEq, Eq, PartialOrd, chorus_macros::SerdeBitFlags)]
|
||||||
#[cfg_attr(feature = "sqlx", derive(chorus_macros::SqlxBitFlags))]
|
#[cfg_attr(feature = "sqlx", derive(chorus_macros::SqlxBitFlags))]
|
||||||
/// Permissions limit what users of certain roles can do on a Guild to Guild basis.
|
/// Permissions limit what users of certain roles can do on a Guild to Guild basis.
|
||||||
///
|
///
|
||||||
|
|
|
@ -32,13 +32,13 @@ use crate::types::{
|
||||||
pub struct Webhook {
|
pub struct Webhook {
|
||||||
pub id: Snowflake,
|
pub id: Snowflake,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub webhook_type: i32,
|
pub webhook_type: WebhookType,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub avatar: String,
|
pub avatar: String,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
pub guild_id: Snowflake,
|
pub guild_id: Snowflake,
|
||||||
pub channel_id: Snowflake,
|
pub channel_id: Snowflake,
|
||||||
pub application_id: Snowflake,
|
pub application_id: Option<Snowflake>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
#[cfg_attr(feature = "sqlx", sqlx(skip))]
|
||||||
pub user: Option<Shared<User>>,
|
pub user: Option<Shared<User>>,
|
||||||
|
@ -48,3 +48,13 @@ pub struct Webhook {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub url: Option<String>,
|
pub url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
|
||||||
|
#[repr(u8)]
|
||||||
|
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
|
||||||
|
pub enum WebhookType {
|
||||||
|
#[default]
|
||||||
|
Incoming = 1,
|
||||||
|
ChannelFollower = 2,
|
||||||
|
Application = 3,
|
||||||
|
}
|
|
@ -177,3 +177,15 @@ pub struct ModifyChannelPositionsSchema {
|
||||||
pub lock_permissions: Option<bool>,
|
pub lock_permissions: Option<bool>,
|
||||||
pub parent_id: Option<Snowflake>,
|
pub parent_id: Option<Snowflake>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// See <https://docs.discord.sex/resources/channel#follow-channel>
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Clone, Default, PartialOrd, Ord, PartialEq, Eq)]
|
||||||
|
pub struct AddFollowingChannelSchema {
|
||||||
|
pub webhook_channel_id: Snowflake,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize, Clone, Default, PartialOrd, Ord, PartialEq, Eq)]
|
||||||
|
pub struct CreateWebhookSchema {
|
||||||
|
pub name: String,
|
||||||
|
pub avatar: Option<String>,
|
||||||
|
}
|
|
@ -2,10 +2,7 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use chorus::types::{
|
use chorus::types::{self, Channel, GetChannelMessagesSchema, MessageSendSchema, PermissionFlags, PermissionOverwrite, PermissionOverwriteType, PrivateChannelCreateSchema, RelationshipType, Snowflake};
|
||||||
self, Channel, GetChannelMessagesSchema, MessageSendSchema, PermissionFlags,
|
|
||||||
PermissionOverwrite, PrivateChannelCreateSchema, RelationshipType, Snowflake,
|
|
||||||
};
|
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
@ -69,16 +66,13 @@ async fn modify_channel() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(modified_channel.name, Some(CHANNEL_NAME.to_string()));
|
assert_eq!(modified_channel.name, Some(CHANNEL_NAME.to_string()));
|
||||||
|
|
||||||
let permission_override = PermissionFlags::from_vec(Vec::from([
|
let permission_override = PermissionFlags::MANAGE_CHANNELS | PermissionFlags::MANAGE_MESSAGES;
|
||||||
PermissionFlags::MANAGE_CHANNELS,
|
|
||||||
PermissionFlags::MANAGE_MESSAGES,
|
|
||||||
]));
|
|
||||||
let user_id: types::Snowflake = bundle.user.object.read().unwrap().id;
|
let user_id: types::Snowflake = bundle.user.object.read().unwrap().id;
|
||||||
let permission_override = PermissionOverwrite {
|
let permission_override = PermissionOverwrite {
|
||||||
id: user_id,
|
id: user_id,
|
||||||
overwrite_type: "1".to_string(),
|
overwrite_type: PermissionOverwriteType::Member,
|
||||||
allow: permission_override,
|
allow: permission_override,
|
||||||
deny: "0".to_string(),
|
deny: PermissionFlags::empty(),
|
||||||
};
|
};
|
||||||
let channel_id: Snowflake = bundle.channel.read().unwrap().id;
|
let channel_id: Snowflake = bundle.channel.read().unwrap().id;
|
||||||
Channel::modify_permissions(
|
Channel::modify_permissions(
|
||||||
|
|
Loading…
Reference in New Issue