diff --git a/.github/workflows/publish-bot.yml b/.github/workflows/publish-bot.yml index 513101f..7e9dc9a 100644 --- a/.github/workflows/publish-bot.yml +++ b/.github/workflows/publish-bot.yml @@ -44,7 +44,7 @@ jobs: - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} - - name: Trigger dev webhook - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.WEBHOOK_URL }} +# - name: Trigger dev webhook +# uses: distributhor/workflow-webhook@v3 +# env: +# webhook_url: ${{ secrets.WEBHOOK_URL }} diff --git a/README.md b/README.md index d2c5b53..ef744cf 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,7 @@ ## How to host yourself? - use docker! + + +## Planned features +- an easy way for non programmers to add commands through yaml files diff --git a/src/main/kotlin/me/duncte123/io/ICommand.kt b/src/main/kotlin/me/duncte123/io/ICommand.kt new file mode 100644 index 0000000..ef69f8e --- /dev/null +++ b/src/main/kotlin/me/duncte123/io/ICommand.kt @@ -0,0 +1,31 @@ +package me.duncte123.io + +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent +import net.dv8tion.jda.api.interactions.commands.build.* + +interface ICommand { + val name: String + val description: String + + val options: List + get() = listOf() + val subCommands: List + get() = listOf() + + fun execute(event: SlashCommandInteractionEvent) + + fun toCommandData(): CommandData { + val data = Commands.slash(name, description) + .setGuildOnly(true) + + if (options.isNotEmpty()) { + data.addOptions(options) + } + + if (subCommands.isNotEmpty()) { + data.addSubcommands(subCommands) + } + + return data + } +} diff --git a/src/main/kotlin/me/duncte123/io/Main.kt b/src/main/kotlin/me/duncte123/io/Main.kt index 180d048..8f6b69c 100644 --- a/src/main/kotlin/me/duncte123/io/Main.kt +++ b/src/main/kotlin/me/duncte123/io/Main.kt @@ -1,7 +1,28 @@ package me.duncte123.io +import me.duncte123.io.commands.JjCommand import net.dv8tion.jda.api.JDABuilder +import net.dv8tion.jda.api.events.GenericEvent +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent +import net.dv8tion.jda.api.events.session.ReadyEvent +import net.dv8tion.jda.api.hooks.EventListener + +val commands = mapOf( + "jj" to JjCommand() +) fun main() { - JDABuilder.createLight(System.getenv("BOT_TOKEN")).build() + JDABuilder.createLight(System.getenv("BOT_TOKEN")) + .addEventListeners(object : EventListener { + override fun onEvent(event: GenericEvent) { + if (event is ReadyEvent) { + event.jda.updateCommands() + .addCommands(commands.values.map { it.toCommandData() }) + .queue() + } else if (event is SlashCommandInteractionEvent) { + commands[event.name]?.execute(event) + } + } + }) + .build() } diff --git a/src/main/kotlin/me/duncte123/io/commands/JjCommand.kt b/src/main/kotlin/me/duncte123/io/commands/JjCommand.kt new file mode 100644 index 0000000..90ba432 --- /dev/null +++ b/src/main/kotlin/me/duncte123/io/commands/JjCommand.kt @@ -0,0 +1,62 @@ +package me.duncte123.io.commands + +import me.duncte123.io.ICommand +import net.dv8tion.jda.api.entities.channel.ChannelType +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent +import net.dv8tion.jda.api.interactions.commands.OptionType +import net.dv8tion.jda.api.interactions.commands.build.OptionData +import net.dv8tion.jda.api.utils.FileUpload + +const val JJ_ID = 272258147169599489L + +class JjCommand : ICommand { + override val name = "jj" + override val description = "Allows JJ to upload pictures via the bot." + + override val options = listOf( + OptionData( + OptionType.CHANNEL, + "channel", + "Where to send the file?", + true + ), + OptionData( + OptionType.ATTACHMENT, + "file", + "the file to send to the channel", + true + ) + ) + + override fun execute(event: SlashCommandInteractionEvent) { + if (event.user.idLong != JJ_ID) { + event.reply("you are not jj").setEphemeral(true).queue() + return + } + + val channel = event.getOption("channel")!!.asChannel + + if (!channel.type.isMessage) { + event.reply("Must be a text channel fuckwhat").setEphemeral(true).queue() + return + } + + val msgChan = channel.asGuildMessageChannel() + + if (!msgChan.canTalk()) { + event.reply("Can't talk there :)").setEphemeral(true).queue() + return + } + + val file = event.getOption("file")!!.asAttachment + + event.reply("Sending the file to ${channel.asMention}").queue() + + file.proxy.download().thenAccept { stream -> + msgChan.sendFiles(FileUpload.fromData(stream, file.fileName)) + .queue() + } + + + } +}