-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): Add support for application emojis (#2364)
- Loading branch information
1 parent
0dbb76a
commit 561bebb
Showing
10 changed files
with
444 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::future::IntoFuture; | ||
|
||
use crate::{ | ||
request::{Request, TryIntoRequest}, | ||
response::{Response, ResponseFuture}, | ||
routing::Route, | ||
Client, Error, | ||
}; | ||
|
||
use serde::Serialize; | ||
use twilight_model::{ | ||
guild::Emoji, | ||
id::{marker::ApplicationMarker, Id}, | ||
}; | ||
|
||
#[derive(Serialize)] | ||
struct AddApplicationEmojiFields<'a> { | ||
image: &'a str, | ||
name: &'a str, | ||
} | ||
|
||
pub struct AddApplicationEmoji<'a> { | ||
fields: AddApplicationEmojiFields<'a>, | ||
application_id: Id<ApplicationMarker>, | ||
http: &'a Client, | ||
} | ||
|
||
impl<'a> AddApplicationEmoji<'a> { | ||
pub(crate) const fn new( | ||
http: &'a Client, | ||
application_id: Id<ApplicationMarker>, | ||
name: &'a str, | ||
image: &'a str, | ||
) -> Self { | ||
Self { | ||
fields: AddApplicationEmojiFields { image, name }, | ||
application_id, | ||
http, | ||
} | ||
} | ||
} | ||
|
||
impl IntoFuture for AddApplicationEmoji<'_> { | ||
type Output = Result<Response<Emoji>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<Emoji>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
let http = self.http; | ||
|
||
match self.try_into_request() { | ||
Ok(request) => http.request(request), | ||
Err(source) => ResponseFuture::error(source), | ||
} | ||
} | ||
} | ||
|
||
impl TryIntoRequest for AddApplicationEmoji<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
let mut request = Request::builder(&Route::AddApplicationEmoji { | ||
application_id: self.application_id.get(), | ||
}); | ||
|
||
request = request.json(&self.fields); | ||
|
||
request.build() | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
twilight-http/src/request/application/emoji/delete_emoji.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::future::IntoFuture; | ||
use twilight_model::id::{ | ||
marker::{ApplicationMarker, EmojiMarker}, | ||
Id, | ||
}; | ||
|
||
use crate::{ | ||
request::{Request, TryIntoRequest}, | ||
response::{Response, ResponseFuture}, | ||
routing::Route, | ||
Client, Error, | ||
}; | ||
|
||
pub struct DeleteApplicationEmoji<'a> { | ||
application_id: Id<ApplicationMarker>, | ||
emoji_id: Id<EmojiMarker>, | ||
http: &'a Client, | ||
} | ||
|
||
impl<'a> DeleteApplicationEmoji<'a> { | ||
pub(crate) const fn new( | ||
http: &'a Client, | ||
application_id: Id<ApplicationMarker>, | ||
emoji_id: Id<EmojiMarker>, | ||
) -> Self { | ||
Self { | ||
application_id, | ||
emoji_id, | ||
http, | ||
} | ||
} | ||
} | ||
|
||
impl IntoFuture for DeleteApplicationEmoji<'_> { | ||
type Output = Result<Response<()>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<()>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
let http = self.http; | ||
|
||
match self.try_into_request() { | ||
Ok(request) => http.request(request), | ||
Err(source) => ResponseFuture::error(source), | ||
} | ||
} | ||
} | ||
|
||
impl TryIntoRequest for DeleteApplicationEmoji<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Ok(Request::from_route(&Route::DeleteApplicationEmoji { | ||
application_id: self.application_id.get(), | ||
emoji_id: self.emoji_id.get(), | ||
})) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
twilight-http/src/request/application/emoji/list_emojis.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::future::IntoFuture; | ||
|
||
use crate::{ | ||
request::{Request, TryIntoRequest}, | ||
response::{marker::ListBody, ResponseFuture}, | ||
routing::Route, | ||
Client, Error, Response, | ||
}; | ||
use twilight_model::{ | ||
guild::Emoji, | ||
id::{marker::ApplicationMarker, Id}, | ||
}; | ||
|
||
#[must_use = "requests must be configured and executed"] | ||
pub struct ListApplicationEmojis<'a> { | ||
http: &'a Client, | ||
application_id: Id<ApplicationMarker>, | ||
} | ||
|
||
impl<'a> ListApplicationEmojis<'a> { | ||
pub(crate) const fn new(http: &'a Client, application_id: Id<ApplicationMarker>) -> Self { | ||
Self { | ||
http, | ||
application_id, | ||
} | ||
} | ||
} | ||
|
||
impl IntoFuture for ListApplicationEmojis<'_> { | ||
type Output = Result<Response<ListBody<Emoji>>, Error>; | ||
|
||
type IntoFuture = ResponseFuture<ListBody<Emoji>>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
let http = self.http; | ||
|
||
match self.try_into_request() { | ||
Ok(request) => http.request(request), | ||
Err(source) => ResponseFuture::error(source), | ||
} | ||
} | ||
} | ||
|
||
impl TryIntoRequest for ListApplicationEmojis<'_> { | ||
fn try_into_request(self) -> Result<Request, Error> { | ||
Ok(Request::from_route(&Route::GetApplicationEmojis { | ||
application_id: self.application_id.get(), | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod add_emoji; | ||
mod delete_emoji; | ||
mod list_emojis; | ||
mod update_emoji; | ||
|
||
pub use self::{ | ||
add_emoji::AddApplicationEmoji, delete_emoji::DeleteApplicationEmoji, | ||
list_emojis::ListApplicationEmojis, update_emoji::UpdateApplicationEmoji, | ||
}; |
Oops, something went wrong.