forked from jmug/stoatchat
Push working draft.
This commit is contained in:
@@ -6,7 +6,7 @@ pub struct Channel {
|
||||
pub id: String,
|
||||
#[serde(rename = "type")]
|
||||
pub channel_type: u8,
|
||||
|
||||
|
||||
pub last_message: Option<String>,
|
||||
|
||||
// for Direct Messages
|
||||
@@ -15,6 +15,7 @@ pub struct Channel {
|
||||
|
||||
// for Guilds
|
||||
pub name: Option<String>,
|
||||
pub guild: Option<String>,
|
||||
|
||||
// for Guilds and Group DMs
|
||||
pub description: Option<String>,
|
||||
|
||||
@@ -1,4 +1,56 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use bson::{bson, doc};
|
||||
|
||||
use super::get_collection;
|
||||
use mongodb::options::FindOneOptions;
|
||||
|
||||
bitfield! {
|
||||
pub struct MemberPermissions(MSB0 [u8]);
|
||||
u8;
|
||||
pub get_access, set_access: 7;
|
||||
pub get_create_invite, set_create_invite: 6;
|
||||
pub get_kick_members, set_kick_members: 5;
|
||||
pub get_ban_members, set_ban_members: 4;
|
||||
pub get_read_messages, set_read_messages: 3;
|
||||
pub get_send_messages, set_send_messages: 2;
|
||||
}
|
||||
|
||||
pub fn find_member_permissions<C: Into<Option<String>>>(id: String, guild: String, channel: C) -> u8 {
|
||||
let col = get_collection("guilds");
|
||||
|
||||
match col.find_one(
|
||||
doc! {
|
||||
"_id": &guild,
|
||||
"members": {
|
||||
"$elemMatch": {
|
||||
"id": &id,
|
||||
}
|
||||
}
|
||||
},
|
||||
FindOneOptions::builder()
|
||||
.projection(
|
||||
doc! {
|
||||
"members.$": 1,
|
||||
"owner": 1,
|
||||
"default_permissions": 1,
|
||||
}
|
||||
)
|
||||
.build()
|
||||
) {
|
||||
Ok(result) => {
|
||||
if let Some(doc) = result {
|
||||
if doc.get_str("owner").unwrap() == id {
|
||||
return u8::MAX;
|
||||
}
|
||||
|
||||
doc.get_i32("default_permissions").unwrap() as u8
|
||||
} else {
|
||||
0
|
||||
}
|
||||
},
|
||||
Err(_) => 0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Member {
|
||||
@@ -24,4 +76,6 @@ pub struct Guild {
|
||||
pub channels: Vec<String>,
|
||||
pub members: Vec<Member>,
|
||||
pub invites: Vec<Invite>,
|
||||
|
||||
pub default_permissions: u32,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user