refluxer 0.1.0

Rust API wrapper for Fluxer
Documentation
use crate::error::HttpError;
use crate::http::client::HttpClient;
use crate::http::routing::Route;
use crate::model::id::{ChannelId, MessageId, UserId};
use crate::model::user::User;

impl HttpClient {
    /// Add a reaction to a message. `emoji` is a URL-encoded emoji string,
    /// e.g. `"👍"` for unicode or `"name:id"` for custom emoji.
    pub async fn create_reaction(
        &self,
        channel_id: ChannelId,
        message_id: MessageId,
        emoji: &str,
    ) -> Result<(), HttpError> {
        self.request_empty(
            Route::CreateReaction {
                channel_id,
                message_id,
                emoji: encode_emoji(emoji),
            },
            None::<&()>,
        )
        .await
    }

    /// Remove own reaction from a message.
    pub async fn delete_own_reaction(
        &self,
        channel_id: ChannelId,
        message_id: MessageId,
        emoji: &str,
    ) -> Result<(), HttpError> {
        self.request_empty(
            Route::DeleteOwnReaction {
                channel_id,
                message_id,
                emoji: encode_emoji(emoji),
            },
            None::<&()>,
        )
        .await
    }

    /// Remove another user's reaction from a message.
    pub async fn delete_user_reaction(
        &self,
        channel_id: ChannelId,
        message_id: MessageId,
        emoji: &str,
        user_id: UserId,
    ) -> Result<(), HttpError> {
        self.request_empty(
            Route::DeleteUserReaction {
                channel_id,
                message_id,
                emoji: encode_emoji(emoji),
                user_id,
            },
            None::<&()>,
        )
        .await
    }

    /// Remove all reactions from a message.
    pub async fn delete_all_reactions(
        &self,
        channel_id: ChannelId,
        message_id: MessageId,
    ) -> Result<(), HttpError> {
        self.request_empty(
            Route::DeleteAllReactions {
                channel_id,
                message_id,
            },
            None::<&()>,
        )
        .await
    }

    /// Remove all reactions of a specific emoji from a message.
    pub async fn delete_all_reactions_for_emoji(
        &self,
        channel_id: ChannelId,
        message_id: MessageId,
        emoji: &str,
    ) -> Result<(), HttpError> {
        self.request_empty(
            Route::DeleteAllReactionsForEmoji {
                channel_id,
                message_id,
                emoji: encode_emoji(emoji),
            },
            None::<&()>,
        )
        .await
    }
    /// Get users who reacted with a specific emoji.
    pub async fn get_reaction_users(
        &self,
        channel_id: ChannelId,
        message_id: MessageId,
        emoji: &str,
    ) -> Result<Vec<User>, HttpError> {
        self.request_no_body(Route::GetReactionUsers {
            channel_id,
            message_id,
            emoji: encode_emoji(emoji),
        })
        .await
    }
}

fn encode_emoji(emoji: &str) -> String {
    // Custom emoji format "name:id" should not be URL-encoded
    if emoji.contains(':') {
        emoji.to_string()
    } else {
        urlencoding::encode(emoji).into_owned()
    }
}