Skip to content

Commit

Permalink
defaultUsageGroupOf function
Browse files Browse the repository at this point in the history
  • Loading branch information
ileukocyte committed Aug 14, 2022
1 parent c18c0f0 commit cd283b4
Show file tree
Hide file tree
Showing 25 changed files with 59 additions and 56 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repositories {

dependencies {
// Discord
implementation(group = "com.github.DV8FromtheWorld", name = "JDA", version = "c252302508") {
implementation(group = "com.github.DV8FromtheWorld", name = "JDA", version = "c838479f74") {
exclude(module = "opus-java")
}
implementation(group = "com.sedmelluq", name = "lavaplayer", version = "1.3.78")
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/io/ileukocyte/hibernum/commands/commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ interface TextCommand : GenericCommand {

fun usageGroupOf(vararg usages: ClassicTextUsage) = ClassicTextUsageGroup(usages.toList())

fun defaultUsageGroupOf(vararg usages: String) = ClassicTextUsageGroup(usages.map { ClassicTextUsage(it) })

/**
* A type of command that can be used as a classic text command exclusively
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class EvalCommand : TextCommand, MessageContextOnlyCommand {
)
override val aliases = setOf("exec", "execute", "kotlin", "kt")
override val usages = setOf(
usageGroupOf("Kotlin code".toClassicTextUsage()),
usageGroupOf("reply to a message with Kotlin code".toClassicTextUsage()),
defaultUsageGroupOf("Kotlin code"),
defaultUsageGroupOf("reply to a message with Kotlin code"),
)

private val packages get() = buildString {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.ileukocyte.hibernum.commands.`fun`
import io.ileukocyte.hibernum.Immutable
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.replyEmbed
import io.ileukocyte.hibernum.extensions.sendEmbed

Expand All @@ -16,7 +16,7 @@ class EightBallCommand : TextCommand {
override val name = "8ball"
override val description = "Asks your question of the Magic 8 Ball"
override val aliases = setOf("eightball", "eight-ball")
override val usages = setOf(usageGroupOf("question".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("question"))
override val options = setOf(
OptionData(OptionType.STRING, "question", "The question to ask of the Magic 8 Ball", true))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.ileukocyte.hibernum.Immutable
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.*
import io.ileukocyte.hibernum.utils.*

Expand Down Expand Up @@ -35,9 +35,7 @@ class GuessNumberCommand : TextCommand {
.setMinValue(5)
.setMaxValue(500_000),
)
override val usages = setOf(
usageGroupOf("min".toClassicTextUsage(), "max".toClassicTextUsage()),
)
override val usages = setOf(defaultUsageGroupOf("min", "max"))

override suspend fun invoke(event: MessageReceivedEvent, args: String?) {
val (min, max) = args?.split("\\s+".toRegex())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TextToImageCommand : TextCommand, MessageContextOnlyCommand {
override val interactionName = "tti"
override val description = "Creates an image containing the provided text"
override val aliases = setOf("tti")
override val usages = setOf(usageGroupOf("input".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("input"))
override val cooldown = 5L

override suspend fun invoke(event: MessageReceivedEvent, args: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.ileukocyte.hibernum.commands.information
import io.ileukocyte.hibernum.builders.buildEmbed
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.asWord
import io.ileukocyte.hibernum.extensions.await
import io.ileukocyte.hibernum.extensions.escapeMarkdown
Expand All @@ -26,7 +26,7 @@ class EmoteCommand : TextCommand {
override val aliases = setOf("emoji", "emoji-info", "emote-info")
override val options = setOf(
OptionData(OptionType.STRING, "emote", "The custom emoji to check information about", true))
override val usages = setOf(usageGroupOf("custom emoji".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("custom emoji"))

override suspend fun invoke(event: MessageReceivedEvent, args: String?) {
val emote = event.message.mentions.customEmojis.firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import io.ileukocyte.hibernum.builders.buildEmbed
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.commands.information.UserCommand.Companion.FEATURED_PERMISSIONS
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.extensions.*
import io.ileukocyte.hibernum.utils.getImageBytes

Expand All @@ -28,9 +28,9 @@ class RoleCommand : TextCommand {
override val description = "Sends the available information about the specified role"
override val aliases = setOf("role-info")
override val usages = setOf(
usageGroupOf("role name".toClassicTextUsage()),
usageGroupOf("role mention".toClassicTextUsage()),
usageGroupOf("role ID".toClassicTextUsage()),
defaultUsageGroupOf("role name"),
defaultUsageGroupOf("role mention"),
defaultUsageGroupOf("role ID"),
)
override val options = setOf(
OptionData(OptionType.ROLE, "role", "The role to check information about", true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.ileukocyte.hibernum.builders.buildEmbed
import io.ileukocyte.hibernum.commands.ClassicTextOnlyCommand
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.MessageContextOnlyCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.await
import io.ileukocyte.hibernum.extensions.escapeMarkdown
import io.ileukocyte.hibernum.utils.getDominantColorByImageUrl
Expand All @@ -27,8 +27,8 @@ class StickerCommand : ClassicTextOnlyCommand, MessageContextOnlyCommand {
override val description = "Sends the available information about the provided sticker"
override val aliases = setOf("sticker-info")
override val usages = setOf(
usageGroupOf("sticker".toClassicTextUsage()),
usageGroupOf("reply to a sticker message".toClassicTextUsage()),
defaultUsageGroupOf("sticker"),
defaultUsageGroupOf("reply to a sticker message"),
)

override suspend fun invoke(event: MessageReceivedEvent, args: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.ileukocyte.hibernum.audio.audioPlayer
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.isInt
import io.ileukocyte.hibernum.extensions.replySuccess
import io.ileukocyte.hibernum.extensions.sendSuccess
Expand All @@ -22,7 +22,7 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData
class MoveCommand : TextCommand {
override val name = "move"
override val description = "Moves the selected track in the queue to the specified position"
override val usages = setOf(usageGroupOf("song".toClassicTextUsage(), "index".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("song", "index"))
override val options = setOf(
OptionData(OptionType.INTEGER, "song", "The index of the song to move", true),
OptionData(OptionType.INTEGER, "index", "The index to move the song to", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.ileukocyte.hibernum.audio.canJoinFromAnother
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.*
import io.ileukocyte.hibernum.handlers.CommandHandler
import io.ileukocyte.hibernum.utils.YOUTUBE_LINK_REGEX
Expand All @@ -37,8 +37,8 @@ class PlayCommand : TextCommand {
OptionData(OptionType.ATTACHMENT, "attachment", "The media file to play"),
)
override val usages = setOf(
usageGroupOf("query".toClassicTextUsage()),
usageGroupOf("file".toClassicTextUsage()),
defaultUsageGroupOf("query"),
defaultUsageGroupOf("file"),
)

override suspend fun invoke(event: MessageReceivedEvent, args: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.ileukocyte.hibernum.commands.music
import io.ileukocyte.hibernum.audio.audioPlayer
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.replySuccess
import io.ileukocyte.hibernum.extensions.sendSuccess

Expand All @@ -15,7 +15,7 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData
class RemoveCommand : TextCommand {
override val name = "remove"
override val description = "Removes the selected track from the queue"
override val usages = setOf(usageGroupOf("song".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("song"))
override val options = setOf(
OptionData(OptionType.INTEGER, "song", "The number of the song to remove", true))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RequeueCommand : TextCommand {
override val name = "requeue"
override val description = "Adds the specified (or currently playing) song to the end of the queue"
override val aliases = setOf("re-add", "readd", "re-queue")
override val usages = setOf(usageGroupOf("song".toClassicTextUsage()))
override val usages = setOf(usageGroupOf("song".toClassicTextUsage(true)))
override val options = setOf(
OptionData(OptionType.INTEGER, "song", "The number of the song to readd"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.ileukocyte.hibernum.audio.audioPlayer
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.replySuccess
import io.ileukocyte.hibernum.extensions.sendSuccess
import io.ileukocyte.hibernum.utils.TIME_CODE_REGEX
Expand All @@ -23,7 +23,7 @@ class SeekCommand : TextCommand {
override val name = "seek"
override val description = "Jumps to the specified time while playing the track"
override val aliases = setOf("jump")
override val usages = setOf(usageGroupOf("[r(ewind):/f(ast-forward):]time code".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("[r(ewind):/f(ast-forward):]time code"))
override val options = setOf(
OptionData(
OptionType.STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.ileukocyte.hibernum.audio.audioPlayer
import io.ileukocyte.hibernum.audio.customUserData
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.await
import io.ileukocyte.hibernum.extensions.setFailureEmbed

Expand All @@ -23,7 +23,7 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData
class SelectCommand : TextCommand {
override val name = "select"
override val description = "Selects another track from the queue and plays it"
override val usages = setOf(usageGroupOf("song".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("song"))
override val options = setOf(
OptionData(OptionType.INTEGER, "song", "The number of the song to play", true))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.ileukocyte.hibernum.builders.buildEmbed
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.*
import io.ileukocyte.hibernum.extensions.EmbedType
import io.ileukocyte.hibernum.utils.*
Expand Down Expand Up @@ -41,7 +41,7 @@ class YouTubePlayCommand : TextCommand {
.addChoice("Videos", "videos")
.addChoice("Playlists", "playlists"),
)
override val usages = setOf(usageGroupOf("query".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("query"))
override val cooldown = 5L

override suspend fun invoke(event: MessageReceivedEvent, args: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.ileukocyte.hibernum.builders.buildEmbed
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.*

import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent
Expand All @@ -24,7 +24,7 @@ class CharacterCommand : TextCommand {
override val aliases = setOf("character")
override val options = setOf(
OptionData(OptionType.STRING, "input", "The characters provided"))
override val usages = setOf(usageGroupOf("input".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("input"))

override suspend fun invoke(event: MessageReceivedEvent, args: String?) {
val input = args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.ileukocyte.hibernum.builders.buildEmbed
import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.await
import io.ileukocyte.hibernum.utils.getImageBytes

Expand All @@ -31,7 +31,7 @@ class ColorCommand : TextCommand {
override val name = "color"
override val description = "Sends brief information about the color provided by its hexadecimal representation"
override val aliases = setOf("color-info", "colour", "colour-info")
override val usages = setOf(usageGroupOf("hex".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("hex"))
override val options = setOf(
OptionData(OptionType.STRING, "hex", "The color's hexadecimal representation", true))
override val cooldown = 3L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.ileukocyte.hibernum.commands.CommandException
import io.ileukocyte.hibernum.commands.GenericCommand.StaleComponentHandling
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.*
import io.ileukocyte.hibernum.utils.awaitEvent

Expand Down Expand Up @@ -47,7 +47,7 @@ class DictionaryCommand : TextCommand {
override val aliases = setOf("define", "definition", "dict", "merriam-webster", "mw")
override val options = setOf(
OptionData(OptionType.STRING, "term", "The term to define", true))
override val usages = setOf(usageGroupOf("term".toClassicTextUsage()))
override val usages = setOf(defaultUsageGroupOf("term"))
override val cooldown = 5L
override val staleComponentHandling = StaleComponentHandling.REMOVE_COMPONENTS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class QRCommand : TextCommand, SubcommandHolder, MessageContextOnlyCommand {
.addOption(OptionType.ATTACHMENT, "image", "The image to read a QR code from", true) to ::read,
)
override val usages = setOf(
usageGroupOf("text input".toClassicTextUsage()),
usageGroupOf("image".toClassicTextUsage()),
defaultUsageGroupOf("text input"),
defaultUsageGroupOf("image"),
)

override suspend fun invoke(event: MessageReceivedEvent, args: String?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.ileukocyte.hibernum.Immutable
import io.ileukocyte.hibernum.builders.buildEmbed
import io.ileukocyte.hibernum.commands.NoArgumentsException
import io.ileukocyte.hibernum.commands.TextCommand
import io.ileukocyte.hibernum.commands.usageGroupOf
import io.ileukocyte.hibernum.commands.defaultUsageGroupOf
import io.ileukocyte.hibernum.extensions.await
import io.ileukocyte.hibernum.extensions.limitTo
import io.ileukocyte.hibernum.extensions.remove
Expand Down Expand Up @@ -37,8 +37,8 @@ class SayCommand : TextCommand {
override val description = "Sends your message on behalf of the bot as an embed message"
override val aliases = setOf("announce")
override val usages = setOf(
usageGroupOf("text input".toClassicTextUsage()),
usageGroupOf("image file".toClassicTextUsage()),
defaultUsageGroupOf("text input"),
defaultUsageGroupOf("image file"),
)
override val options = setOf(
OptionData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class SpotifyCommand : TextCommand {
override val name = "spotify"
override val description = "Searches a Spotify track by the provided query and sends some information about one"
override val usages = setOf(
usageGroupOf("search term".toClassicTextUsage()),
usageGroupOf("link".toClassicTextUsage()),
usageGroupOf("reply to a Spotify track link message".toClassicTextUsage()),
defaultUsageGroupOf("search term"),
defaultUsageGroupOf("link"),
defaultUsageGroupOf("reply to a Spotify track link message"),
)
override val options = setOf(
OptionData(OptionType.STRING, "query", "A search term or a link", true))
Expand Down
Loading

0 comments on commit cd283b4

Please sign in to comment.