Skip to content

Commit

Permalink
Support embeds on custom commands
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Mar 9, 2024
1 parent cfe2f6f commit 44fb0a7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
41 changes: 41 additions & 0 deletions commands/ship.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Hey there, this is a super advanced command.
# Please look at the hello world command to learn how to make simple commands

name: ship
description: Ship two people to see how compatible they are!

input:
- name: user1
type: USER
desc: Left side of the heart
required: true
- name: user2
type: USER
desc: Right side of the heart (will be you by default)
required: false

output: |-
import net.dv8tion.jda.api.EmbedBuilder
import kotlin.math.floor
// Functions first
fun calculateScore(firstId: Long, secondId: Long): Int {
if (firstId == secondId) {
return 100
}
return floor((firstId + secondId) / 7.0) % 100
}
val leftUser = event.getOption("user1")!!.asMember
val rightUser = event.getOption("user2")?.asMember ?: event.member!!
val score = calculateScore(leftUser.idLong, rightUser.idLong)
// TODO: fetch the image
// Fun fact, you can return embeds as well
EmbedBuilder()
.setTitle("${leftUser.effectiveName} and ${rightUser.effectiveName}")
.addField("Your love score is $score%", "", false)
.build()
5 changes: 5 additions & 0 deletions src/main/kotlin/me/duncte123/io/commands/UserCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import me.duncte123.io.ICommand
import net.dv8tion.jda.api.entities.MessageEmbed
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
import net.dv8tion.jda.api.interactions.commands.build.OptionData
import net.dv8tion.jda.api.requests.RestAction
Expand Down Expand Up @@ -81,6 +82,10 @@ data class UserCommand @JsonCreator constructor (
}
}

is MessageEmbed -> {
event.hook.sendMessageEmbeds(out).queue()
}

else -> {
val toString = out.toString()

Expand Down

0 comments on commit 44fb0a7

Please sign in to comment.