Open beta
parent
d530b182b3
commit
6da879ee0c
|
@ -7,10 +7,7 @@ use serenity::{
|
||||||
prelude::Context,
|
prelude::Context,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{bot::commands::CommandOutput, consts::VERSION, utils::embed::Status};
|
||||||
bot::commands::CommandOutput,
|
|
||||||
utils::{consts::VERSION, embed::Status},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const NAME: &str = "version";
|
pub const NAME: &str = "version";
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||||
EmbedBuilder::new()
|
EmbedBuilder::new()
|
||||||
.title("Cannot join voice channel")
|
.title("Cannot join voice channel")
|
||||||
.icon_url("https://spoticord.com/static/image/prohibited.png")
|
.icon_url("https://spoticord.com/static/image/prohibited.png")
|
||||||
.description("You need to link your Spotify account. Use </link:1036714850367320136> or go to https://account.spoticord.com/ to get started.")
|
.description("You need to link your Spotify account. Use </link:1036714850367320136> or go to [the accounts website](https://account.spoticord.com/) to get started.")
|
||||||
.status(Status::Error)
|
.status(Status::Error)
|
||||||
.build(),
|
.build(),
|
||||||
true,
|
true,
|
||||||
|
@ -141,7 +141,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||||
EmbedBuilder::new()
|
EmbedBuilder::new()
|
||||||
.title("Cannot join voice channel")
|
.title("Cannot join voice channel")
|
||||||
.icon_url("https://spoticord.com/static/image/prohibited.png")
|
.icon_url("https://spoticord.com/static/image/prohibited.png")
|
||||||
.description("You need to link your Spotify account. Use </link:1036714850367320136> or go to https://account.spoticord.com/ to get started.")
|
.description("You need to link your Spotify account. Use </link:1036714850367320136> or go to [the accounts website](https://account.spoticord.com/) to get started.")
|
||||||
.status(Status::Error)
|
.status(Status::Error)
|
||||||
.build(),
|
.build(),
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -103,11 +103,11 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||||
description.push_str(&format!("{} / {}", utils::time_to_str(position / 1000), utils::time_to_str(pbi.duration_ms / 1000)));
|
description.push_str(&format!("{} / {}", utils::time_to_str(position / 1000), utils::time_to_str(pbi.duration_ms / 1000)));
|
||||||
|
|
||||||
// Get owner of session
|
// Get owner of session
|
||||||
let owner = match ctx.cache.user(owner) {
|
let owner = match utils::discord::get_user(&ctx, owner).await {
|
||||||
Some(user) => user,
|
Some(user) => user,
|
||||||
None => {
|
None => {
|
||||||
// This shouldn't happen
|
// This shouldn't happen
|
||||||
// TODO: This can happen, idk when
|
// TODO: Test if this can no longer happen
|
||||||
|
|
||||||
error!("Could not find user with id {}", owner);
|
error!("Could not find user with id {}", owner);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use serenity::{
|
||||||
prelude::{Context, EventHandler},
|
prelude::{Context, EventHandler},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::utils::consts::MOTD;
|
use crate::consts::MOTD;
|
||||||
|
|
||||||
use super::commands::CommandManager;
|
use super::commands::CommandManager;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::{
|
||||||
|
|
||||||
mod audio;
|
mod audio;
|
||||||
mod bot;
|
mod bot;
|
||||||
|
mod consts;
|
||||||
mod database;
|
mod database;
|
||||||
mod ipc;
|
mod ipc;
|
||||||
mod librespot_ext;
|
mod librespot_ext;
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
use serenity::{
|
||||||
|
model::{prelude::UserId, user::User},
|
||||||
|
prelude::Context,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn escape(text: impl Into<String>) -> String {
|
pub fn escape(text: impl Into<String>) -> String {
|
||||||
let text: String = text.into();
|
let text: String = text.into();
|
||||||
|
|
||||||
|
@ -8,3 +13,15 @@ pub fn escape(text: impl Into<String>) -> String {
|
||||||
.replace("~", "\\~")
|
.replace("~", "\\~")
|
||||||
.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,6 +1,5 @@
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
pub mod consts;
|
|
||||||
pub mod discord;
|
pub mod discord;
|
||||||
pub mod embed;
|
pub mod embed;
|
||||||
pub mod spotify;
|
pub mod spotify;
|
||||||
|
|
|
@ -5,40 +5,6 @@ use log::{error, trace};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::Value;
|
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)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct Artist {
|
pub struct Artist {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -76,6 +42,40 @@ pub struct Episode {
|
||||||
pub show: Show,
|
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(
|
pub async fn get_track_info(
|
||||||
token: impl Into<String>,
|
token: impl Into<String>,
|
||||||
track: SpotifyId,
|
track: SpotifyId,
|
||||||
|
|
Loading…
Reference in New Issue