Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix favourite songs not showing anymore without query #38

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog],
and this project adheres to [Semantic Versioning].

## [1.3.2] - 2024-05-23

### Added

- Added some rudimentary Sentry upload for command panics

### Changed

- Show all favourites if the search query is empty

## [1.3.1] - 2024-05-23

### Changed
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["judeharley", "byers", "langley", "frohike", "migration"]
resolver = "2"

[workspace.package]
version = "1.3.1"
version = "1.3.2"
authors = ["cozyGalvinism <jean@der-capta.in>"]
edition = "2021"

Expand Down
25 changes: 20 additions & 5 deletions byers/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@ pub async fn autocomplete_songs(
partial: &str,
) -> impl Iterator<Item = poise::serenity_prelude::AutocompleteChoice> {
let data = ctx.data();

let songs = Songs::search(partial, &data.db)
let user = Users::get_or_insert(ctx.author().id.get(), &data.db)
.await
.expect_or_log("Failed to query database");

let songs = if partial.is_empty() {
user.list_favourites(&data.db)
.await
.expect_or_log("Failed to query database")
} else {
Songs::search(partial, &data.db)
.await
.expect_or_log("Failed to query database")
};

songs.into_iter().take(20).map(|song| {
AutocompleteChoice::new(
format!("{} - {}", song.artist, song.title)
Expand All @@ -73,9 +82,15 @@ pub async fn autocomplete_favourite_songs(
.await
.expect_or_log("Failed to query database");

let songs = Songs::search_favourited_songs(partial, &user, &data.db)
.await
.expect_or_log("Failed to query database");
let songs = if partial.is_empty() {
user.list_favourites(&data.db)
.await
.expect_or_log("Failed to query database")
} else {
Songs::search_favourited_songs(partial, &user, &data.db)
.await
.expect_or_log("Failed to query database")
};

songs.into_iter().take(20).map(|song| {
AutocompleteChoice::new(
Expand Down
1 change: 1 addition & 0 deletions byers/src/commands/youtube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ If you don't remember your old YouTube name or you no longer have access to your
SituwaitionOptsBuilder::default()
.timeout(Duration::from_secs(120))
.check_interval(Duration::from_secs(1))
.check_cooldown(None)
.build()
.unwrap(),
)
Expand Down
17 changes: 17 additions & 0 deletions byers/src/event_handlers/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ pub async fn on_error(error: FrameworkError<'_>) -> Result<(), Error> {
sentry::add_breadcrumb(BreadcrumbableContext(ctx).as_breadcrumbs().await);
sentry_anyhow::capture_anyhow(&error);
ctx.say(err_str).await?;
},
FrameworkError::CommandPanic { ref payload, ref ctx, .. } => {
let payload_clone = payload.clone();
sentry::add_breadcrumb(BreadcrumbableContext(*ctx).as_breadcrumbs().await);
if let Some(payload) = payload_clone {
sentry_anyhow::capture_anyhow(&anyhow::anyhow!(payload));
} else {
sentry_anyhow::capture_anyhow(&anyhow::anyhow!("Panic in command"));
}

let embed = poise::serenity_prelude::CreateEmbed::default()
.title("Internal error")
.color((255, 0, 0))
.description("An unexpected internal error has occurred.");

ctx.send(CreateReply::default().embed(embed).ephemeral(true))
.await?;
}
_ => {
poise::builtins::on_error(error).await?;
Expand Down
8 changes: 1 addition & 7 deletions judeharley/examples/playground.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use judeharley::Decimal;

#[tokio::main]
async fn main() {
let db = judeharley::connect_database("postgres://byers:byers@localhost/byers").await.unwrap();

let songs = judeharley::Songs::search("zehanpuryu", &db).await.unwrap();

println!("{:#?}", songs);

}
Loading