Skip to content

Commit

Permalink
Merge pull request #16 from ddivad195/feat/permissions-update
Browse files Browse the repository at this point in the history
feat: update permissions using latest dkt snapshot
  • Loading branch information
ddivad195 authored Jul 20, 2022
2 parents 32bab43 + a83a4aa commit be43fc0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 39 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ version = Versions.BOT
description = "A bot for saving useful messages to a DM by reacting to them."

plugins {
kotlin("jvm") version "1.5.31"
kotlin("plugin.serialization") version "1.5.31"
kotlin("jvm") version "1.7.10"
kotlin("plugin.serialization") version "1.7.10"
id("com.github.johnrengelman.shadow") version "7.0.0"
}

Expand All @@ -14,7 +14,7 @@ repositories {
}

dependencies {
implementation("me.jakejmattson:DiscordKt:${Versions.DISCORDKT}")
implementation("me.jakejmattson:DiscordKt:0.23.0-SNAPSHOT")
implementation("io.github.microutils:kotlin-logging-jvm:2.1.20")
}

Expand Down
10 changes: 5 additions & 5 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

## Key
| Symbol | Meaning |
| ----------- | ------------------------------ |
|-------------|--------------------------------|
| [Argument] | Argument is not required. |

## Configuration
| Commands | Arguments | Description |
| ----------- | --------- | ---------------------------------------------------------- |
|-------------|-----------|------------------------------------------------------------|
| configure | | Configure a guild to use Keeper. |
| setPrefix | Prefix | Set the prefix required for the bot to register a command. |
| setReaction | Emoji | Set the reaction used to save messages |
| setRole | Role | Set the role required to use this bot. |

## General
| Commands | Arguments | Description |
| -------- | --------- | ------------------------------- |
|----------|-----------|---------------------------------|
| bookmark | Message | Bookmark a message using Keeper |

## Operation
| Commands | Arguments | Description |
| -------- | --------- | ---------------------------- |
|----------|-----------|------------------------------|
| disable | | Disabled the bot reactions |
| enable | | Enable the bot reactions |
| stats | | View statistics about Keeper |

