All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.jakejmattson.kutils.api.arguments.FileArg.kt Maven / Gradle / Ivy

There is a newer version: 0.18.1
Show newest version
package me.jakejmattson.kutils.api.arguments

import me.jakejmattson.kutils.api.dsl.arguments.*
import me.jakejmattson.kutils.api.dsl.command.CommandEvent
import java.io.File

open class FileArg(override val name: String = "File") : ArgumentType() {
    companion object : FileArg()

    override fun convert(arg: String, args: List, event: CommandEvent<*>): ArgumentResult {
        val attachments = event.message.attachments

        if (attachments.isEmpty())
            return ArgumentResult.Error("$name argument requires a message attachment.")

        val file = attachments.first().downloadToFile().get()

        return ArgumentResult.Success(file, 0)
    }

    override fun generateExamples(event: CommandEvent<*>) = listOf("File")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy