Make clippy happy, add tokio monitoring
This commit is contained in:
@@ -19,14 +19,14 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
EmbedBuilder::new()
|
||||
.title("Spoticord Help")
|
||||
.icon_url("https://spoticord.com/logo-standard.webp")
|
||||
.description(format!("**Welcome to Spoticord**
|
||||
.description("**Welcome to Spoticord**
|
||||
It seems you have requested some help. Not to worry, we can help you out.\n
|
||||
**Not sure how the bot works?**
|
||||
**[Click here](https://spoticord.com/#how-to)** for a quick overview about how to set up Spoticord and how to use it.\n
|
||||
**Which commands are there?**
|
||||
You can find all **[the commands](https://spoticord.com/#commands)** on the website. You may also just type `/` in Discord and see which commands are available there.\n
|
||||
**Need more help?**
|
||||
If you still need some help, whether you are having issues with the bot or you just want to give us some feedback, you can join our **[Discord server](https://discord.gg/wRCyhVqBZ5)**."))
|
||||
If you still need some help, whether you are having issues with the bot or you just want to give us some feedback, you can join our **[Discord server](https://discord.gg/wRCyhVqBZ5)**.".to_string())
|
||||
.status(Status::Info)
|
||||
.build(),
|
||||
false,
|
||||
|
||||
@@ -17,9 +17,13 @@ pub const NAME: &str = "link";
|
||||
pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutput {
|
||||
Box::pin(async move {
|
||||
let data = ctx.data.read().await;
|
||||
let database = data.get::<Database>().unwrap();
|
||||
let database = data.get::<Database>().expect("to contain a value");
|
||||
|
||||
if let Ok(_) = database.get_user_account(command.user.id.to_string()).await {
|
||||
if database
|
||||
.get_user_account(command.user.id.to_string())
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
respond_message(
|
||||
&ctx,
|
||||
&command,
|
||||
@@ -35,7 +39,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
}
|
||||
|
||||
if let Ok(request) = database.get_user_request(command.user.id.to_string()).await {
|
||||
let base = std::env::var("SPOTICORD_ACCOUNTS_URL").unwrap();
|
||||
let base = std::env::var("SPOTICORD_ACCOUNTS_URL").expect("to be present");
|
||||
let link = format!("{}/spotify/{}", base, request.token);
|
||||
|
||||
respond_message(
|
||||
@@ -102,7 +106,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
.await
|
||||
{
|
||||
Ok(request) => {
|
||||
let base = std::env::var("SPOTICORD_ACCOUNTS_URL").unwrap();
|
||||
let base = std::env::var("SPOTICORD_ACCOUNTS_URL").expect("to be present");
|
||||
let link = format!("{}/spotify/{}", base, request.token);
|
||||
|
||||
respond_message(
|
||||
@@ -121,9 +125,8 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Err(why) => {
|
||||
error!("Error creating user request: {:?}", why);
|
||||
|
||||
@@ -137,8 +140,6 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
@@ -22,7 +22,7 @@ pub const NAME: &str = "rename";
|
||||
pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutput {
|
||||
Box::pin(async move {
|
||||
let data = ctx.data.read().await;
|
||||
let database = data.get::<Database>().unwrap();
|
||||
let database = data.get::<Database>().expect("to contain a value");
|
||||
|
||||
// Check if user exists, if not, create them
|
||||
if let Err(why) = database.get_user(command.user.id.to_string()).await {
|
||||
@@ -65,7 +65,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
|
||||
let device_name = match command.data.options.get(0) {
|
||||
Some(option) => match option.value {
|
||||
Some(ref value) => value.as_str().unwrap().to_string(),
|
||||
Some(ref value) => value.as_str().expect("to be a string").to_string(),
|
||||
None => {
|
||||
respond_message(
|
||||
&ctx,
|
||||
|
||||
@@ -17,8 +17,8 @@ pub const NAME: &str = "unlink";
|
||||
pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutput {
|
||||
Box::pin(async move {
|
||||
let data = ctx.data.read().await;
|
||||
let database = data.get::<Database>().unwrap();
|
||||
let session_manager = data.get::<SessionManager>().unwrap();
|
||||
let database = data.get::<Database>().expect("to contain a value");
|
||||
let session_manager = data.get::<SessionManager>().expect("to contain a value");
|
||||
|
||||
// Disconnect session if user has any
|
||||
if let Some(session) = session_manager.find(command.user.id).await {
|
||||
|
||||
@@ -170,7 +170,7 @@ impl CommandManager {
|
||||
cmds: &HashMap<String, CommandInfo>,
|
||||
mut commands: &'a mut CreateApplicationCommands,
|
||||
) -> &'a mut CreateApplicationCommands {
|
||||
for (_, command_info) in cmds {
|
||||
for command_info in cmds.values() {
|
||||
commands = commands.create_application_command(|command| (command_info.register)(command));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ pub const NAME: &str = "join";
|
||||
|
||||
pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutput {
|
||||
Box::pin(async move {
|
||||
let guild = ctx.cache.guild(command.guild_id.unwrap()).unwrap();
|
||||
let guild = ctx
|
||||
.cache
|
||||
.guild(command.guild_id.expect("to contain a value"))
|
||||
.expect("to be present");
|
||||
|
||||
// Get the voice channel id of the calling user
|
||||
let channel_id = match guild
|
||||
@@ -81,8 +84,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
}
|
||||
};
|
||||
|
||||
if let Ok(permissions) =
|
||||
channel.permissions_for_user(&ctx.cache, &ctx.cache.current_user_id())
|
||||
if let Ok(permissions) = channel.permissions_for_user(&ctx.cache, ctx.cache.current_user_id())
|
||||
{
|
||||
if !permissions.view_channel() || !permissions.connect() || !permissions.speak() {
|
||||
respond_message(
|
||||
@@ -142,8 +144,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
}
|
||||
};
|
||||
|
||||
if let Ok(permissions) =
|
||||
channel.permissions_for_user(&ctx.cache, &ctx.cache.current_user_id())
|
||||
if let Ok(permissions) = channel.permissions_for_user(&ctx.cache, ctx.cache.current_user_id())
|
||||
{
|
||||
if !permissions.view_channel() || !permissions.send_messages() || !permissions.embed_links()
|
||||
{
|
||||
@@ -167,7 +168,10 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
}
|
||||
|
||||
let data = ctx.data.read().await;
|
||||
let session_manager = data.get::<SessionManager>().unwrap().clone();
|
||||
let session_manager = data
|
||||
.get::<SessionManager>()
|
||||
.expect("to contain a value")
|
||||
.clone();
|
||||
|
||||
// Check if another session is already active in this server
|
||||
let mut session_opt = session_manager.get_session(guild.id).await;
|
||||
@@ -206,7 +210,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
.description(
|
||||
format!(
|
||||
"You are already playing music in another server ({}).\nStop playing in that server first before joining this one.",
|
||||
ctx.cache.guild(session.guild_id().await).unwrap().name
|
||||
ctx.cache.guild(session.guild_id().await).expect("to be present").name
|
||||
)).status(Status::Error).build(),
|
||||
true,
|
||||
)
|
||||
@@ -230,7 +234,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
if let Some(session) = session_opt.as_mut() {
|
||||
if let Err(why) = session.update_owner(&ctx, command.user.id).await {
|
||||
// Need to link first
|
||||
if let SessionCreateError::NoSpotifyError = why {
|
||||
if let SessionCreateError::NoSpotify = why {
|
||||
update_message(
|
||||
&ctx,
|
||||
&command,
|
||||
@@ -243,7 +247,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
.await;
|
||||
|
||||
return;
|
||||
} else if let SessionCreateError::NoLongerSpotifyError = why {
|
||||
} else if let SessionCreateError::SpotifyExpired = why {
|
||||
update_message(
|
||||
&ctx,
|
||||
&command,
|
||||
@@ -284,7 +288,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
.await
|
||||
{
|
||||
// Need to link first
|
||||
if let SessionCreateError::NoSpotifyError = why {
|
||||
if let SessionCreateError::NoSpotify = why {
|
||||
update_message(
|
||||
&ctx,
|
||||
&command,
|
||||
@@ -297,7 +301,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
.await;
|
||||
|
||||
return;
|
||||
} else if let SessionCreateError::NoLongerSpotifyError = why {
|
||||
} else if let SessionCreateError::SpotifyExpired = why {
|
||||
update_message(
|
||||
&ctx,
|
||||
&command,
|
||||
|
||||
@@ -15,9 +15,15 @@ pub const NAME: &str = "leave";
|
||||
pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutput {
|
||||
Box::pin(async move {
|
||||
let data = ctx.data.read().await;
|
||||
let session_manager = data.get::<SessionManager>().unwrap().clone();
|
||||
let session_manager = data
|
||||
.get::<SessionManager>()
|
||||
.expect("to contain a value")
|
||||
.clone();
|
||||
|
||||
let session = match session_manager.get_session(command.guild_id.unwrap()).await {
|
||||
let session = match session_manager
|
||||
.get_session(command.guild_id.expect("to contain a value"))
|
||||
.await
|
||||
{
|
||||
Some(session) => session,
|
||||
None => {
|
||||
respond_message(
|
||||
|
||||
@@ -37,9 +37,15 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
};
|
||||
|
||||
let data = ctx.data.read().await;
|
||||
let session_manager = data.get::<SessionManager>().unwrap().clone();
|
||||
let session_manager = data
|
||||
.get::<SessionManager>()
|
||||
.expect("to contain a value")
|
||||
.clone();
|
||||
|
||||
let session = match session_manager.get_session(command.guild_id.unwrap()).await {
|
||||
let session = match session_manager
|
||||
.get_session(command.guild_id.expect("to contain a value"))
|
||||
.await
|
||||
{
|
||||
Some(session) => session,
|
||||
None => {
|
||||
not_playing.await;
|
||||
@@ -86,8 +92,8 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
// Create title
|
||||
let title = format!(
|
||||
"{} - {}",
|
||||
pbi.get_artists().unwrap(),
|
||||
pbi.get_name().unwrap()
|
||||
pbi.get_artists().expect("to contain a value"),
|
||||
pbi.get_name().expect("to contain a value")
|
||||
);
|
||||
|
||||
// Create description
|
||||
@@ -100,9 +106,9 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
|
||||
for i in 0..20 {
|
||||
if i == spot {
|
||||
description.push_str("🔵");
|
||||
description.push('🔵');
|
||||
} else {
|
||||
description.push_str("▬");
|
||||
description.push('▬');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +147,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
};
|
||||
|
||||
// Get the thumbnail image
|
||||
let thumbnail = pbi.get_thumbnail_url().unwrap();
|
||||
let thumbnail = pbi.get_thumbnail_url().expect("to contain a value");
|
||||
|
||||
if let Err(why) = command
|
||||
.create_interaction_response(&ctx.http, |response| {
|
||||
@@ -159,7 +165,9 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
.url(format!(
|
||||
"https://open.spotify.com/{}/{}",
|
||||
audio_type,
|
||||
spotify_id.to_base62().unwrap()
|
||||
spotify_id
|
||||
.to_base62()
|
||||
.expect("to be able to convert to base62")
|
||||
))
|
||||
.description(description)
|
||||
.footer(|footer| footer.text(&owner.name).icon_url(owner.face()))
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
.interaction_response_data(|message| message.content("Pong!"))
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
.ok();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ pub const NAME: &str = "token";
|
||||
pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutput {
|
||||
Box::pin(async move {
|
||||
let data = ctx.data.read().await;
|
||||
let db = data.get::<Database>().unwrap();
|
||||
let db = data.get::<Database>().expect("to contain a value");
|
||||
|
||||
let token = db.get_access_token(command.user.id.to_string()).await;
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||
.interaction_response_data(|message| message.content(content).ephemeral(true))
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
.ok();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user