diff --git a/yiski-common/src/main/kotlin/one/devos/yiski/common/utils/EmbedHelpers.kt b/yiski-common/src/main/kotlin/one/devos/yiski/common/utils/EmbedHelpers.kt index c07dc4f..0aa64dd 100644 --- a/yiski-common/src/main/kotlin/one/devos/yiski/common/utils/EmbedHelpers.kt +++ b/yiski-common/src/main/kotlin/one/devos/yiski/common/utils/EmbedHelpers.kt @@ -1,18 +1,12 @@ package one.devos.yiski.common.utils +import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.data.Colors import java.awt.Color -import java.io.FileInputStream +import java.io.File import java.io.InputStream -import kotlin.io.path.toPath object EmbedHelpers { - fun imagesPath(pathToImage: String): InputStream { -// return FileInputStream(Path.of(pathToImage).toFile()) -// return this::class.java.classLoader.getResource(pathToImage)?.toURI()?.toPath()?.toFile()!!.inputStream() // this feels dangerous but thanks naz - return this::class.java.classLoader.getResourceAsStream(pathToImage) ?: error("Could not get image from given path") - } - fun successColor(successRed: Int = Colors.SUCCESS.r, successGreen: Int = Colors.SUCCESS.g, successBlue: Int = Colors.SUCCESS.b): Int { return Color(successRed, successGreen, successBlue).rgb } @@ -32,4 +26,12 @@ object EmbedHelpers { fun moderationColor(modRed: Int = Colors.MODERATION.r, modGreen: Int = Colors.MODERATION.g, modBlue: Int = Colors.MODERATION.b): Int { return Color(modRed, modGreen, modBlue).rgb } + + fun imageUpload(file: String): FileUpload { + return FileUpload.fromData(PathsHelper.filePath.path(PathsHelper.FileType.IMAGE, file), PathsHelper.filePath.file(file)) + } + + fun videoUpload(file: String): FileUpload { + return FileUpload.fromData(PathsHelper.filePath.path(PathsHelper.FileType.VIDEO, file), PathsHelper.filePath.file(file)) + } } \ No newline at end of file diff --git a/yiski-common/src/main/kotlin/one/devos/yiski/common/utils/PathsHelper.kt b/yiski-common/src/main/kotlin/one/devos/yiski/common/utils/PathsHelper.kt new file mode 100644 index 0000000..8cdb349 --- /dev/null +++ b/yiski-common/src/main/kotlin/one/devos/yiski/common/utils/PathsHelper.kt @@ -0,0 +1,24 @@ +package one.devos.yiski.common.utils + +import java.io.InputStream + +object PathsHelper { + enum class FileType(val s: String) { + VIDEO("assets/videos"), + IMAGE("assets/images") + } + + fun filePath(pathToFile: String): InputStream { + return this::class.java.classLoader.getResourceAsStream(pathToFile) ?: error("Could not get file from given path") + } + + object filePath { + fun file(fileName: String): String { + return fileName + } + + fun path(filetype: Enum, file: String): InputStream { + return filePath("${filetype.toString()}/${file.toString()}") + } + } +} \ No newline at end of file diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/DevTools.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/DevTools.kt index c46c8ee..fb8e5ea 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/DevTools.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/DevTools.kt @@ -7,6 +7,7 @@ import kotlinx.serialization.serializer import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.imageUpload import one.devos.yiski3.Yiski3 import one.devos.yiski3.data.DevToolsData import one.devos.yiski3.logger @@ -20,10 +21,10 @@ class DevTools : Scaffold { @SlashCommand(name = "devtools", description = "How to turn on Discord Dev Tools on stable branch") suspend fun devtools(ctx: SlashContext) { val devToolsToml = DevToolsToml.read() - val devToolsImage = EmbedHelpers.imagesPath(Yiski3.config.images.inlineStaticImagesTables.devtools) + val devToolsImage = Yiski3.config.images.inlineStaticImagesTables.devtools ctx.interaction.deferReply() - .setFiles(FileUpload.fromData(devToolsImage, Yiski3.config.images.inlineStaticImagesTables.devtoolsfile)) + .setFiles(imageUpload(devToolsImage)) .setEmbeds(Embed { title = devToolsToml.title.embed description = devToolsToml.text.embed @@ -33,7 +34,7 @@ class DevTools : Scaffold { field(devToolsToml.title.linux, devToolsToml.text.linux, false) field(devToolsToml.title.result, devToolsToml.text.result, false) field(devToolsToml.title.source, devToolsToml.text.source, false) - image = "attachment://${Yiski3.config.images.inlineStaticImagesTables.devtoolsfile}" + image = "attachment://${devToolsImage}" }) .await() diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/headcrab/Headcrab.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/headcrab/Headcrab.kt index b7f19b5..8802a29 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/headcrab/Headcrab.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/headcrab/Headcrab.kt @@ -6,6 +6,8 @@ import net.dv8tion.jda.api.entities.User import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.imageUpload +import one.devos.yiski.common.utils.PathsHelper import one.devos.yiski3.Yiski3 import one.devos.yiski3.data.HeadcrabSuccess import one.devos.yiski3.logger @@ -68,14 +70,14 @@ class Headcrab : Scaffold { } } - val inputStreamHeadcrabSuccess = EmbedHelpers.imagesPath(Yiski3.config.images.inlineGifImageTables.headcrabsuccess) + val inputStreamHeadcrabSuccess = PathsHelper.filePath.file(Yiski3.config.images.inlineGifImageTables.headcrabsuccess) ctx.interaction.deferReply() - .setFiles(FileUpload.fromData(inputStreamHeadcrabSuccess, Yiski3.config.images.inlineGifImageTables.headcrabfailfile)) + .setFiles(imageUpload(Yiski3.config.images.inlineGifImageTables.headcrabfail)) .setEmbeds(Embed { title = "Headcrab failed!" - description = "${user.asMention} has succsefully deflected the headcrab from ${ctx.author.asMention}!" - image = "attachment://${Yiski3.config.images.inlineGifImageTables.headcrabsuccessfile}" // Aubree is being a massive HIMBO + description = "${user.asMention} has successfully deflected the headcrab from ${ctx.author.asMention}!" + image = "attachment://${Yiski3.config.images.inlineGifImageTables.headcrabsuccess}" // Aubree is being a massive HIMBO color = EmbedHelpers.infoColor() if (reason != null) { field("", reasonAsNull(), false) diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Antihorny.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Antihorny.kt index 8ead0db..7565698 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Antihorny.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Antihorny.kt @@ -4,8 +4,10 @@ import dev.minn.jda.ktx.coroutines.await import net.dv8tion.jda.api.entities.User import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule -import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.videoUpload +import one.devos.yiski.common.utils.PathsHelper import one.devos.yiski3.Yiski3 +import one.devos.yiski3.logger import xyz.artrinix.aviation.command.slash.SlashContext import xyz.artrinix.aviation.command.slash.annotations.Description import xyz.artrinix.aviation.command.slash.annotations.SlashCommand @@ -15,10 +17,12 @@ import xyz.artrinix.aviation.entities.Scaffold class Antihorny : Scaffold { @SlashCommand(name = "antihorny", description = "For when you need to pull out the spray bottle") suspend fun antihorny(ctx: SlashContext, @Description("Suspect") user: User) { - val antiHorny = EmbedHelpers.imagesPath(Yiski3.config.videos.antihorny) + val antiHorny = Yiski3.config.videos.antihorny + + logger.debug { videoUpload(antiHorny) } ctx.interaction.deferReply() .setContent(user.asMention) - .setFiles(FileUpload.fromData(antiHorny, Yiski3.config.videos.antihornyfile)).await() + .setFiles(videoUpload(antiHorny)).await() } } \ No newline at end of file diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Gasp.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Gasp.kt index 7b71698..f8812d7 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Gasp.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Gasp.kt @@ -5,6 +5,8 @@ import dev.minn.jda.ktx.messages.Embed import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.videoUpload +import one.devos.yiski.common.utils.PathsHelper import one.devos.yiski3.Yiski3 import xyz.artrinix.aviation.command.slash.SlashContext import xyz.artrinix.aviation.command.slash.annotations.SlashCommand @@ -14,7 +16,7 @@ import xyz.artrinix.aviation.entities.Scaffold class Gasp : Scaffold { @SlashCommand(name = "rtx", description = "Its just like real life!") suspend fun gasp(ctx: SlashContext) { - val gasp = EmbedHelpers.imagesPath(Yiski3.config.videos.gasp) + val gasp = Yiski3.config.videos.gasp ctx.interaction.deferReply() .setEmbeds(Embed { @@ -22,6 +24,6 @@ class Gasp : Scaffold { description = "warning: loud" color = EmbedHelpers.infoColor() }).await() - ctx.channel.sendFiles(FileUpload.fromData(gasp, Yiski3.config.videos.gaspfile)).await() + ctx.channel.sendFiles(videoUpload(gasp)).await() } } \ No newline at end of file diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/IMS.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/IMS.kt index b008ba0..39b0455 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/IMS.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/IMS.kt @@ -5,6 +5,8 @@ import dev.minn.jda.ktx.messages.Embed import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.imageUpload +import one.devos.yiski.common.utils.PathsHelper import one.devos.yiski3.Yiski3 import xyz.artrinix.aviation.command.slash.SlashContext import xyz.artrinix.aviation.command.slash.annotations.SlashCommand @@ -14,14 +16,14 @@ import xyz.artrinix.aviation.entities.Scaffold class IMS : Scaffold { @SlashCommand(name = "ims", description = "yes") suspend fun ims(ctx: SlashContext) { - val imsImage = EmbedHelpers.imagesPath(Yiski3.config.images.inlineStaticImagesTables.ims) + val imsImage = Yiski3.config.images.inlineStaticImagesTables.ims ctx.interaction.deferReply() - .setFiles(FileUpload.fromData(imsImage, Yiski3.config.images.inlineStaticImagesTables.imsfile)) + .setFiles(imageUpload(imsImage)) .setEmbeds(Embed { title = "IMS" description = "Go fuck yourself" - image = "attachment://${Yiski3.config.images.inlineStaticImagesTables.imsfile}" + image = "attachment://${imsImage}" color = EmbedHelpers.infoColor() }) .await() diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/MemoryLeak.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/MemoryLeak.kt index 59737e6..6f1d22c 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/MemoryLeak.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/MemoryLeak.kt @@ -5,6 +5,8 @@ import dev.minn.jda.ktx.messages.Embed import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.videoUpload +import one.devos.yiski.common.utils.PathsHelper import one.devos.yiski3.Yiski3 import xyz.artrinix.aviation.command.slash.SlashContext import xyz.artrinix.aviation.command.slash.annotations.SlashCommand @@ -14,7 +16,7 @@ import xyz.artrinix.aviation.entities.Scaffold class MemoryLeak : Scaffold { @SlashCommand(name = "memoryleak", description = "signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)") suspend fun memoryleak(ctx: SlashContext) { - val memoryLeak = EmbedHelpers.imagesPath(Yiski3.config.videos.memoryleak) + val memoryLeak = Yiski3.config.videos.memoryleak ctx.interaction.deferReply() .setEmbeds(Embed { @@ -22,6 +24,6 @@ class MemoryLeak : Scaffold { description = "Buffer overflow" color = EmbedHelpers.infoColor() }).await() - ctx.channel.sendFiles(FileUpload.fromData(memoryLeak, Yiski3.config.videos.memoryleakfile)).await() + ctx.channel.sendFiles(videoUpload(memoryLeak)).await() } } \ No newline at end of file diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/RTX.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/RTX.kt index 7cfb731..a89b326 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/RTX.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/RTX.kt @@ -5,6 +5,8 @@ import dev.minn.jda.ktx.messages.Embed import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.videoUpload +import one.devos.yiski.common.utils.PathsHelper import one.devos.yiski3.Yiski3 import xyz.artrinix.aviation.command.slash.SlashContext import xyz.artrinix.aviation.command.slash.annotations.SlashCommand @@ -14,7 +16,7 @@ import xyz.artrinix.aviation.entities.Scaffold class RTX : Scaffold { @SlashCommand(name = "rtx", description = "Its just like real life!") suspend fun rtx(ctx: SlashContext) { - val rtxVideo = EmbedHelpers.imagesPath(Yiski3.config.videos.rtx) + val rtxVideo = Yiski3.config.videos.rtx ctx.interaction.deferReply() .setEmbeds(Embed { @@ -22,6 +24,6 @@ class RTX : Scaffold { description = "warning: loud" color = EmbedHelpers.infoColor() }).await() - ctx.channel.sendFiles(FileUpload.fromData(rtxVideo, Yiski3.config.videos.rtxfile)).await() + ctx.channel.sendFiles(videoUpload(rtxVideo)).await() } } \ No newline at end of file diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Teehee.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Teehee.kt new file mode 100644 index 0000000..16b8c10 --- /dev/null +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Teehee.kt @@ -0,0 +1,31 @@ +package one.devos.yiski3.commands.silly + +import dev.minn.jda.ktx.coroutines.await +import dev.minn.jda.ktx.messages.Embed +import net.dv8tion.jda.api.utils.FileUpload +import one.devos.yiski.common.annotations.YiskiModule +import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.imageUpload +import one.devos.yiski.common.utils.PathsHelper +import one.devos.yiski3.Yiski3 +import xyz.artrinix.aviation.command.slash.SlashContext +import xyz.artrinix.aviation.command.slash.annotations.SlashCommand +import xyz.artrinix.aviation.entities.Scaffold + +@YiskiModule +class Teehee : Scaffold { + @SlashCommand(name = "teehee", description = "got a little silly") + suspend fun teehee(ctx: SlashContext) { + val file = Yiski3.config.images.inlineStaticImagesTables.teehee + + ctx.interaction.deferReply() + .setFiles(imageUpload(file)) + .setEmbeds(Embed { + title = "teehee" + description = "*inkling sounds*" + image = "attachment://${file}" + color = EmbedHelpers.infoColor() + }) + .await() + } +} \ No newline at end of file diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Token.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Token.kt index 6c9fcfd..3d1710a 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Token.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/Token.kt @@ -5,6 +5,8 @@ import dev.minn.jda.ktx.messages.Embed import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.imageUpload +import one.devos.yiski.common.utils.PathsHelper import one.devos.yiski3.Yiski3 import xyz.artrinix.aviation.command.slash.SlashContext import xyz.artrinix.aviation.command.slash.annotations.SlashCommand @@ -14,14 +16,14 @@ import xyz.artrinix.aviation.entities.Scaffold class Token : Scaffold { @SlashCommand(name = "token", description = "Its always the token") suspend fun token(ctx: SlashContext) { - val imsImage = EmbedHelpers.imagesPath(Yiski3.config.images.inlineStaticImagesTables.token) + val imsImage = Yiski3.config.images.inlineStaticImagesTables.token ctx.interaction.deferReply() - .setFiles(FileUpload.fromData(imsImage, Yiski3.config.images.inlineStaticImagesTables.tokenfile)) + .setFiles(imageUpload(Yiski3.config.images.inlineStaticImagesTables.token)) .setEmbeds(Embed { title = "Token" description = "I love leaking my Token!" - image = "attachment://${Yiski3.config.images.inlineStaticImagesTables.tokenfile}" + image = "attachment://${Yiski3.config.images.inlineStaticImagesTables.token}" color = EmbedHelpers.infoColor() }) .await() diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/WhatAreYouDoing.kt b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/WhatAreYouDoing.kt index a0459ab..9602c68 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/WhatAreYouDoing.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/commands/silly/WhatAreYouDoing.kt @@ -5,6 +5,8 @@ import dev.minn.jda.ktx.messages.Embed import net.dv8tion.jda.api.utils.FileUpload import one.devos.yiski.common.annotations.YiskiModule import one.devos.yiski.common.utils.EmbedHelpers +import one.devos.yiski.common.utils.EmbedHelpers.imageUpload +import one.devos.yiski.common.utils.PathsHelper import one.devos.yiski3.Yiski3 import xyz.artrinix.aviation.command.slash.SlashContext import xyz.artrinix.aviation.command.slash.annotations.SlashCommand @@ -14,7 +16,7 @@ import xyz.artrinix.aviation.entities.Scaffold class WhatAreYouDoing : Scaffold { @SlashCommand(name = "whatareyoudoing", description = "STOP PLEASE STOP FOR THE LO-") suspend fun whatareyoudoing(ctx: SlashContext) { - val whatAreYouDoing = EmbedHelpers.imagesPath(Yiski3.config.videos.whatareyoudoing) + val whatAreYouDoing = Yiski3.config.videos.whatareyoudoing ctx.interaction.deferReply() .setEmbeds(Embed { @@ -22,6 +24,6 @@ class WhatAreYouDoing : Scaffold { description = "STOP PLEASE STOP FOR THE LO-" color = EmbedHelpers.infoColor() }).await() - ctx.channel.sendFiles(FileUpload.fromData(whatAreYouDoing, Yiski3.config.videos.whatareyoudoingfile)).await() + ctx.channel.sendFiles(imageUpload(whatAreYouDoing)).await() } } \ No newline at end of file diff --git a/yiski3/src/main/kotlin/one/devos/yiski3/data/Yiski3ConfigData.kt b/yiski3/src/main/kotlin/one/devos/yiski3/data/Yiski3ConfigData.kt index 3b82e2a..3651b32 100644 --- a/yiski3/src/main/kotlin/one/devos/yiski3/data/Yiski3ConfigData.kt +++ b/yiski3/src/main/kotlin/one/devos/yiski3/data/Yiski3ConfigData.kt @@ -22,32 +22,23 @@ data class Yiski3ConfigData( @Serializable data class VideosConfig( val antihorny: String, - val antihornyfile: String, val gasp: String, - val gaspfile: String, val memoryleak: String, - val memoryleakfile: String, val rtx: String, - val rtxfile: String, val whatareyoudoing: String, - val whatareyoudoingfile: String ) } @Serializable data class StaticImageTables( val devtools: String, - val devtoolsfile: String, val ims: String, - val imsfile: String, val token: String, - val tokenfile: String + val teehee: String, ) @Serializable data class GifImageTables( val headcrabsuccess: String, - val headcrabsuccessfile: String, val headcrabfail: String, - val headcrabfailfile: String, ) \ No newline at end of file diff --git a/yiski3/src/main/resources/assets/images/teehee.png b/yiski3/src/main/resources/assets/images/teehee.png new file mode 100644 index 0000000..b863841 Binary files /dev/null and b/yiski3/src/main/resources/assets/images/teehee.png differ