Lots of refactoring, mostly to figure out how Axum works, tbh

This commit is contained in:
2023-03-29 02:46:19 +02:00
parent 9c3dfba3ba
commit eab9c83067
6 changed files with 151 additions and 87 deletions

26
src/discord/mod.rs Normal file
View 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}")))
}