## Utility
| Commands | Arguments | Description |
| -------- | --------- | -------------------- |
|----------|-----------|----------------------|
| Help | [Command] | Display a help menu. |

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 2 additions & 4 deletions src/main/kotlin/me/ddivad/keeper/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dev.kord.gateway.Intent
import dev.kord.gateway.Intents
import dev.kord.gateway.PrivilegedIntent
import me.ddivad.keeper.dataclasses.Configuration
import me.ddivad.keeper.dataclasses.Permissions
import me.ddivad.keeper.services.CacheService
import me.ddivad.keeper.services.StatisticsService
import me.jakejmattson.discordkt.dsl.bot
Expand All @@ -30,14 +29,13 @@ suspend fun main() {

configure {
commandReaction = null
allowMentionPrefix = true
mentionAsPrefix = true
theme = Color(0x00BFFF)
entitySupplyStrategy = EntitySupplyStrategy.cacheWithCachingRestFallback
intents = Intents(
Intent.GuildMessageReactions,
Intent.DirectMessagesReactions
)
permissions = Permissions
}

mentionEmbed {
Expand Down Expand Up @@ -66,7 +64,7 @@ suspend fun main() {
"Reaction: ${guildConfiguration.bookmarkReaction}\n" +
"```")
addField("Bot Info", "```" +
"Version: 1.7.0\n" +
"Version: 1.8.0\n" +
"DiscordKt: ${it.discord.versions.library}\n" +
"Kord: ${it.discord.versions.kord}\n" +
"Kotlin: ${KotlinVersion.CURRENT}\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private val logger = KotlinLogging.logger { }
fun generalCommands(configuration: Configuration, statsService: StatisticsService) = commands("General") {
slash("bookmark", "Bookmark") {
description = "Bookmark a message using Keeper"
requiredPermission = Permissions.NONE
requiredPermissions = Permissions.EVERYONE
execute(MessageArg) {
val guild = guild.asGuildOrNull()
statsService.bookmarkAdded(guild)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import me.ddivad.keeper.dataclasses.Configuration
import me.ddivad.keeper.dataclasses.Permissions
import me.jakejmattson.discordkt.arguments.*
import me.jakejmattson.discordkt.commands.commands
import java.lang.Compiler.command

@Suppress("unused")
fun guildConfigurationCommands(configuration: Configuration) = commands("Configuration", Permissions.STAFF) {
Expand All @@ -25,44 +26,43 @@ fun guildConfigurationCommands(configuration: Configuration) = commands("Configu
description = "Set the prefix required for the bot to register a command."
execute(AnyArg("Prefix")) {
if (!configuration.hasGuildConfig(guild.id)) {
respond("Guild configuration exists. To modify it use the commands to set values.", false)
respond("Guild configuration exists. To modify it use the commands to set values.")
return@execute
}

val prefix = args.first
configuration[guild.id]?.prefix = prefix
configuration.save()
respond("Prefix set to: $prefix", false)
respondPublic("Prefix set to: $prefix")
}
}

slash("setRole") {
description = "Set the role required to use this bot."
execute(RoleArg) {
if (!configuration.hasGuildConfig(guild.id)) {
respond("Guild configuration exists. To modify it use the commands to set values.", false)
respondPublic("Guild configuration exists. To modify it use the commands to set values.")
return@execute
}

val requiredRole = args.first
configuration[guild.id]?.requiredRoleId = requiredRole.id
configuration.save()
respond("Required role set to: ${requiredRole.name}", false)
respondPublic("Required role set to: ${requiredRole.name}")
}


slash("setReaction") {
description = "Set the reaction used to save messages"
execute(UnicodeEmojiArg) {
if (!configuration.hasGuildConfig(guild.id)) {
respond("Guild configuration exists. To modify it use the commands to set values.", false)
respond("Guild configuration exists. To modify it use the commands to set values.")
return@execute
}

val reaction = args.first
configuration[guild.id]?.bookmarkReaction = reaction.unicode
configuration.save()
respond("Reaction set to: $reaction", false)
respondPublic("Reaction set to: $reaction")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fun operationCommands(configuration: Configuration, statsService: StatisticsServ
}
configuration[guild.id]?.enabled = true
configuration.save()
respond("Bot enabled", false)
respondPublic("Bot enabled")
}
}

Expand All @@ -30,14 +30,14 @@ fun operationCommands(configuration: Configuration, statsService: StatisticsServ
}
configuration[guild.id]?.enabled = false
configuration.save()
respond("Bot disabled", false)
respondPublic("Bot disabled")
}
}

slash("stats") {
description = "View statistics about Keeper"
execute {
respond(false) {
respondPublic {
buildStatsEmbed(guild, configuration, statsService)
}
}
Expand Down
21 changes: 6 additions & 15 deletions src/main/kotlin/me/ddivad/keeper/dataclasses/Permissions.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package me.ddivad.keeper.dataclasses

import me.jakejmattson.discordkt.dsl.Permission
import me.jakejmattson.discordkt.dsl.PermissionSet
import me.jakejmattson.discordkt.dsl.permission
import dev.kord.common.entity.Permission
import dev.kord.common.entity.Permissions

@Suppress("unused")
object Permissions : PermissionSet {
val BOT_OWNER = permission("Bot Owner") { users(discord.getInjectionObjects<Configuration>().botOwner) }
val GUILD_OWNER = permission("Guild Owner") { guild?.ownerId?.let { users(it) } }
val STAFF = permission("Staff") {
discord.getInjectionObjects<Configuration>()[guild!!.id]?.requiredRoleId?.let {
roles(it)
}
}
val NONE = permission("None") { guild?.everyoneRole?.let { roles(it.id) } }

override val hierarchy: List<Permission> = listOf(NONE, STAFF, GUILD_OWNER, BOT_OWNER)
override val commandDefault: Permission = STAFF
object Permissions {
val GUILD_OWNER = Permissions(Permission.ManageGuild)
val STAFF = Permissions(Permission.ManageMessages)
val EVERYONE = Permissions(Permission.SendMessages)
}

0 comments on commit be43fc0

Please sign in to comment.