Skip to content

Commit

Permalink
Merge pull request #17 from ddivad195/feat/slash-updates
Browse files Browse the repository at this point in the history
feat: update dkt snapshot version
  • Loading branch information
ddivad195 authored Aug 11, 2022
2 parents be43fc0 + 5a9dcc7 commit 9aff2db
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 198 deletions.
23 changes: 14 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.util.*

group = "me.ddivad"
version = Versions.BOT
version = "1.9.0"
description = "A bot for saving useful messages to a DM by reacting to them."

plugins {
Expand All @@ -14,27 +16,30 @@ repositories {
}

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

tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"

Properties().apply {
setProperty("name", "Keeper")
setProperty("description", project.description)
setProperty("version", version.toString())
setProperty("url", "https://github.com/ddivad195/keeper")

store(file("src/main/resources/bot.properties").outputStream(), null)
}
}

shadowJar {
archiveFileName.set("Keeper.jar")
manifest {
attributes(
"Main-Class" to "me.ddivad.keeper.MainKt"
"Main-Class" to "me.ddivad.keeper.MainKt"
)
}
}
}


object Versions {
const val BOT = "1.2.0"
const val DISCORDKT = "0.23.0-SNAPSHOT"
}
22 changes: 8 additions & 14 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@
| [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. |
| Commands | Arguments | Description |
|-------------|-----------|----------------------------------------|
| configure | Reaction | Configure a guild to use Keeper. |
| disable | | Disable the bot reactions |
| enable | | Enable the bot reactions |
| setReaction | Reaction | Set the reaction used to save messages |

## 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 |
| bookmark | Message | Bookmark this message |
| info | | View statistics about Keeper |

## Utility
| Commands | Arguments | Description |
Expand Down
45 changes: 2 additions & 43 deletions src/main/kotlin/me/ddivad/keeper/Main.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
package me.ddivad.keeper

import dev.kord.common.annotation.KordPreview
import dev.kord.common.entity.Snowflake
import dev.kord.core.supplier.EntitySupplyStrategy
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.services.CacheService
import me.ddivad.keeper.services.StatisticsService
import me.jakejmattson.discordkt.dsl.bot
import me.jakejmattson.discordkt.extensions.*
import java.awt.Color

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

bot(token) {
val configuration = data("config/config.json") { Configuration() }
data("config/config.json") { Configuration() }

prefix {
guild?.let { configuration[guild!!.id]?.prefix } ?: defaultPrefix
}
prefix { "/" }

configure {
commandReaction = null
Expand All @@ -38,41 +32,6 @@ suspend fun main() {
)
}

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

title = "Keeper"
thumbnail {
url = self.pfpUrl
}
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.8.0\n" +
"DiscordKt: ${it.discord.versions.library}\n" +
"Kord: ${it.discord.versions.kord}\n" +
"Kotlin: ${KotlinVersion.CURRENT}\n" +
"```")
addField("Uptime", statsService.uptime)
addField("Source", "http://github.com/ddivad195/keeper")
}

