Open beta

This commit is contained in:
DaXcess committed 2022-11-01 09:36:25 +01:00
1 parent d530b182b3
commit 6da879ee0c
9 files changed
+58 -44

No files matched your search

-3
View File
@@ -1,3 +0,0 @@
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const MOTD: &str = "OPEN BETA (v2)";
// pub const MOTD: &str = "some good 'ol music";
+17
View File
@@ -1,3 +1,8 @@
use serenity::{
model::{prelude::UserId, user::User},
prelude::Context,
};
pub fn escape(text: impl Into<String>) -> String {
let text: String = text.into();
@@ -8,3 +13,15 @@ pub fn escape(text: impl Into<String>) -> String {
.replace("~", "\\~")
.replace("`", "\\`")
}
pub async fn get_user(ctx: &Context, id: UserId) -> Option<User> {
let user = match ctx.cache.user(id) {
Some(user) => user,
None => match ctx.http.get_user(id.0).await {
Ok(user) => user,
Err(_) => return None,
},
};
Some(user)
}
-1
View File
@@ -1,6 +1,5 @@
use std::time::{SystemTime, UNIX_EPOCH};
pub mod consts;
pub mod discord;
pub mod embed;
pub mod spotify;
+34 -34
View File
@@ -5,40 +5,6 @@ use log::{error, trace};
use serde::Deserialize;
use serde_json::Value;
pub async fn get_username(token: impl Into<String>) -> Result<String, String> {
let token = token.into();
let client = reqwest::Client::new();
let response = match client
.get("https://api.spotify.com/v1/me")
.bearer_auth(token)
.send()
.await
{
Ok(response) => response,
Err(why) => {
error!("Failed to get username: {}", why);
return Err(format!("{}", why));
}
};
let body: Value = match response.json().await {
Ok(body) => body,
Err(why) => {
error!("Failed to parse body: {}", why);
return Err(format!("{}", why));
}
};
if let Value::String(username) = &body["id"] {
trace!("Got username: {}", username);
return Ok(username.clone());
}
error!("Missing 'id' field in body");
Err("Failed to parse body: Invalid body received".to_string())
}
#[derive(Debug, Clone, Deserialize)]
pub struct Artist {
pub name: String,
@@ -76,6 +42,40 @@ pub struct Episode {
pub show: Show,
}
pub async fn get_username(token: impl Into<String>) -> Result<String, String> {
let token = token.into();
let client = reqwest::Client::new();
let response = match client
.get("https://api.spotify.com/v1/me")
.bearer_auth(token)
.send()
.await
{
Ok(response) => response,
Err(why) => {
error!("Failed to get username: {}", why);
return Err(format!("{}", why));
}
};
let body: Value = match response.json().await {
Ok(body) => body,
Err(why) => {
error!("Failed to parse body: {}", why);
return Err(format!("{}", why));
}
};
if let Value::String(username) = &body["id"] {
trace!("Got username: {}", username);
return Ok(username.clone());
}
error!("Missing 'id' field in body");
Err("Failed to parse body: Invalid body received".to_string())
}
pub async fn get_track_info(
token: impl Into<String>,
track: SpotifyId,