Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.9.0 #352

Merged
merged 18 commits into from
Sep 12, 2023
Merged

4.9.0 #352

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
enable-beta-ecosystems: true

updates:
- package-ecosystem: "gradle"
target-branch: "develop"
directory: "/"

schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
target-branch: "develop"
directory: "/"

schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Lily makes use of the following tools and frameworks.
* [Kord](https://github.com/kordlib/kord), the Kotlin API for Discord.
* [KordEx](https://github.com/Kord-Extensions/kord-extensions), an integrated commands and extensions framework for Kord.
* KordEx's [Phishing](https://github.com/Kord-Extensions/kord-extensions/tree/develop/extra-modules/extra-phishing), [PluralKit](https://github.com/Kord-Extensions/kord-extensions/tree/develop/extra-modules/extra-pluralkit) and [Unsafe](https://github.com/Kord-Extensions/kord-extensions/tree/develop/modules/unsafe) modules.
* [MongoDB](https://www.mongodb.com/) and [KMongo](https://litote.org/kmongo/)
* [MongoDB](https://www.mongodb.com/)'s [Kotlin Driver](https://www.mongodb.com/docs/drivers/kotlin/)
to manage the database.
* [Logback](https://github.com/qos-ch/logback), a library that makes logging prettier
* [Kotlin Logging](https://github.com/MicroUtils/kotlin-logging), a lightweight logging that wraps SLF4J with kotlin extensions
Expand Down
20 changes: 13 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
application

Expand All @@ -16,7 +15,7 @@ plugins {
}

group = "org.hyacinthbots.lilybot"
version = "4.8.5"
version = "4.9.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -54,6 +53,7 @@ dependencies {
implementation(libs.kord.extensions.phishing)
implementation(libs.kord.extensions.pluralkit)
implementation(libs.kord.extensions.unsafe)
implementation(libs.kord.extensions.mongodb)

implementation(libs.kotlin.stdlib)

Expand All @@ -65,7 +65,7 @@ dependencies {
implementation(libs.github.api)

// KMongo
implementation(libs.kmongo)
implementation(libs.mongo.driver)

// Cozy's welcome module
implementation(libs.cozy.welcome)
Expand Down Expand Up @@ -108,12 +108,18 @@ tasks {

detekt {
buildUponDefaultConfig = true
config = files("$rootDir/detekt.yml")
config.setFrom("$rootDir/detekt.yml")

autoCorrect = true
}

blossom {
replaceToken("@build_id@", grgit.head().abbreviatedId)
replaceToken("@version@", project.version.toString())
sourceSets {
main {
blossom {
kotlinSources {
property("build_id", grgit.head().abbreviatedId)
property("version", project.version.toString())
}
}
}
}
2 changes: 0 additions & 2 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ style:
active: true
OptionalUnit:
active: false
OptionalWhenBraces:
active: true
PreferToOverPairSyntax:
active: true
RedundantExplicitType:
Expand Down
19 changes: 19 additions & 0 deletions docs/changelogs/4.x.x/4.9.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# LilyBot 4.9.0

This release removes th deprecated log uploading, expands the capabilities of the clear command and fixes many bugs
You can find the full changelog below

New:
* Allow custom messages to be sent with bans, intended for adding Appeals Servers. This is part of the moderation config

Change:
* The clear command can now clear different ranges of messages based on certain parameters. #348
* Lily now uses the official Kotlin MongoDB driver, rather than KMongo. #351
* Upgradle to 8.3 and update other dependencies

Fix:
* Remove usage of deprecated username tags, making use of the new username system
* Fix bulk delete now working properly
* The permission checks on Auto-threading roles

You can find a list of all the commits in this update [here](https://github.com/hyacinthbots/LilyBot/compare/v4.8.5...v4.9.0)
42 changes: 37 additions & 5 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Required Member Permissions: Manage Server
* `quick-timeout-length` - The length of timeouts to use for quick timeouts - Coalescing Optional Duration
* `warn-auto-punishments` - Whether to automatically punish users for reach a certain threshold on warns - Optional Boolean
* `log-publicly` - Whether to log moderation publicly or not. - Optional Boolean
* `ban-dm-message` - A custom message to send to users when they are banned. - Optional String

---
#### Command name: `config logging`
Expand Down Expand Up @@ -291,12 +292,43 @@ Description: Kicks a user.
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
### Command name: `clear`
Description: Clears messages from a channel.
**Required Member Permissions**: Manage Messages
#### Command name: `clear count`
**Description**: Clear a specific count of messages
Required Member Permissions: Manage Messages

* Arguments:
* **Arguments**:
* `messages` - Number of messages to delete - Int
* `author` - The author of the messages to clear - Optional User

---
#### Command name: `clear before`
**Description**: Clear messages before a given message ID
Required Member Permissions: Manage Messages

* **Arguments**:
* `before` - The ID of the message to clear before - Snowflake
* `message-count` - The number of messages to clear - Optional Int/Long
* `author` - The author of the messages to clear - Optional User

---
#### Command name: `clear after`
**Description**: Clear messages before a given message ID
Required Member Permissions: Manage Messages

* **Arguments**:
* `after` - The ID of the message to clear after - Snowflake
* `message-count` - The number of messages to clear - Optional Int/Long
* `author` - The author of the messages to clear - Optional User

---
#### Command name: `clear between`
**Description**: Clear messages between 2 message IDs
Required Member Permissions: Manage Messages

* **Arguments**:
* `after` - The ID of the message to clear after - Snowflake
* `before` - The ID of the message to clear before - Snowflake
* `author` - The author of the messages to clear - Optional User

---
### Command name: `timeout`
Expand Down Expand Up @@ -645,7 +677,7 @@ Description: Check whether a given domain is a known phishing domain.
**Description**: Set a custom API URL, "reset" to reset

* **Arguments**:
* `api-url` - Set an alternative API url, or "reset" to use the default - Optional String
* `api-url` - Set an alternative API URL, or "reset" to use the default - Optional String

---
#### Command name: `pluralkit bot`
Expand Down
22 changes: 12 additions & 10 deletions libs.versions.toml → gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[versions]
# Plugins
kotlin = "1.8.21"
kotlin = "1.9.10"
shadow = "8.1.1"
detekt = "1.23.0"
detekt = "1.23.1"
git-hooks = "0.0.2"
grgit = "5.2.0"
blossom = "1.3.1"
blossom = "2.0.1"

# Libraries
kord-extensions = "1.5.8-20230618.092018-1"
logging = "3.0.5"
logback = "1.4.7"
github-api = "1.314"
kmongo = "4.9.0"
#kord-extensions = "1.5.9-20230820.204324-8"
kord-extensions = "1.5.9-SNAPSHOT"
logging = "5.1.0"
logback = "1.4.11"
github-api = "1.316"
mongo-driver = "4.10.2"
cozy-welcome = "1.0.1-SNAPSHOT"
dma = "v0.2.1"
docgenerator = "0.1.2-SNAPSHOT"
Expand All @@ -22,11 +23,12 @@ kord-extensions-core = { module = "com.kotlindiscord.kord.extensions:kord-extens
kord-extensions-phishing = { module = "com.kotlindiscord.kord.extensions:extra-phishing", version.ref = "kord-extensions" }
kord-extensions-pluralkit = { module = "com.kotlindiscord.kord.extensions:extra-pluralkit", version.ref = "kord-extensions"}
kord-extensions-unsafe = { module = "com.kotlindiscord.kord.extensions:unsafe", version.ref = "kord-extensions"}
kord-extensions-mongodb = { module = "com.kotlindiscord.kord.extensions:adapter-mongodb", version.ref = "kord-extensions" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" }
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
logging = { module = "io.github.microutils:kotlin-logging", version.ref = "logging" }
logging = { module = "io.github.oshai:kotlin-logging", version.ref = "logging" }
github-api = { module = "org.kohsuke:github-api", version.ref = "github-api" }
kmongo = { module = "org.litote.kmongo:kmongo-coroutine-serialization", version.ref = "kmongo" }
mongo-driver = { module = "org.mongodb:mongodb-driver-kotlin-coroutine", version.ref = "mongo-driver" }
detekt = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt"}
cozy-welcome = {module = "org.quiltmc.community:module-welcome", version.ref = "cozy-welcome"}
dma = { module = "org.hyacinthbots:discord-moderation-actions", version.ref = "dma"}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 6 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,10 +131,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down
8 changes: 0 additions & 8 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
rootProject.name = "LilyBot"

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hyacinthbots.lilybot.internal

/**
* This object stores the constants for the Build ID and version of Lily in her current state
*/
object BuildInfo {
/** The short commit hash of this build of Lily. */
const val BUILD_ID: String = "{{ build_id }}"

/** The current version of LilyBot. */
const val LILY_VERSION: String = "{{ version }}"
}
10 changes: 5 additions & 5 deletions src/main/kotlin/org/hyacinthbots/lilybot/LilyBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
package org.hyacinthbots.lilybot

import com.kotlindiscord.kord.extensions.ExtensibleBot
import com.kotlindiscord.kord.extensions.adapters.mongodb.mongoDB
import com.kotlindiscord.kord.extensions.checks.hasPermission
import com.kotlindiscord.kord.extensions.modules.extra.phishing.DetectionAction
import com.kotlindiscord.kord.extensions.modules.extra.phishing.extPhishing
import com.kotlindiscord.kord.extensions.modules.extra.pluralkit.extPluralKit
import dev.kord.common.entity.Permission
import dev.kord.gateway.Intent
import dev.kord.gateway.PrivilegedIntent
import mu.KotlinLogging
import io.github.oshai.kotlinlogging.KotlinLogging
import org.hyacinthbots.docgenerator.docsGenerator
import org.hyacinthbots.docgenerator.enums.CommandTypes
import org.hyacinthbots.docgenerator.enums.SupportedFileFormat
import org.hyacinthbots.lilybot.database.collections.WelcomeChannelCollection
import org.hyacinthbots.lilybot.database.storage.MongoDBDataAdapter
import org.hyacinthbots.lilybot.extensions.config.Config
import org.hyacinthbots.lilybot.extensions.config.ConfigOptions
import org.hyacinthbots.lilybot.extensions.config.GuildLogging
Expand Down Expand Up @@ -60,7 +60,7 @@ val docFile = Path("./docs/commands.md")
suspend fun main() {
val bot = ExtensibleBot(BOT_TOKEN) {
database(true)
dataAdapter(::MongoDBDataAdapter)
mongoDB()

members {
lockMemberRequests = true // Collect members one at a time to avoid hitting rate limits
Expand Down Expand Up @@ -146,10 +146,10 @@ suspend fun main() {
// Connect to GitHub to allow the GitHub commands to function
try {
github = GitHubBuilder().build()
gitHubLogger.info("Connected to GitHub!")
gitHubLogger.info { "Connected to GitHub!" }
} catch (exception: IOException) {
exception.printStackTrace()
gitHubLogger.error("Failed to connect to GitHub!")
gitHubLogger.error { "Failed to connect to GitHub!" }
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.hyacinthbots.lilybot.database

import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent
import com.mongodb.client.model.Filters.eq
import dev.kord.core.Kord
import dev.kord.core.behavior.getChannelOfOrNull
import dev.kord.core.entity.channel.thread.ThreadChannel
import dev.kord.rest.request.KtorRequestException
import kotlinx.coroutines.flow.toList
import kotlinx.datetime.Clock
import mu.KotlinLogging
import org.hyacinthbots.lilybot.database.Cleanups.cleanupGuildData
Expand All @@ -24,7 +26,6 @@ import org.hyacinthbots.lilybot.database.collections.WelcomeChannelCollection
import org.hyacinthbots.lilybot.database.entities.GuildLeaveTimeData
import org.hyacinthbots.lilybot.database.entities.ThreadData
import org.koin.core.component.inject
import org.litote.kmongo.eq

/**
* This object contains the Database clean up functions, for removing old data from the database that Lily no longer
Expand All @@ -38,10 +39,10 @@ object Cleanups : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val guildLeaveTimeCollection = db.mainDatabase.getCollection<GuildLeaveTimeData>()
internal val guildLeaveTimeCollection = db.mainDatabase.getCollection<GuildLeaveTimeData>(GuildLeaveTimeData.name)

@PublishedApi
internal val threadDataCollection = db.mainDatabase.getCollection<ThreadData>()
internal val threadDataCollection = db.mainDatabase.getCollection<ThreadData>(ThreadData.name)

@PublishedApi
internal val cleanupsLogger = KotlinLogging.logger("Database Cleanups")
Expand Down Expand Up @@ -75,7 +76,7 @@ object Cleanups : KordExKoinComponent {
UtilityConfigCollection().clearConfig(it.guildId)
WarnCollection().clearWarns(it.guildId)
WelcomeChannelCollection().removeWelcomeChannelsForGuild(it.guildId, kord)
guildLeaveTimeCollection.deleteOne(GuildLeaveTimeData::guildId eq it.guildId)
guildLeaveTimeCollection.deleteOne(eq(GuildLeaveTimeData::guildId.name, it.guildId))
deletedGuildData += 1 // Increment the counter for logging
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/kotlin/org/hyacinthbots/lilybot/database/Collection.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.hyacinthbots.lilybot.database

/**
* This class stores the name of a collection, so it can be referenced easily, avoiding string duplication
*
* An example of how it should be used can be found below. The name property used in the get collection line comes from
* this class
* ```kt
* class MagicCollection : KordExKoinComponent {
* private val db: Database by inject()
*
* val collection = db.mainDatabase.getCollection<MagicCollectionData>(name)
*
* suspend fun get(): List<MagicCollectionData> = collection.find().toList()
*
* companion object : Collection("magicCollection")
* }
* ```
*
* @property name The name of the collection
*/
abstract class Collection(val name: String)
Loading