Skip to content

Commit becd3bc

Browse files
committed
Upgrade to KUtils 0.11.0
1 parent aab948d commit becd3bc

8 files changed

Lines changed: 34 additions & 41 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<img src="https://img.shields.io/badge/Kotlin-1.3.50-blue.svg" alt="Kotlin 1.3.50">
44
</a>
55
<a href="https://gitlab.com/Aberrantfox/KUtils">
6-
<img src="https://img.shields.io/badge/KUtils-0.10.1-blue.svg" alt="KUtils 0.10.1">
6+
<img src="https://img.shields.io/badge/KUtils-0.11.0-blue.svg" alt="KUtils 0.11.0">
77
</a>
88
<a href="https://GitHub.com/JakeJMattson/EmbedBot/releases/">
99
<img src="https://img.shields.io/github/release/JakeJMattson/EmbedBot.svg" alt="Release">

commands.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@
8484
| ListEmbeds | <none> | List all embeds created in this guild. |
8585

8686
## Utility
87-
| Commands | Arguments | Description |
88-
| ------------ | --------- | ------------------------------------------- |
89-
| BotInfo | <none> | Display the bot information. |
90-
| ListCommands | <none> | List all available commands. |
91-
| Ping | <none> | Display the network ping of the bot. |
92-
| Uptime | <none> | Displays how long the bot has been running. |
93-
| help | (Word) | Display a help menu |
87+
| Commands | Arguments | Description |
88+
| -------- | --------- | ------------------------------------------- |
89+
| BotInfo | <none> | Display the bot information. |
90+
| Help | (Command) | Display a help menu. |
91+
| Ping | <none> | Display the network ping of the bot. |
92+
| Uptime | <none> | Displays how long the bot has been running. |
9493

pom.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
<!-- Version Numbers -->
2121
<jvm.target>1.8</jvm.target>
2222
<kotlin.version>1.3.50</kotlin.version>
23-
<kutils.version>0.10.1</kutils.version>
23+
<coroutines.version>1.3.1</coroutines.version>
24+
<kutils.version>0.11.0</kutils.version>
25+
<assembly.plugin.version>3.1.1</assembly.plugin.version>
2426
</properties>
2527

2628
<repositories>
@@ -44,7 +46,7 @@
4446
<dependency>
4547
<groupId>org.jetbrains.kotlinx</groupId>
4648
<artifactId>kotlinx-coroutines-core</artifactId>
47-
<version>1.3.0-RC2</version>
49+
<version>${coroutines.version}</version>
4850
</dependency>
4951

5052
<!-- KUtils -->
@@ -89,7 +91,7 @@
8991
<plugin>
9092
<groupId>org.apache.maven.plugins</groupId>
9193
<artifactId>maven-assembly-plugin</artifactId>
92-
<version>3.1.0</version>
94+
<version>${assembly.plugin.version}</version>
9395
<executions>
9496
<execution>
9597
<id>make-assembly</id>

src/main/kotlin/io/github/jakejmattson/embedbot/MainApp.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ import io.github.jakejmattson.embedbot.locale.messages
44
import me.aberrantfox.kjdautils.api.startBot
55

66
fun main(args: Array<String>) {
7-
val token = args.firstOrNull()
8-
?: throw IllegalArgumentException(messages.errors.NO_ARGS)
7+
val token = args.firstOrNull() ?: throw IllegalArgumentException(messages.errors.NO_ARGS)
98

109
startBot(token) {
1110
configure {
1211
globalPath = "io.github.jakejmattson.embedbot"
1312
reactToCommands = false
1413
documentationSortOrder = arrayListOf("BotConfiguration", "GuildConfiguration", "Core", "Copy", "Field",
1514
"Cluster", "Edit", "Information", "Utility")
16-
17-
//Move the help command from the internal "utility" category, to the local "Utility" category
18-
container.commands.getValue("help").category = "Utility"
1915
}
2016
}
2117
}

src/main/kotlin/io/github/jakejmattson/embedbot/commands/BotConfigurationCommands.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.jakejmattson.embedbot.commands
22