onStart {
val cacheService = this.getInjectionObjects(CacheService::class)
try {
Expand Down
39 changes: 21 additions & 18 deletions src/main/kotlin/me/ddivad/keeper/commands/GeneralCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import dev.kord.rest.request.KtorRequestException
import dev.kord.x.emoji.Emojis
import dev.kord.x.emoji.addReaction
import me.ddivad.keeper.dataclasses.Configuration
import me.ddivad.keeper.dataclasses.Permissions
import me.ddivad.keeper.embeds.buildSavedMessageEmbed
import me.ddivad.keeper.embeds.buildStatsEmbed
import me.ddivad.keeper.services.StatisticsService
import me.jakejmattson.discordkt.arguments.MessageArg
import me.jakejmattson.discordkt.commands.commands
import me.jakejmattson.discordkt.extensions.sendPrivateMessage
import mu.KotlinLogging
Expand All @@ -16,23 +15,27 @@ private val logger = KotlinLogging.logger { }

@Suppress("unused")
fun generalCommands(configuration: Configuration, statsService: StatisticsService) = commands("General") {
slash("bookmark", "Bookmark") {
description = "Bookmark a message using Keeper"
requiredPermissions = Permissions.EVERYONE
execute(MessageArg) {
val guild = guild.asGuildOrNull()
statsService.bookmarkAdded(guild)
try {
this.author.sendPrivateMessage {
buildSavedMessageEmbed(args.first.asMessage(), guild)
}.addReaction(Emojis.x)
respond("Message Bookmarked ${Emojis.bookmark}")
logger.info { "Message Bookmarked by ${this.author.username}" }
} catch (e: KtorRequestException) {
respond("Looks like you have DMs disabled. To bookmark messages, this needs to be enabled.")
logger.error { "Bookmark DM could not be sent" }
}
message("Bookmark Message", "bookmark", "Bookmark this message") {
val guild = guild.asGuildOrNull()
statsService.bookmarkAdded(guild)
try {
this.author.sendPrivateMessage {
buildSavedMessageEmbed(args.first.asMessage(), guild)
}.addReaction(Emojis.x)
respond("Message Bookmarked ${Emojis.bookmark}")
logger.info { "Message Bookmarked by ${this.author.username}" }
} catch (e: KtorRequestException) {
respond("Looks like you have DMs disabled. To bookmark messages, this needs to be enabled.")
logger.error { "Bookmark DM could not be sent" }
}
}

slash("info") {
description = "View statistics about Keeper"
execute {
respondPublic {
buildStatsEmbed(guild, configuration, statsService)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,69 +1,63 @@
package me.ddivad.keeper.commands

import me.ddivad.keeper.conversations.ConfigurationConversation
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) {
command("configure") {
slash("configure") {
description = "Configure a guild to use Keeper."
execute {
execute(UnicodeEmojiArg("Reaction", "The reaction that will be used to bookmark messages")) {
if (configuration.hasGuildConfig(guild.id)) {
respond("Guild configuration exists. To modify it use the commands to set values.")
respond("Guild configuration already exists. To modify it use the commands to set values.")
return@execute
}
ConfigurationConversation(configuration)
.createConfigurationConversation(guild)
.startPublicly(discord, author, channel)
configuration.setup(guild, args.first.unicode)
respond("Guild Setup")

}
}

slash("setPrefix") {
description = "Set the prefix required for the bot to register a command."
execute(AnyArg("Prefix")) {
slash("setReaction") {
description = "Set the reaction used to save messages"
execute(UnicodeEmojiArg("Reaction", "The reaction that will be used to bookmark messages")) {
if (!configuration.hasGuildConfig(guild.id)) {
respond("Guild configuration exists. To modify it use the commands to set values.")
respond("Guild configuration does not exist. Run `/configure` first.")
return@execute
}

val prefix = args.first
configuration[guild.id]?.prefix = prefix
val reaction = args.first
configuration[guild.id]?.bookmarkReaction = reaction.unicode
configuration.save()
respondPublic("Prefix set to: $prefix")
respondPublic("Reaction set to: $reaction")
}
}

slash("setRole") {
description = "Set the role required to use this bot."
execute(RoleArg) {
slash("enable") {
description = "Enable the bot reactions"
execute {
if (!configuration.hasGuildConfig(guild.id)) {
respondPublic("Guild configuration exists. To modify it use the commands to set values.")
respond("Guild configuration does not exist. Run `/configure` first.")
return@execute
}

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

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.")
return@execute
}

val reaction = args.first
configuration[guild.id]?.bookmarkReaction = reaction.unicode
configuration.save()
respondPublic("Reaction set to: $reaction")
slash("disable") {
description = "Disable the bot reactions"
execute {
if (!configuration.hasGuildConfig(guild.id)) {
respond("Guild configuration does not exist. Run `/configure` first.")
return@execute
}
configuration[guild.id]?.enabled = false
configuration.save()
respondPublic("Reactions disabled")
}
}
}
}
45 changes: 0 additions & 45 deletions src/main/kotlin/me/ddivad/keeper/commands/OperationCommands.kt

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9aff2db

Please sign in to comment.