-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<OptionData> | ||
get() = listOf() | ||
val subCommands: List<SubcommandData> | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
|
||
|
||
} | ||
} |