Skip to content

Commit

Permalink
Merge pull request #7 from ddivad195/feat/kord-upgrade
Browse files Browse the repository at this point in the history
feat: update to kord
  • Loading branch information
ddivad195 authored Nov 14, 2020
2 parents 4885fd1 + 06177c8 commit bd97f8e
Show file tree
Hide file tree
Showing 18 changed files with 260 additions and 290 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ RUN gradle shadowJar --no-daemon

FROM openjdk:11.0.8-jre-slim
RUN mkdir /config/
COPY --from=build /keeper/build/libs/*.jar /
COPY --from=build /keeper/build/libs/Keeper.jar /

ENTRYPOINT ["java", "-jar", "/Keeper.jar"]
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
repositories {
mavenCentral()
jcenter()
maven("https://oss.sonatype.org/content/repositories/snapshots/")
}

dependencies {
Expand All @@ -36,5 +37,5 @@ tasks {

object Versions {
const val BOT = "1.2.0"
const val DISCORDKT = "0.19.1"
const val DISCORDKT = "0.22.0-SNAPSHOT"
}
14 changes: 7 additions & 7 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
## Key
| Symbol | Meaning |
| ----------- | ------------------------------ |
| (Argument) | Argument is not required. |
| (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 | Unicode Emote | Set the reaction used to save messages |
| setRole | Role | Set the role required to use this bot. |
| 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 |
Expand Down
8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
version: '3.7'
services:
keeper:
container_name: Keeper
build:
dockerfile: Dockerfile
context: .
bot:
container_name: keeper
image: ddivad195/keeper:latest
volumes:
- type: bind
source: ./config/config.json
Expand Down
114 changes: 55 additions & 59 deletions src/main/kotlin/me/ddivad/keeper/Main.kt
Original file line number Diff line number Diff line change
@@ -1,84 +1,80 @@
package me.ddivad.keeper

import com.google.gson.Gson
import com.gitlab.kordlib.common.entity.Snowflake
import com.gitlab.kordlib.gateway.Intent
import com.gitlab.kordlib.gateway.PrivilegedIntent
import me.ddivad.keeper.dataclasses.Configuration
import me.ddivad.keeper.extensions.requiredPermissionLevel
import me.ddivad.keeper.services.PermissionsService
import me.ddivad.keeper.services.StatisticsService
import me.jakejmattson.discordkt.api.dsl.bot
import me.jakejmattson.discordkt.api.extensions.jda.fullName
import me.jakejmattson.discordkt.api.extensions.jda.profileLink
import me.jakejmattson.discordkt.api.extensions.jda.toMember
import me.jakejmattson.discordkt.api.extensions.addField
import me.jakejmattson.discordkt.api.extensions.addInlineField
import me.jakejmattson.discordkt.api.extensions.profileLink
import me.jakejmattson.discordkt.api.extensions.toSnowflake
import java.awt.Color
import java.util.*

data class Properties(val author: String, val version: String, val discordKt: String, val repository: String)

val startTime = Date()

fun main(args: Array<String>) {
@PrivilegedIntent
suspend fun main(args: Array<String>) {
val token = System.getenv("BOT_TOKEN") ?: null
val prefix = System.getenv("DEFAULT_PREFIX") ?: "<none>"
val defaultPrefix = System.getenv("DEFAULT_PREFIX") ?: "<none>"
require(token != null) { "Expected the bot token as an environment variable" }

bot(token) {
configure {
val (configuration, permissionsService, statsService: StatisticsService)
= it.getInjectionObjects(Configuration::class, PermissionsService::class, StatisticsService::class)
prefix {
val configuration = discord.getInjectionObjects(Configuration::class)

guild?.let { configuration[guild!!.id.longValue]?.prefix } ?: defaultPrefix
}
configure {
commandReaction = null
allowMentionPrefix = true
theme = Color(0x00BFFF)
}

prefix {
it.guild?.let { configuration[it.idLong]?.prefix } ?: prefix
mentionEmbed {
val (configuration, statsService) = it.discord.getInjectionObjects(Configuration::class, StatisticsService::class)
val guild = it.guild ?: return@mentionEmbed
val guildConfiguration = configuration[it.guild!!.id.longValue] ?: return@mentionEmbed
val self = it.channel.kord.getSelf()
val liveRole = guild.getRole(guildConfiguration.requiredRoleId.toSnowflake())
author {
val user = guild.kord.getUser(Snowflake(394484823944593409))
icon = user?.avatar?.url
name = user?.username
url = user?.profileLink
}

colors {
infoColor = Color(0x00BFFF)
title = "Keeper"
thumbnail {
url = self.avatar.url
}

mentionEmbed {
val guild = it.guild ?: return@mentionEmbed
val jda = it.discord.jda
val prefix = it.relevantPrefix
val role = configuration[guild.idLong]?.getLiveRole(jda)?.takeUnless { it == guild.publicRole }?.asMention
?: ""

author {
jda.retrieveUserById(394484823944593409).queue { user ->
iconUrl = user.effectiveAvatarUrl
name = user.fullName()
url = user.profileLink
}
}

simpleTitle = "Keeper"
thumbnail = jda.selfUser.effectiveAvatarUrl
color = infoColor
description = "A bot for saving useful messages to a DM by reacting to them."
addInlineField("Required role", role)
addInlineField("Prefix", prefix)
addField("Config Info", "```" +
"Enabled: ${configuration[it.guild!!.idLong]?.enabled}\n" +
"Reaction: ${configuration[it.guild!!.idLong]?.bookmarkReaction}\n" +
"```")
addField("Bot Info", "```" +
"Version: 1.2.0\n" +
"DiscordKt: 0.19.0\n" +
"Kotlin: ${KotlinVersion.CURRENT}\n" +
"Uptime: ${statsService.uptime}" +
"```")
addInlineField("Source", "http://github.com/ddivad195/keeper")
}
color = it.discord.configuration.theme
description = "A bot for saving useful messages to a DM by reacting to them."
addInlineField("Required role", liveRole.mention)
addInlineField("Prefix", it.prefix())
addField("Config Info", "```" +
"Enabled: ${guildConfiguration.enabled}\n" +
"Reaction: ${guildConfiguration.bookmarkReaction}\n" +
"```")
addField("Bot Info", "```" +
"Version: 1.3.0\n" +
"DiscordKt: 0.19.0\n" +
"Kotlin: ${KotlinVersion.CURRENT}\n" +
"```")
addField("Uptime", statsService.uptime)
addField("Source", "http://github.com/ddivad195/keeper")
}


visibilityPredicate {
val guild = it.guild ?: return@visibilityPredicate false
val member = it.user.toMember(guild)!!
val permission = it.command.requiredPermissionLevel
permissions {
val requiredPermissionLevel = command.requiredPermissionLevel
val guild = guild ?: return@permissions false
val member = user.asMember(guild.id)

permissionsService.hasClearance(guild, it.user, permission)
}
val permissionsService = discord.getInjectionObjects(PermissionsService::class)
return@permissions permissionsService.hasClearance(member, requiredPermissionLevel)
}

}
}
}
20 changes: 8 additions & 12 deletions src/main/kotlin/me/ddivad/keeper/commands/GeneralCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ package me.ddivad.keeper.commands
import me.ddivad.keeper.dataclasses.Configuration
import me.ddivad.keeper.extensions.requiredPermissionLevel
import me.ddivad.keeper.services.Permission
import me.jakejmattson.discordkt.api.annotations.CommandSet
import me.jakejmattson.discordkt.api.arguments.MessageArg
import me.jakejmattson.discordkt.api.dsl.command.commands
import me.jakejmattson.discordkt.api.services.ConversationService
import me.jakejmattson.discordkt.api.dsl.commands

@CommandSet("General")
fun generalCommands(configuration: Configuration) = commands {
command("delete") {
fun generalCommands(configuration: Configuration) = commands("General") {
dmCommand("delete") {
description = "Delete a Keeper bookmark by ID inside of DM channel"
requiresGuild = false
requiredPermissionLevel = Permission.EVERYONE
requiredPermissionLevel = Permission.USER
execute(MessageArg) {
val message = it.args.first
val message = args.first

if (message.author == it.discord.jda.selfUser && it.guild == null) {
message.delete().queue()
if (message.author == this.channel.kord.getSelf().asUser()) {
message.delete()
} else {
it.unsafeRespond("Can only delete messages sent by ${it.discord.jda.selfUser.asMention} in direct message channels.")
respond("Can only delete messages sent by ${this.channel.kord.getSelf().mention} in direct message channels.")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,66 @@ package me.ddivad.keeper.commands

import me.ddivad.keeper.conversations.ConfigurationConversation
import me.ddivad.keeper.dataclasses.Configuration
import me.jakejmattson.discordkt.api.annotations.CommandSet
import me.jakejmattson.discordkt.api.arguments.*
import me.jakejmattson.discordkt.api.dsl.command.commands
import me.jakejmattson.discordkt.api.services.ConversationService
import me.jakejmattson.discordkt.api.dsl.commands

@CommandSet("Configuration")
fun guildConfigurationCommands(configuration: Configuration, conversationService: ConversationService) = commands {
command("configure") {
fun guildConfigurationCommands(configuration: Configuration) = commands("Configuration") {
guildCommand("configure") {
description = "Configure a guild to use Keeper."
execute {
if (configuration.hasGuildConfig(it.guild!!.idLong))
return@execute it.respond("Guild configuration exists. To modify it use the commands to set values.")

conversationService.startPublicConversation<ConfigurationConversation>(it.author, it.channel, it.guild!!)
it.respond("Guild setup")
if (configuration.hasGuildConfig(guild.id.longValue)) {
respond("Guild configuration exists. To modify it use the commands to set values.")
return@execute
}
ConfigurationConversation(configuration)
.createConfigurationConversation(guild)
.startPublicly(discord, author, channel)
respond("Guild setup")
}
}
command("setPrefix") {

guildCommand("setPrefix") {
description = "Set the prefix required for the bot to register a command."
execute(AnyArg("Prefix")) {
if (!configuration.hasGuildConfig(it.guild!!.idLong))
return@execute it.respond("Please run the **configure** command to set this initially.")

val prefix = it.args.first
if (!configuration.hasGuildConfig(guild.id.longValue)) {
respond("Guild configuration exists. To modify it use the commands to set values.")
return@execute
}

configuration[it.guild!!.idLong]?.prefix = prefix
val prefix = args.first
configuration[guild.id.longValue]?.prefix = prefix
configuration.save()

it.respond("Prefix set to: $prefix")
respond("Prefix set to: $prefix")
}
}

command("setRole") {
guildCommand("setRole") {
description = "Set the role required to use this bot."
execute(RoleArg) {
if (!configuration.hasGuildConfig(it.guild!!.idLong))
return@execute it.respond("Please run the **configure** command to set this initially.")

val requiredRole = it.args.first
if (!configuration.hasGuildConfig(guild.id.longValue)) {
respond("Guild configuration exists. To modify it use the commands to set values.")
return@execute
}

configuration[it.guild!!.idLong]?.requiredRoleId = requiredRole.idLong
val requiredRole = args.first
configuration[guild.id.longValue]?.requiredRoleId = requiredRole.id.longValue
configuration.save()

it.respond("Required role set to: ${requiredRole.name}")
respond("Required role set to: ${requiredRole.name}")
}


command("setReaction") {
guildCommand("setReaction") {
description = "Set the reaction used to save messages"
execute(UnicodeEmoteArg) {
if (!configuration.hasGuildConfig(it.guild!!.idLong))
return@execute it.respond("Please run the **configure** command to set this initially.")
execute(UnicodeEmojiArg) {
if (!configuration.hasGuildConfig(guild.id.longValue)) {
respond("Guild configuration exists. To modify it use the commands to set values.")
return@execute
}

val reaction = it.args.first

configuration[it.guild!!.idLong]?.bookmarkReaction = reaction
val reaction = args.first
configuration[guild.id.longValue]?.bookmarkReaction = reaction.unicode
configuration.save()

it.respond("Reaction set to: $reaction")
respond("Reaction set to: $reaction")
}
}
}
Expand Down
Loading

0 comments on commit bd97f8e

Please sign in to comment.