Skip to content

Commit

Permalink
Merge pull request #341 from HyacinthBots/develop
Browse files Browse the repository at this point in the history
4.8.0
  • Loading branch information
NoComment1105 authored Feb 28, 2023
2 parents c7f221a + 4eaa6bf commit ea6b760
Show file tree
Hide file tree
Showing 34 changed files with 451 additions and 45 deletions.
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.kt text eol=lf diff=kotlin
*.kts text eol=lf diff=kotlin

gradlew text eol=lf
*.bat text eol=crlf

*.md text eol=lf diff=markdown

*.properties text eol=lf
*.yml text eol=lf

*.class binary
*.jar binary
*.png binary
1 change: 1 addition & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
arguments: build --stacktrace
gradle-home-cache-cleanup: true

- name: Upload build artifacts
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
arguments: build --stacktrace
gradle-home-cache-cleanup: true

- name: Upload build artifacts
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
uses: gradle/gradle-build-action@v2
with:
arguments: build --stacktrace
gradle-home-cache-cleanup: true

- name: Upload artifacts GitHub
uses: AButler/[email protected]
Expand Down
14 changes: 7 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
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")
Expand All @@ -14,7 +16,7 @@ plugins {
}

group = "org.hyacinthbots.lilybot"
version = "4.7.0"
version = "4.8.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -84,13 +86,11 @@ gitHooks {

tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "17"
languageVersion = libs.plugins.kotlin.get().version.requiredVersion.substringBeforeLast(".")
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget("17"))
languageVersion.set(KotlinVersion.fromVersion(libs.plugins.kotlin.get().version.requiredVersion.substringBeforeLast(".")))
incremental = true
freeCompilerArgs = listOf(
"-opt-in=kotlin.RequiresOptIn"
)
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
}
}

Expand Down
18 changes: 18 additions & 0 deletions docs/changelogs/4.x.x/4.8.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# LilyBot 4.8.0

This update fixes bugs and adds a couple of new features
You can find the full changelog below

New:
* Automatically applies she-her and it-its roles to Lily when a pronoun role menu is created
* Allow users to subscribe to roles in a similar fashion to role menus, but with commands

Change:
* Update to Kotlin 1.8.10, Gradle 8.0.1 and other dependencies (Internal)
* Removed configDb parameter from migrations (Internal)

Fix:
* Remove deprecated kord functions (Internal)
* Fix reminder IDs sometimes overlapping causing duplicate entries and errors

