Skip to content

Commit d3c8651

Browse files
committed
profile upgrades
1 parent 4047a59 commit d3c8651

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

src/main/kotlin/commands/social/SetBackground.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ import miniManual
1414
import net.dv8tion.jda.api.JDA
1515
import net.dv8tion.jda.api.entities.Message
1616
import net.dv8tion.jda.api.entities.User
17+
import net.dv8tion.jda.api.entities.emoji.Emoji
18+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
19+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent
20+
import net.dv8tion.jda.api.hooks.ListenerAdapter
1721
import net.dv8tion.jda.api.interactions.components.buttons.Button
1822
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle
23+
import net.dv8tion.jda.api.interactions.components.selections.SelectMenu
24+
import net.dv8tion.jda.api.interactions.components.selections.SelectOption
1925
import net.dv8tion.jda.api.requests.restaction.WebhookMessageEditAction
2026
import net.dv8tion.jda.api.utils.FileUpload
2127
import org.atteo.evo.inflector.English
@@ -28,6 +34,27 @@ import java.awt.image.BufferedImage
2834
import java.net.URL
2935
import javax.imageio.ImageIO
3036

37+
object DropdownBot : ListenerAdapter() {
38+
override fun onSlashCommandInteraction(event: SlashCommandInteractionEvent) {
39+
if (event.name == "food") {
40+
val selectMenu = SelectMenu.create("choose-food")
41+
.addOption("Pizza", "pizza", "Classic") // SelectOption with only the label, value, and description
42+
.addOptions(
43+
SelectOption.of("Hamburger", "hamburger") // another way to create a SelectOption
44+
.withDescription("Tasty") // this time with a description
45+
.withEmoji(Emoji.fromUnicode("\uD83C\uDF54")) // and an emoji
46+
.withDefault(true)) // while also being the default option
47+
.build()
48+
}
49+
}
50+
51+
override fun onSelectMenuInteraction(event: SelectMenuInteractionEvent) {
52+
if (event.componentId == "choose-food") {
53+
event.reply("You chose " + event.values[0]).queue()
54+
}
55+
}
56+
}
57+
3158
fun setBackgroundCommand(jda: JDA) {
3259
jda.onCommand("set_background") { event ->
3360
try {
@@ -67,6 +94,9 @@ fun setBackgroundCommand(jda: JDA) {
6794
val card = makeProfileCard(event.user, getSlicedBG())
6895
return event.hook.editMessage(content = "**Preview!**")
6996
.setFiles(FileUpload.fromData(bufferedImageToByteArray(card), "profile.png"))
97+
}
98+
fun getFontDropdown() {
99+
70100
}
71101
fun getButtons(): Array<Button> {
72102
val upButton = jda.button(

src/main/kotlin/ui/RealPaginator.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,17 @@ class Paginator internal constructor(private val nonce: String, private val ttl:
5555

5656
private var index = 0
5757
private val pageCache = mutableListOf<MessageCreateData>()
58-
private val nextPage: MessageCreateData get() = pageCache[++index]
59-
private val prevPage: MessageCreateData get() = pageCache[--index]
58+
private val nextPage: MessageCreateData get() {
59+
index = (index + 1) % pageCache.size
60+
return pageCache[index]
61+
}
62+
private val prevPage: MessageCreateData get() {
63+
index = (index - 1)
64+
if(index < 0) {
65+
index = pageCache.size - 1
66+
}
67+
return pageCache[index]
68+
}
6069
var customActionComponents: List<ActionComponent>? = null
6170
var filter: (ButtonInteraction) -> Boolean = { true }
6271
var injectMessageCallback: ((index: Int, messageEdit: MessageEditCallbackAction) -> Unit)? = null
@@ -72,8 +81,8 @@ class Paginator internal constructor(private val nonce: String, private val ttl:
7281

7382
internal fun getControls(): ActionRow {
7483
val controls: MutableList<ActionComponent> = mutableListOf(
75-
prev.withDisabled(index == 0).withId("$nonce:prev"),
76-
next.withDisabled(index == pageCache.size - 1).withId("$nonce:next")
84+
prev.withId("$nonce:prev"),
85+
next.withId("$nonce:next")
7786
)
7887
if(customActionComponents != null) {
7988
controls.addAll(customActionComponents!!)

src/main/kotlin/utils/MakeProfileCard.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import org.atteo.evo.inflector.English
66
import java.awt.Color
77
import java.awt.Font
88
import java.awt.image.BufferedImage
9+
import java.net.URL
10+
import javax.imageio.ImageIO
911

1012
val profileCardHeight = 128
1113
fun makeProfileCard(user: User, overrideBackground: BufferedImage?): BufferedImage {
1214
val thingyUser = userDao.queryBuilder().selectColumns("id", "generationsDone").where().eq("discordUserID", user.id).queryForFirst()
15+
val pfp = ImageIO.read(URL(user.avatarUrl)).resize(64, 64)
1316
val card = BufferedImage(512, profileCardHeight, BufferedImage.TYPE_INT_RGB)
1417
val labelFont = Font("Arial", Font.PLAIN, 16)
1518
val valFont = Font("Arial", Font.BOLD, 18)
16-
1719
val g = card.graphics
1820

1921
fun drawBackground(bg: BufferedImage) {
@@ -22,16 +24,18 @@ fun makeProfileCard(user: User, overrideBackground: BufferedImage?): BufferedIma
2224
if (overrideBackground != null) {
2325
drawBackground(overrideBackground)
2426
}
27+
g.drawImage(pfp, 10, 10, null)
28+
val pfpSideX = pfp.width + 10
2529
g.color = Color.WHITE
2630
g.font = valFont
27-
g.drawString(user.name, 20, 25)
31+
g.drawString(user.name, pfpSideX + 10, 25)
2832

29-
fun addLabelAndValue(label: String, value: String) {
30-
g.drawString(value, 20, 60)
33+
fun addLabelAndValue(x: Int, y: Int, label: String, value: String) {
34+
g.drawString(value, x, y)
3135
val valWidth = g.fontMetrics.stringWidth(value)
3236
g.font = labelFont
33-
g.drawString(label, valWidth + 40, 60)
37+
g.drawString(label, x + valWidth + 10, y)
3438
}
35-
addLabelAndValue(English.plural("Generation", if(thingyUser.generationsDone > 1) 2 else 1), thingyUser.generationsDone.toString())
39+
addLabelAndValue(pfpSideX + 10, 60, English.plural("Generation", if(thingyUser.generationsDone > 1) 2 else 1), thingyUser.generationsDone.toString())
3640
return card
3741
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package utils
2+
3+
import java.awt.Image
4+
import java.awt.image.BufferedImage
5+
6+
fun BufferedImage.resize(newW: Int, newH: Int): BufferedImage {
7+
val tmp = this.getScaledInstance(newW, newH, Image.SCALE_SMOOTH)
8+
val dimg = BufferedImage(newW, newH, BufferedImage.TYPE_INT_RGB)
9+
val g2d = dimg.createGraphics()
10+
g2d.drawImage(tmp, 0, 0, null)
11+
g2d.dispose()
12+
return dimg
13+
}

0 commit comments

Comments
 (0)