Skip to content

Commit

Permalink
Fix bugs (#30)
Browse files Browse the repository at this point in the history
* Fix detekt issues

* Replace work around in favour of Kord release

* Fix bugs
- Make docs command case-insensitive
- Fix bug when no search results are found (Google and tag search)

* Remove debug code
  • Loading branch information
DRSchlaubi authored Feb 1, 2021
1 parent 7a6f863 commit 64e6507
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import dev.kord.x.commands.annotation.AutoWired
import dev.kord.x.commands.annotation.ModuleName
import dev.kord.x.commands.argument.Argument
import dev.kord.x.commands.argument.extension.filter
import dev.kord.x.commands.argument.extension.map
import dev.kord.x.commands.argument.extension.named
import dev.kord.x.commands.argument.result.extension.FilterResult
import dev.kord.x.commands.argument.text.WordArgument
Expand All @@ -63,6 +64,7 @@ private fun <CONTEXT> Argument<String, CONTEXT>.docsFilter() = filter { doc ->
@OptIn(KordPreview::class)
private val JavaDocArgument = WordArgument
.named("javadoc-name")
.map { it.toLowerCase() }
.docsFilter()
.asSlashArgument("Das Javadoc in dem gesucht werden soll") {
choice("JDK 11 Dokumentation", "jdk11")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun searchCommand() = command("google") {
private suspend fun KordCommandEvent.search(search: String) {
doExpensiveTask("Searching...", "Bitte warte, bis ich Ergebnisse gefunden habe!") {
val list = getResultAsList(search)
if (list == null) {
if (list.isNullOrEmpty()) {
editEmbed(Embeds.error("Schade!", "Google möchte dir anscheinend nicht antworten! ._."))
} else {
delete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import de.nycode.bankobot.command.command
import de.nycode.bankobot.command.slashcommands.arguments.asSlashArgument
import de.nycode.bankobot.commands.TagModule
import de.nycode.bankobot.commands.tag.searchTags
import de.nycode.bankobot.utils.Embeds
import de.nycode.bankobot.utils.Embeds.respondEmbed
import de.nycode.bankobot.utils.LazyItemProvider
import de.nycode.bankobot.utils.paginate
import dev.kord.x.commands.annotation.AutoWired
Expand All @@ -46,6 +48,13 @@ internal fun searchTagsCommand(): CommandSet = command("search-tag") {

invoke(WordArgument.named("Suchbegriff").asSlashArgument("Der Suchbegriff")) { search ->
val tags = searchTags(search)
if (tags.isEmpty()) {
respondEmbed(Embeds.error(
"Nichts gefunden!",
"Es scheint keine tags für den Suchbegriff $search zu geben"
))
return@invoke
}
LazyItemProvider(tags.size) { start, end ->
tags.subList(start, end + 1)
.map { it.name }
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/de/nycode/bankobot/utils/GoogleUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ package de.nycode.bankobot.utils

import de.nycode.bankobot.BankoBot
import de.nycode.bankobot.config.Config
import io.ktor.client.features.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import kotlinx.serialization.Serializable

object GoogleUtil {
Expand Down

0 comments on commit 64e6507

Please sign in to comment.