You can find a list of all the commits in this update [here](https://github.com/hyacinthbots/LilyBot/compare/v4.6.3...v4.7.0)
22 changes: 22 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,28 @@ Required Member Permissions: Manage Messages

* **Arguments**:
None
---
#### Command name: `role-subscription update`
**Description**: Update your role subscription

* **Arguments**:
None
---
#### Command name: `role-subscription add-role`
**Description**: Add a role that can be added through role subscription commands
Required Member Permissions: Manage Server, Manage Roles

* **Arguments**:
* `role` - A role to add or remove from the subscribable roles - Role

---
#### Command name: `role-subscription remove-role`
**Description**: Remove a role that can be added through role subscription commands
Required Member Permissions: Manage Server, Manage Roles

* **Arguments**:
* `role` - A role to add or remove from the subscribable roles - Role

---
### Command name: `tag-preview`
Description: Preview a tag's contents without sending it publicly.
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
14 changes: 7 additions & 7 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[versions]
# Plugins
kotlin = "1.8.0"
shadow = "7.1.2"
kotlin = "1.8.10"
shadow = "8.1.0"
detekt = "1.22.0"
git-hooks = "0.0.2"
grgit = "5.0.0"
blossom = "1.3.1"

# Libraries
kord-extensions = "1.5.6-20230208.121744-1"
logging = "3.0.4"
kord-extensions = "1.5.6-20230224.151334-5"
logging = "3.0.5"
logback = "1.4.5"
github-api = "1.313"
github-api = "1.314"
kmongo = "4.8.0"
cozy-welcome = "1.0-SNAPSHOT"
dma = "v0.2.0"
docgenerator = "0.1.2"
dma = "0.2.0-SNAPSHOT"
docgenerator = "0.1.2-SNAPSHOT"

[libraries]
kord-extensions-core = { module = "com.kotlindiscord.kord.extensions:kord-extensions", version.ref = "kord-extensions" }
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
rootProject.name = "LilyBot"

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
versionCatalogs {
create("libs") {
from(files("libs.versions.toml"))
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.hyacinthbots.lilybot.database.collections.ModerationConfigCollection
import org.hyacinthbots.lilybot.database.collections.NewsChannelPublishingCollection
import org.hyacinthbots.lilybot.database.collections.ReminderCollection
import org.hyacinthbots.lilybot.database.collections.RoleMenuCollection
import org.hyacinthbots.lilybot.database.collections.RoleSubscriptionCollection
import org.hyacinthbots.lilybot.database.collections.TagsCollection
import org.hyacinthbots.lilybot.database.collections.ThreadsCollection
import org.hyacinthbots.lilybot.database.collections.UtilityConfigCollection
Expand Down Expand Up @@ -70,6 +71,7 @@ object Cleanups : KordExKoinComponent {
NewsChannelPublishingCollection().clearAutoPublishingForGuild(it.guildId)
ReminderCollection().removeGuildReminders(it.guildId)
RoleMenuCollection().removeAllRoleMenus(it.guildId)
RoleSubscriptionCollection().removeAllSubscribableRoles(it.guildId)
TagsCollection().clearTags(it.guildId)
ThreadsCollection().removeGuildThreads(it.guildId)
UtilityConfigCollection().clearConfig(it.guildId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.hyacinthbots.lilybot.database.collections

import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent
import dev.kord.common.entity.Snowflake
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.RoleSubscriptionData
import org.koin.core.component.inject
import org.litote.kmongo.eq

/**
* This class contains the functions for interacting with the [Role Subscription database][RoleSubscriptionData]. This
* class contains the functions for getting, adding, removing and clearing subscribable roles.
*
* @since 4.9.0
* @see getSubscribableRoles
* @see createSubscribableRoleRecord
* @see addSubscribableRole
* @see removeSubscribableRole
* @see removeAllSubscribableRoles
*/
class RoleSubscriptionCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<RoleSubscriptionData>()

/**
* Gets the roles that are subscribable for a given guild.
*
* @param inputGuildId The guild to get the roles for
* @return The [RoleSubscriptionData] for the guild
*
* @author NoComment1105
* @since 4.9.0
*/
suspend inline fun getSubscribableRoles(inputGuildId: Snowflake): RoleSubscriptionData? =
collection.findOne(RoleSubscriptionData::guildId eq inputGuildId)

/**
* Creates a subscribable role record in the database. This should only be used if a record does not already exist.
*
* @param inputGuildId The ID of the guild to create the record for
*
* @author NoComment1105
* @since 4.9.0
*/
suspend inline fun createSubscribableRoleRecord(inputGuildId: Snowflake) =
collection.insertOne(RoleSubscriptionData(inputGuildId, mutableListOf()))

/**
* Adds a role to the subscribable role list.
*
* @param inputGuildId The ID of the guild to add to the list
* @param inputRoleId The ID of the role to add
* @return True if the transaction was a success, false if it was not, null if the collection does not exist
*
* @author NoComment1105
* @since 4.9.0
*/
suspend inline fun addSubscribableRole(inputGuildId: Snowflake, inputRoleId: Snowflake): Boolean? {
val col = collection.findOne(RoleSubscriptionData::guildId eq inputGuildId) ?: return null
val newRoleList = col.subscribableRoles
if (newRoleList.contains(inputRoleId)) return false else newRoleList.add(inputRoleId)
collection.updateOne(
RoleSubscriptionData::guildId eq inputGuildId,
RoleSubscriptionData(inputGuildId, newRoleList)
)
return true
}

/**
* Removes a role to the subscribable role list.
*
* @param inputGuildId The ID of the guild to alter the list of
* @param inputRoleId The ID of the role to rem,ove
* @return True if the transaction was a success, false if it was not, null if the collection does not exist
*
* @author NoComment1105
* @since 4.9.0
*/
suspend inline fun removeSubscribableRole(inputGuildId: Snowflake, inputRoleId: Snowflake): Boolean? {
val col = collection.findOne(RoleSubscriptionData::guildId eq inputGuildId) ?: return null
val newRoleList = col.subscribableRoles
if (!newRoleList.contains(inputRoleId)) {
return false
} else {
val removal = newRoleList.remove(inputRoleId)
if (!removal) return false
}
collection.updateOne(
RoleSubscriptionData::guildId eq inputGuildId,
RoleSubscriptionData(inputGuildId, newRoleList)
)
return true
}

/**
* Removes all subscribable roles for a guild.
*
* @param inputGuildId The ID of the guild to remove subscribable roles for
*
* @author NoComment1105
* @since 4.9.0
*/
suspend inline fun removeAllSubscribableRoles(inputGuildId: Snowflake) =
collection.deleteOne(RoleSubscriptionData::guildId eq inputGuildId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.hyacinthbots.lilybot.database.entities

import dev.kord.common.entity.Snowflake
import kotlinx.serialization.Serializable

/**
* The data for role subscriptions.
*
* @property guildId The ID of the guild the subscription roles are for
* @property subscribableRoles The roles that can be subscribed too.
* @since 4.9.0
*/
@Serializable
data class RoleSubscriptionData(
val guildId: Snowflake,
val subscribableRoles: MutableList<Snowflake>
)
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ object Migrator : KordExKoinComponent {
5 -> ::mainV5
6 -> ::mainV6
7 -> ::mainV7
8 -> ::mainV8
else -> break
}(db.mainDatabase, db.configDatabase)
}(db.mainDatabase)

logger.info { "Migrated main database to version $nextVersion." }
} catch (t: Throwable) {
Expand Down Expand Up @@ -105,7 +106,7 @@ object Migrator : KordExKoinComponent {
3 -> ::configV3
4 -> ::configV4
else -> break
}(db.configDatabase, db.mainDatabase)
}(db.configDatabase)

logger.info { "Migrated config database to version $nextVersion" }
} catch (t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import org.litote.kmongo.coroutine.CoroutineDatabase
import org.litote.kmongo.exists
import org.litote.kmongo.setValue

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
suspend fun configV1(configDb: CoroutineDatabase, mainDb: CoroutineDatabase) {
suspend fun configV1(configDb: CoroutineDatabase) {
with(configDb.getCollection<LoggingConfigData>("loggingConfigData")) {
updateMany(
LoggingConfigData::enableMessageEditLogs exists false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import org.litote.kmongo.coroutine.CoroutineDatabase
import org.litote.kmongo.exists
import org.litote.kmongo.setValue

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
suspend fun configV2(db: CoroutineDatabase, mainDb: CoroutineDatabase) {
suspend fun configV2(db: CoroutineDatabase) {
with(db.getCollection<ModerationConfigData>("moderationConfigData")) {
updateMany(
ModerationConfigData::quickTimeoutLength exists false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import org.litote.kmongo.coroutine.CoroutineDatabase
import org.litote.kmongo.exists
import org.litote.kmongo.setValue

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
suspend fun configV3(db: CoroutineDatabase, mainDb: CoroutineDatabase) {
suspend fun configV3(db: CoroutineDatabase) {
with(db.getCollection<LoggingConfigData>("loggingConfigData")) {
updateMany(
LoggingConfigData::enablePublicMemberLogs exists false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package org.hyacinthbots.lilybot.database.migrations.config

import org.litote.kmongo.coroutine.CoroutineDatabase

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
suspend fun configV4(db: CoroutineDatabase, mainDb: CoroutineDatabase) {
@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER", "RedundantSuspendModifier")
suspend fun configV4(db: CoroutineDatabase) {
// Support config has been removed.
// if (db.getCollection<SupportConfigData>().find().toList().isEmpty()) {
// db.dropCollection("supportConfigData")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package org.hyacinthbots.lilybot.database.migrations.main
import org.hyacinthbots.lilybot.database.entities.StatusData
import org.litote.kmongo.coroutine.CoroutineDatabase

@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER")
// This was commented out due to the remindme data class being removed
suspend fun mainV1(db: CoroutineDatabase, configDb: CoroutineDatabase) {
suspend fun mainV1(db: CoroutineDatabase) {
// val reminders = db.getCollection<RemindMeData>("remindMeData")
//
// val repeating = mutableListOf<ReplaceOneModel<RemindMeData>>()
Expand Down
Loading

0 comments on commit ea6b760

Please sign in to comment.