-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PurgeMessages to /system-command fix: Modal TextInput defaults are now working if null
- Loading branch information
Showing
10 changed files
with
161 additions
and
90 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
58 changes: 0 additions & 58 deletions
58
...n/io/viascom/discord/bot/starter/bot/command/systemcommand/CheckPermissionDataProvider.kt
This file was deleted.
Oops, something went wrong.
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
98 changes: 98 additions & 0 deletions
98
.../kotlin/io/viascom/discord/bot/starter/bot/command/systemcommand/PurgeMessagesProvider.kt
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,98 @@ | ||
package io.viascom.discord.bot.starter.bot.command.systemcommand | ||
|
||
import io.viascom.discord.bot.starter.bot.command.SystemCommand | ||
import io.viascom.discord.bot.starter.bot.emotes.AlunaEmote | ||
import io.viascom.discord.bot.starter.bot.handler.Command | ||
import io.viascom.discord.bot.starter.bot.handler.queueAndRegisterInteraction | ||
import io.viascom.discord.bot.starter.util.createTextInput | ||
import io.viascom.discord.bot.starter.util.getOptionAsString | ||
import io.viascom.discord.bot.starter.util.getValueAsString | ||
import net.dv8tion.jda.api.entities.GuildMessageChannel | ||
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent | ||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent | ||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent | ||
import net.dv8tion.jda.api.interactions.InteractionHook | ||
import net.dv8tion.jda.api.interactions.components.ActionRow | ||
import net.dv8tion.jda.api.interactions.components.Modal | ||
import net.dv8tion.jda.api.interactions.components.text.TextInput | ||
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle | ||
import net.dv8tion.jda.api.sharding.ShardManager | ||
import java.util.stream.Collectors | ||
|
||
@Command | ||
class PurgeMessagesProvider( | ||
private val shardManager: ShardManager | ||
) : SystemCommandDataProvider( | ||
"purge_messages", | ||
"Purge Messages", | ||
true, | ||
false, | ||
true, | ||
true | ||
) { | ||
|
||
lateinit var selectedChannel: GuildMessageChannel | ||
|
||
override fun execute(event: SlashCommandInteractionEvent, hook: InteractionHook?, command: SystemCommand) { | ||
|
||
val id = event.getOptionAsString("args", "")!! | ||
if (id.isEmpty()) { | ||
event.deferReply().setContent("${AlunaEmote.BOT_CROSS.asMention()} Please specify an ID as argument for this command").queue() | ||
return | ||
} | ||
|
||
val channel = shardManager.getChannelById(GuildMessageChannel::class.java, id) | ||
if (channel == null) { | ||
event.deferReply().setContent("${AlunaEmote.BOT_CROSS.asMention()} Please specify a valid channel ID as argument for this command").queue() | ||
return | ||
} | ||
|
||
selectedChannel = channel | ||
|
||
//Show modal | ||
val amount: TextInput = createTextInput("amount", "Amount of messages", TextInputStyle.SHORT) | ||
|
||
val modal: Modal = Modal.create("purge", "Purge") | ||
.addActionRows(ActionRow.of(amount)) | ||
.build() | ||
|
||
event.replyModal(modal).queueAndRegisterInteraction(command) | ||
} | ||
|
||
override fun onModalInteraction(event: ModalInteractionEvent, additionalData: HashMap<String, Any?>): Boolean { | ||
event.deferReply(true).queue { | ||
it.editOriginal( | ||
"${AlunaEmote.BOT_CHECK.asMention()} Removing ${ | ||
event.getValueAsString( | ||
"amount", | ||
"0" | ||
) | ||
} messages from ${selectedChannel.asMention}..." | ||
).queue() | ||
|
||
val number = event.getValueAsString("amount", "0")!!.toLong() | ||
selectedChannel.iterableHistory.queue { | ||
val messages = it.stream().limit(number).collect(Collectors.toList()) | ||
selectedChannel.purgeMessages(messages) | ||
} | ||
} | ||
return true | ||
} | ||
|
||
override fun onArgsAutoComplete(event: CommandAutoCompleteInteractionEvent) { | ||
val input = event.getOptionAsString("args", "")!! | ||
|
||
if (input == "") { | ||
event.replyChoices().queue() | ||
return | ||
} | ||
|
||
val possibleChannel = shardManager.getChannelById(GuildMessageChannel::class.java, input) | ||
|
||
if (possibleChannel != null) { | ||
event.replyChoices(net.dv8tion.jda.api.interactions.commands.Command.Choice(possibleChannel.name, possibleChannel.id)).queue() | ||
} else { | ||
event.replyChoices().queue() | ||
} | ||
} | ||
} |
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
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