From d6ea8977a669abddc4a1b725cfa50b5ffd1a95f6 Mon Sep 17 00:00:00 2001 From: Seoxi Ryouko Date: Thu, 31 Jul 2025 00:44:48 -0500 Subject: [PATCH] Fixed spotify more --- Cargo.lock | 2 +- src/main.rs | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1858265..bd8d25f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4270,7 +4270,7 @@ dependencies = [ [[package]] name = "watcat" -version = "0.3.0" +version = "0.4.0" dependencies = [ "arabic_reshaper", "dotenvy", diff --git a/src/main.rs b/src/main.rs index 6de8a63..6c6e46e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ extern crate dotenvy; extern crate lastfm; extern crate reqwest; extern crate reqwest_middleware; -use http_cache_reqwest::{CACacheManager, Cache, CacheMode, HttpCache, HttpCacheOptions}; +use http_cache_reqwest::{CACacheManager, Cache, CacheMode, HttpCache, HttpCacheOptions,}; use serenity::async_trait; use serenity::builder::{CreateAttachment, CreateMessage}; @@ -11,7 +11,7 @@ use serenity::model::id::UserId; use serenity::prelude::*; extern crate magick_rust; -use magick_rust::{ColorspaceType, CompositeOperator, MagickWand, PixelWand, magick_wand_genesis, FilterType}; +use magick_rust::{ColorspaceType, CompositeOperator, MagickWand, PixelWand, magick_wand_genesis, FilterType,}; use std::env; use std::sync::{Once, Arc}; @@ -25,7 +25,7 @@ extern crate sqlx; use sqlx::sqlite::SqlitePool; use rspotify::{ClientCredsSpotify, Credentials, clients::BaseClient,}; -use rspotify::model::{enums::types::SearchType, search::SearchResult}; +use rspotify::model::{enums::types::SearchType, search::SearchResult,}; use imagetext::fontdb::FontDB; use imagetext::superfont::SuperFont; @@ -178,9 +178,9 @@ async fn spot(ctx: &Context, arg: &str, id: UserId) -> Reply { Err(e) => return Reply::Text(format!("Failed to get track {e}")), _ => return Reply::Text("Spotify search failed".to_owned()), }; - match &tracks.items[0].external_urls.get("spotify") { - Some(url) => Reply::Text(url.to_owned().to_owned()), - None => Reply::Text("Unable to get spotify url".to_owned()), + match &tracks.items.first().map(|x| x.external_urls.get("spotify")) { + Some(Some(url)) => Reply::Text(url.to_owned().to_owned()), + _ => Reply::Text("Unable to get spotify url".to_owned()), } } @@ -395,12 +395,6 @@ async fn set(ctx: &Context, arg: &str, id: UserId) -> Reply { Reply::Text(format!("set user {arg}")) } -//macro_rules! cmd { -// (c:lit, abbr:lit, a:ident) => { -// (".k", $c, $a) | (".k", $a, $c) | (concat!(".k", $abbr), $ident, "") -// } -//} - #[async_trait] impl EventHandler for Handler { async fn message(&self, ctx: Context, msg: Message) {