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

feat: Add item cost to schematics embedding #262

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import java.io.ByteArrayOutputStream
import kotlinx.coroutines.future.await
import mindustry.Vars
import mindustry.game.Schematic
import net.dv8tion.jda.api.JDA
import net.dv8tion.jda.api.entities.Emote
import net.dv8tion.jda.api.entities.Member
import net.dv8tion.jda.api.entities.Message
import net.dv8tion.jda.api.entities.channel.ChannelType
Expand Down Expand Up @@ -177,6 +179,19 @@ class MindustryContentListener(instances: InstanceManager) : ImperiumApplication
return
}
.getOrThrow()
val cost = StringBuilder()
for (stack in schem.requirements()) {
// Uses bots uploaded emojis in the developer portal otherwise defaults to discord's
// built in :question: emote
// Requires you to upload the emotes. Format "itemname" eg: "blastcompound" vs
// "blast-compound"
val emotes = bot.getEmotesByName(stack.item.name.replace("-", ""), true)
val result = if (emotes.isNotEmpty()) emotes[0] else null

cost.append(result?.asMention ?: ":question:")
cost.append(stack.amount).append(" ")
}

channel
.sendMessage(
MessageCreate {
Expand All @@ -189,6 +204,7 @@ class MindustryContentListener(instances: InstanceManager) : ImperiumApplication
author(member)
color = MINDUSTRY_ACCENT_COLOR.rgb
title = schematic.name().stripMindustryColors()
field("Requirements", cost.toString().trim())
description = schematic.description().stripMindustryColors()
image = "attachment://preview.png"
}
Expand Down
Loading