Lots of refactoring, mostly to figure out how Axum works, tbh
This commit is contained in:
26
src/discord/mod.rs
Normal file
26
src/discord/mod.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use serde::Deserialize;
|
||||
use twilight_http::Client;
|
||||
|
||||
pub mod commands;
|
||||
pub mod interactions;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct ClientCredentialsResponse {
|
||||
access_token: String,
|
||||
}
|
||||
|
||||
fn client_credentials_grant(authorization: String) -> anyhow::Result<ClientCredentialsResponse> {
|
||||
Ok(ureq::post("https://discord.com/api/v10/oauth2/token")
|
||||
.set("Authorization", &format!("Basic {}", authorization))
|
||||
.send_form(&[
|
||||
("grant_type", "client_credentials"),
|
||||
("scope", "applications.commands.update"),
|
||||
])
|
||||
.unwrap()
|
||||
.into_json()?)
|
||||
}
|
||||
|
||||
pub fn discord_client(authorization: String) -> anyhow::Result<Client> {
|
||||
let token = client_credentials_grant(authorization)?.access_token;
|
||||
Ok(Client::new(format!("Bearer {token}")))
|
||||
}
|
||||
Reference in New Issue
Block a user