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

Updated: Added search if Play command is used without a URL #53

Merged
merged 6 commits into from
Apr 21, 2022
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
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx256m
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run this code on a low-memory VM (1GB ram) and this is helpful for building there. I can remove it if anyone objects but it seems helpful in general.

12 changes: 11 additions & 1 deletion src/main/kotlin/dev/arbjerg/ukulele/command/PlayCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class PlayCommand(
) : Command("play", "p") {
override suspend fun CommandContext.invoke() {
if (!ensureVoiceChannel()) return
val identifier = argumentText

var identifier = argumentText
if (!checkValidUrl(identifier)) {
identifier = "ytsearch:$identifier"
}

players.get(guild, guildProperties).lastChannel = channel
apm.loadItem(identifier, Loader(this, player, identifier))
}
Expand Down Expand Up @@ -51,6 +56,11 @@ class PlayCommand(
return ourVc != null
}

fun checkValidUrl(url: String): Boolean {
return url.startsWith("http://")
|| url.startsWith("https://")
}

inner class Loader(
private val ctx: CommandContext,
private val player: Player,
Expand Down