33
import io.github.jakejmattson.embedbot.dataclasses.Configuration
4-
import io.github.jakejmattson.embedbot.extensions.*
4+
import io.github.jakejmattson.embedbot.extensions.requiredPermissionLevel
55
import io.github.jakejmattson.embedbot.locale.messages
66
import io.github.jakejmattson.embedbot.services.*
77
import me.aberrantfox.kjdautils.api.dsl.*

src/main/kotlin/io/github/jakejmattson/embedbot/commands/GuildConfigurationCommands.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.jakejmattson.embedbot.commands
22

33
import io.github.jakejmattson.embedbot.dataclasses.*
4-
import io.github.jakejmattson.embedbot.extensions.*
4+
import io.github.jakejmattson.embedbot.extensions.requiredPermissionLevel
55
import io.github.jakejmattson.embedbot.locale.messages
66
import io.github.jakejmattson.embedbot.services.*
77
import me.aberrantfox.kjdautils.api.dsl.*

src/main/kotlin/io/github/jakejmattson/embedbot/commands/UtilityCommands.kt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import io.github.jakejmattson.embedbot.extensions.*
44
import io.github.jakejmattson.embedbot.locale.messages
55
import io.github.jakejmattson.embedbot.services.*
66
import me.aberrantfox.kjdautils.api.dsl.*
7-
import me.aberrantfox.kjdautils.extensions.jda.toMember
87
import java.util.Date
98

109
private val startTime = Date()
@@ -41,24 +40,4 @@ fun utilityCommands(infoService: InfoService, permissionsService: PermissionsSer
4140
}
4241
}
4342
}
44-
45-
command("ListCommands") {
46-
description = messages.descriptions.LIST_COMMANDS
47-
execute { event ->
48-
val member = event.author.toMember(event.guild!!)!!
49-
50-
val commands = event.container.commands.values.asSequence()
51-
.filter { permissionsService.hasClearance(member, it.requiredPermissionLevel) }
52-
.groupBy { it.category }.toList()
53-
.filter { it.second.isNotEmpty() }
54-
.sortedBy { (_, value) -> -value.size }
55-
.toList().toMap()
56-
57-
event.respondEmbed {
58-
commands.forEach { entry ->
59-
addInlineField(entry.key, entry.value.sortedBy { it.name }.joinToString("\n") { it.name })
60-
}
61-
}
62-
}
63-
}
6443
}

src/main/kotlin/io/github/jakejmattson/embedbot/services/PermissionsService.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.github.jakejmattson.embedbot.services
22

33
import io.github.jakejmattson.embedbot.dataclasses.Configuration
4+
import io.github.jakejmattson.embedbot.extensions.requiredPermissionLevel
45
import me.aberrantfox.kjdautils.api.annotation.Service
5-
import net.dv8tion.jda.api.entities.Member
6+
import me.aberrantfox.kjdautils.api.dsl.Command
7+
import me.aberrantfox.kjdautils.discord.Discord
8+
import me.aberrantfox.kjdautils.extensions.jda.toMember
9+
import net.dv8tion.jda.api.entities.*
610

711
enum class Permission {
812
BOT_OWNER,
@@ -14,7 +18,20 @@ enum class Permission {
1418
val DEFAULT_REQUIRED_PERMISSION = Permission.STAFF
1519

1620
@Service
17-
class PermissionsService(private val configuration: Configuration) {
21+
class PermissionsService(private val configuration: Configuration, discord: Discord) {
22+
init {
23+
discord.configuration.visibilityPredicate = { command: Command, user: User, _: MessageChannel, guild: Guild? ->
24+
if (guild != null) {
25+
val member = user.toMember(guild)!!
26+
val permission = command.requiredPermissionLevel
27+
28+
hasClearance(member, permission)
29+
}
30+
else {
31+
false
32+
}
33+
}
34+
}
1835

1936
fun hasClearance(member: Member, requiredPermissionLevel: Permission) = member.getPermissionLevel().ordinal <= requiredPermissionLevel.ordinal
2037

0 commit comments

Comments
 (0)