|
1 | 1 | package me.ddivad.judgebot.conversations |
2 | 2 |
|
| 3 | +import dev.kord.common.entity.ButtonStyle |
3 | 4 | import dev.kord.core.entity.Guild |
4 | 5 | import dev.kord.core.entity.Member |
5 | | -import dev.kord.rest.builder.message.EmbedBuilder |
6 | 6 | import me.ddivad.judgebot.dataclasses.* |
7 | 7 | import me.ddivad.judgebot.embeds.createHistoryEmbed |
8 | 8 | import me.ddivad.judgebot.embeds.createInfractionRuleEmbed |
9 | 9 | import me.ddivad.judgebot.services.DatabaseService |
10 | 10 | import me.ddivad.judgebot.services.infractions.InfractionService |
11 | | -import me.jakejmattson.discordkt.api.arguments.IntegerArg |
12 | 11 | import me.jakejmattson.discordkt.api.dsl.conversation |
13 | 12 |
|
14 | | -class InfractionConversation(private val databaseService: DatabaseService, |
15 | | - private val configuration: Configuration, |
16 | | - private val infractionService: InfractionService) { |
17 | | - fun createInfractionConversation(guild: Guild, targetUser: Member, weight: Int, infractionReason: String, type: InfractionType) = conversation("cancel") { |
| 13 | +class InfractionConversation( |
| 14 | + private val databaseService: DatabaseService, |
| 15 | + private val configuration: Configuration, |
| 16 | + private val infractionService: InfractionService |
| 17 | +) { |
| 18 | + fun createInfractionConversation( |
| 19 | + guild: Guild, |
| 20 | + targetUser: Member, |
| 21 | + weight: Int, |
| 22 | + infractionReason: String, |
| 23 | + type: InfractionType |
| 24 | + ) = conversation("cancel") { |
18 | 25 | val guildConfiguration = configuration[guild.id.value] ?: return@conversation |
19 | 26 | val user = databaseService.users.getOrCreateUser(targetUser, guild) |
20 | 27 | val points = weight * |
21 | 28 | if (type == InfractionType.Strike) guildConfiguration.infractionConfiguration.strikePoints |
22 | 29 | else guildConfiguration.infractionConfiguration.warnPoints |
23 | 30 | val rules = databaseService.guilds.getRules(guild) |
24 | 31 | val ruleId = if (rules.isNotEmpty()) { |
25 | | - respond { createInfractionRuleEmbed(guild, rules) } |
26 | | - val rule = promptUntil( |
27 | | - IntegerArg, |
28 | | - prompt = "Enter choice:", |
29 | | - isValid = { number -> rules.any { it.number == number } || number == 0 }, |
30 | | - error = "Rule not found. Please enter a valid rule ID or 0:" |
31 | | - ) |
| 32 | + |
| 33 | + val rule = promptButton<Int> { |
| 34 | + embed { |
| 35 | + createInfractionRuleEmbed(guild, rules) |
| 36 | + } |
| 37 | + rules.chunked(5).forEach { list -> |
| 38 | + buttons { |
| 39 | + list.forEach { rule -> |
| 40 | + button("${rule.number}", null, rule.number, ButtonStyle.Primary) |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + buttons { |
| 45 | + button("Infract without rule", null, 0, ButtonStyle.Danger) |
| 46 | + } |
| 47 | + } |
| 48 | + |
32 | 49 | if (rule > 0) rule else null |
33 | 50 | } else null |
34 | 51 | val infraction = Infraction(this.user.id.asString, infractionReason, type, points, ruleId) |
|
0 commit comments