Merge branch 'main' into perpetual/gateway-dev

This commit is contained in:
kozabrada123 2023-06-08 17:35:17 +02:00
commit 0f4eef2fb9
4 changed files with 211 additions and 38 deletions

View File

@ -43,44 +43,46 @@
- [x] Channel creation - [x] Channel creation
- [x] Channel deletion - [x] Channel deletion
- [x] [Channel management (name, description, icon, etc.)](https://github.com/polyphony-chat/chorus/issues/48) - [x] [Channel management (name, description, icon, etc.)](https://github.com/polyphony-chat/chorus/issues/48)
- [ ] Deleting messages - [ ] [Join and Leave Guilds](https://github.com/polyphony-chat/chorus/issues/45)
- [ ] Message threads - [ ] [Start DMs](https://github.com/polyphony-chat/chorus/issues/45)
- [ ] [Reactions](https://github.com/polyphony-chat/chorus/issues/85) - [ ] [Group DM creation, deletion and member management](https://github.com/polyphony-chat/chorus/issues/89)
- [ ] [Deleting messages](https://github.com/polyphony-chat/chorus/issues/91)
- [ ] [Message threads](https://github.com/polyphony-chat/chorus/issues/90)
- [x] [Reactions](https://github.com/polyphony-chat/chorus/issues/85)
- [ ] Message Search - [ ] Message Search
- [ ] Message history - [ ] Message history
- [ ] Emoji
- [ ] Stickers
- [ ] [Forum channels](https://github.com/polyphony-chat/chorus/issues/90)
### User Management ### User Management
- [ ] User profile customization - [ ] [User profile customization](https://github.com/polyphony-chat/chorus/issues/41)
- [x] Gettings users and user profiles - [x] Gettings users and user profiles
- [ ] Friend requests - [ ] [Friend requests](https://github.com/polyphony-chat/chorus/issues/92)
- [ ] Blocking users - [ ] [Blocking users](https://github.com/polyphony-chat/chorus/issues/92)
- [ ] User presence (online, offline, idle, etc.) - [ ] User presence (online, offline, idle, etc.)
- [ ] User status (custom status, etc.) - [ ] User status (custom status, etc.)
- [x] Account deletion - [x] Account deletion
### Additional Features ### Additional Features
- [ ] Emoji
- [ ] Stickers
- [ ] Forum channels
- [ ] Server discovery - [ ] Server discovery
- [ ] Server templates - [ ] Server templates
### Voice and Video ### Voice and Video
- [ ] Voice chat support - [ ] [Voice chat support](https://github.com/polyphony-chat/chorus/issues/49)
- [ ] Video chat support - [ ] [Video chat support](https://github.com/polyphony-chat/chorus/issues/49)
### Permissions and Roles ### Permissions and Roles
- [ ] Role management (creation, deletion, modification) - [ ] [Role management](https://github.com/polyphony-chat/chorus/issues/46) (creation, deletion, modification)
- [ ] Permission management (assigning and revoking permissions) - [ ] [Permission management](https://github.com/polyphony-chat/chorus/issues/46) (assigning and revoking permissions)
- [ ] Channel-specific permissions - [ ] [Channel-specific permissions](https://github.com/polyphony-chat/chorus/issues/88)
- [ ] Role-based access control - [ ] Role-based access control
### Server Management ### Guild Management
- [x] Server creation - [x] Guild creation
- [x] Server deletion - [x] Guild deletion
- [ ] Server settings management (name, description, icon, etc.) - [ ] [Guild settings (name, description, icon, etc.)](https://github.com/polyphony-chat/chorus/issues/43)
- [ ] Member management (adding, removing, banning, unbanning) - [ ] Guild invites
- [ ] Server invites
### Moderation ### Moderation
- [ ] Channel moderation (slow mode, etc.) - [ ] Channel moderation (slow mode, etc.)

8
SECURITY.md Normal file
View File

@ -0,0 +1,8 @@
# Security Policy
## Reporting a Vulnerability
If you find a security vulnerability, please report it in one of the following ways:
- contact a code owner directly on our Discord server
- open an Issue on GitHub
- Reach out to us via E-Mail: lignite-due-00@icloud.com

View File

@ -7,26 +7,28 @@ use crate::{
}; };
/** /**
Extends the [`types::Reaction`] struct with useful metadata. Useful metadata for working with [`types::Reaction`], bundled together nicely.
*/ */
pub struct ReactionMeta { pub struct ReactionMeta {
pub message_id: types::Snowflake, pub message_id: types::Snowflake,
pub channel_id: types::Snowflake, pub channel_id: types::Snowflake,
pub reaction: types::Reaction,
} }
impl ReactionMeta { impl ReactionMeta {
/** /**
Deletes all reactions for a message. Deletes all reactions for a message.
# Arguments This endpoint requires the `MANAGE_MESSAGES` permission to be present on the current user.
* `user` - A mutable reference to a [`UserMeta`] instance.
# Returns # Arguments
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`]. * `user` - A mutable reference to a [`UserMeta`] instance.
# Returns
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
Fires a `Message Reaction Remove All` Gateway event.
# Reference # Reference
See [https://discord.com/developers/docs/resources/channel#delete-all-reactions](https://discord.com/developers/docs/resources/channel#delete-all-reactions) See [https://discord.com/developers/docs/resources/channel#delete-all-reactions](https://discord.com/developers/docs/resources/channel#delete-all-reactions)
*/ */
pub async fn delete_all( pub async fn delete_all(
&self, &self,
user: &mut UserMeta, user: &mut UserMeta,
@ -92,8 +94,7 @@ impl ReactionMeta {
/** /**
Deletes all the reactions for a given `emoji` on a message. This endpoint requires the Deletes all the reactions for a given `emoji` on a message. This endpoint requires the
MANAGE_MESSAGES permission to be present on the current user. Fires a `Message Reaction MANAGE_MESSAGES permission to be present on the current user.
Remove Emoji` Gateway event.
# Arguments # Arguments
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or * `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
@ -103,6 +104,7 @@ impl ReactionMeta {
# Returns # Returns
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`]. A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
Fires a `Message Reaction Remove Emoji` Gateway event.
# Reference # Reference
See [https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji](https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji) See [https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji](https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji)
@ -131,17 +133,14 @@ impl ReactionMeta {
) )
.await .await
} }
}
impl types::Reaction {
/** /**
Create a reaction for the message. Create a reaction for the message.
This endpoint requires the READ_MESSAGE_HISTORY permission This endpoint requires the READ_MESSAGE_HISTORY permission
to be present on the current user. Additionally, if nobody else has reacted to the message using to be present on the current user. Additionally, if nobody else has reacted to the message using
this emoji, this endpoint requires the ADD_REACTIONS permission to be present on the current this emoji, this endpoint requires the ADD_REACTIONS permission to be present on the current
user. Fires a Message Reaction Add Gateway event. user.
# Arguments # Arguments
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or * `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
@ -151,13 +150,13 @@ impl types::Reaction {
# Returns # Returns
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`]. A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
Returns a 204 empty response on success. Returns a 204 empty response on success.
Fires a Message Reaction Add Gateway event.
# Reference # Reference
See [https://discord.com/developers/docs/resources/channel#create-reaction](https://discord.com/developers/docs/resources/channel#create-reaction) See [https://discord.com/developers/docs/resources/channel#create-reaction](https://discord.com/developers/docs/resources/channel#create-reaction)
*/ */
pub async fn create( pub async fn create(
channel_id: &Snowflake, &self,
message_id: &Snowflake,
emoji: &str, emoji: &str,
user: &mut UserMeta, user: &mut UserMeta,
) -> Result<reqwest::Response, crate::errors::InstanceServerError> { ) -> Result<reqwest::Response, crate::errors::InstanceServerError> {
@ -165,8 +164,8 @@ impl types::Reaction {
let url = format!( let url = format!(
"{}/channels/{}/messages/{}/reactions/{}/@me/", "{}/channels/{}/messages/{}/reactions/{}/@me/",
belongs_to.urls.get_api(), belongs_to.urls.get_api(),
channel_id, self.channel_id,
message_id, self.message_id,
emoji emoji
); );
let request = Client::new().put(url).bearer_auth(user.token()); let request = Client::new().put(url).bearer_auth(user.token());
@ -180,4 +179,93 @@ impl types::Reaction {
) )
.await .await
} }
/**
Delete a reaction the current user has made for the message.
# Arguments
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
format name:id with the emoji name and emoji id.
* `user` - A mutable reference to a [`UserMeta`] instance.
# Returns
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
Returns a 204 empty response on success.
Fires a `Message Reaction Remove` Gateway event.
# Reference
See [https://discord.com/developers/docs/resources/channel#delete-own-reaction](https://discord.com/developers/docs/resources/channel#delete-own-reaction)
*/
pub async fn remove(
&self,
emoji: &str,
user: &mut UserMeta,
) -> Result<reqwest::Response, crate::errors::InstanceServerError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let url = format!(
"{}/channels/{}/messages/{}/reactions/{}/@me/",
belongs_to.urls.get_api(),
self.channel_id,
self.message_id,
emoji
);
let request = Client::new().delete(url).bearer_auth(user.token());
LimitedRequester::new()
.await
.send_request(
request,
crate::api::limits::LimitType::Channel,
&mut belongs_to.limits,
&mut user.limits,
)
.await
}
/**
Delete a user's reaction to a message.
This endpoint requires the MANAGE_MESSAGES permission to be present on the current user.
# Arguments
* `user_id` - A string slice containing the ID of the user whose reaction is to be deleted.
* `emoji` - A string slice containing the emoji to delete. The `emoji` must be URL Encoded or
the request will fail with 10014: Unknown Emoji. To use custom emoji, you must encode it in the
format name:id with the emoji name and emoji id.
* `user` - A mutable reference to a [`UserMeta`] instance.
# Returns
A `Result` containing a [`reqwest::Response`] or a [`crate::errors::InstanceServerError`].
Returns a 204 empty response on success.
Fires a Message Reaction Remove Gateway event.
# Reference
See [https://discord.com/developers/docs/resources/channel#delete-own-reaction](https://discord.com/developers/docs/resources/channel#delete-own-reaction)
*/
pub async fn delete_user(
&self,
user_id: &str,
emoji: &str,
user: &mut UserMeta,
) -> Result<reqwest::Response, crate::errors::InstanceServerError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let url = format!(
"{}/channels/{}/messages/{}/reactions/{}/{}",
belongs_to.urls.get_api(),
self.channel_id,
self.message_id,
emoji,
user_id
);
let request = Client::new().delete(url).bearer_auth(user.token());
LimitedRequester::new()
.await
.send_request(
request,
crate::api::limits::LimitType::Channel,
&mut belongs_to.limits,
&mut user.limits,
)
.await
}
} }

View File

@ -50,3 +50,78 @@ pub struct RoleTags {
// available_for_purchase: bool, // available_for_purchase: bool,
// guild_connections: bool, // guild_connections: bool,
} }
#[derive(Debug)]
#[repr(u64)]
pub enum PermissionFlags {
CreateInstantInvite = 0x0000000000000001,
KickMembers = 0x0000000000000002,
BanMembers = 0x0000000000000004,
Administrator = 0x0000000000000008,
ManageChannels = 0x0000000000000010,
ManageGuild = 0x0000000000000020,
AddReactions = 0x0000000000000040,
ViewAuditLog = 0x0000000000000080,
PrioritySpeaker = 0x0000000000000100,
Stream = 0x0000000000000200,
ViewChannel = 0x0000000000000400,
SendMessages = 0x0000000000000800,
SendTtsMessages = 0x0000000000001000,
ManageMessages = 0x0000000000002000,
EmbedLinks = 0x0000000000004000,
AttachFiles = 0x0000000000008000,
ReadMessageHistory = 0x0000000000010000,
MentionEveryone = 0x0000000000020000,
UseExternalEmojis = 0x0000000000040000,
ViewGuildInsights = 0x0000000000080000,
Connect = 0x0000000000100000,
Speak = 0x0000000000200000,
MuteMembers = 0x0000000000400000,
DeafenMembers = 0x0000000000800000,
MoveMembers = 0x0000000001000000,
UseVad = 0x0000000002000000,
ChangeNickname = 0x0000000004000000,
ManageNicknames = 0x0000000008000000,
ManageRoles = 0x0000000010000000,
ManageWebhooks = 0x0000000020000000,
ManageGuildExpressions = 0x0000000040000000,
UseApplicationCommands = 0x0000000080000000,
RequestToSpeak = 0x0000000100000000,
ManageEvents = 0x0000000200000000,
ManageThreads = 0x0000000400000000,
CreatePublicThreads = 0x0000000800000000,
CreatePrivateThreads = 0x0000001000000000,
UseExternalStickers = 0x0000002000000000,
SendMessagesInThreads = 0x0000004000000000,
UseEmbeddedActivities = 0x0000008000000000,
ModerateMembers = 0x0000010000000000,
ViewCreatorMonetizationAnalytics = 0x0000020000000000,
UseSoundboard = 0x0000040000000000,
UseExternalSounds = 0x0000200000000000,
SendVoiceMessages = 0x0000400000000000,
}
impl RoleObject {
/// Checks if the role has a specific permission.
///
/// # Arguments
///
/// * `permission` - The permission to check for.
///
/// # Example
///
/// ```
/// use chorus::types;
/// let mut role = types::RoleObject::default();
/// let permission = types::PermissionFlags::ModerateMembers as u64 | types::PermissionFlags::UseSoundboard as u64;
/// role.permissions = permission.to_string();
/// assert_eq!(true, role.has_permission(types::PermissionFlags::ModerateMembers));
/// assert_eq!(true, role.has_permission(types::PermissionFlags::UseSoundboard));
/// ```
pub fn has_permission(&self, permission: PermissionFlags) -> bool {
if self.permissions.parse::<u64>().unwrap() & permission as u64 != 0 {
return true;
}
false
}
}