Skip to content

Commit

Permalink
Merge pull request #297 from HyacinthBots/develop
Browse files Browse the repository at this point in the history
4.4.0
  • Loading branch information
NoComment1105 authored Nov 9, 2022
2 parents f4f6d23 + 214fd90 commit 84b2f7e
Show file tree
Hide file tree
Showing 34 changed files with 2,123 additions and 1,471 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If you're looking to set up a development environment for Lily, try our [develop


## Links
* Visit [our buymeacoffee page](https://buymeacoffee.com/Hyacinthbots) to support the continued development of HyacinthBots projects!
* Visit [our Buy Me a Coffee page](https://buymeacoffee.com/Hyacinthbots) to support the continued development of HyacinthBots projects!
* Join [our Discord](https://discord.gg/hy2329fcTZ) to watch the development and get support for LilyBot and other HyacinthBots projects!
* Follow us on Twitter [`@HyacinthBots`](https://twitter.com/hyacinthbots)
* Email us at [`hyacinthbots@outlook.com`](mailto:hyacinthbots@outlook.com)
Expand Down
16 changes: 16 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Security Policy

This policy details how to report vulnerabilities and the steps taken to ensure vulnerabilities are mitigated.

## Supported Versions
We only support the latest version of LilyBot, as this is the version used in our production bot environment. If you are using an outdated version, please update and see if the vulnerability is still present.

## Reporting a Vulnerability

When reporting a vulnerability, we request that you gather all the information you can about the vulnerability and compile it into a document before sending it to us via email at hyacinthbots@outlook.com.

You will receive a response quickly declaring that we have received your email and the contents of it and are now aware of the vulnerability. We will proceed to make inquiries into the severity of the vulnerability and determine the speed and course of action to take.

You will receive updates on the vulnerability as and when we have them. You will be regularly informed of what we find and the course of action we are taking.

Upon removal of the vulnerability you will receive an email detailing this and a new release will be created, containing a fix for the vulnerability, to ensure that everyone is made safe.
32 changes: 31 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.FileOutputStream
import java.util.*

plugins {
application
Expand All @@ -12,7 +15,7 @@ plugins {
}

group = "org.hyacinthbots.lilybot"
version = "4.3.0"
version = "4.4.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -73,6 +76,8 @@ dependencies {

// Cozy's welcome module
implementation(libs.cozy.welcome)

implementation(libs.dma)
}

application {
Expand All @@ -85,6 +90,17 @@ gitHooks {
)
}

val generatedVersionDir = "$buildDir/generated-version"

sourceSets {
main {
kotlin {
output.dir(generatedVersionDir)
}
}
}


tasks {
withType<KotlinCompile> {
kotlinOptions {
Expand Down Expand Up @@ -121,6 +137,20 @@ tasks {
gradleVersion = "7.5.1"
distributionType = Wrapper.DistributionType.BIN
}

register("generateVersionProperties") {
doLast {
val propertiesFile = file("$generatedVersionDir/version.properties")
propertiesFile.parentFile.mkdirs()
val properties = Properties()
properties.setProperty("version", "$version")
properties.store(FileOutputStream(propertiesFile), null)
}
}

named("processResources") {
dependsOn("generateVersionProperties")
}
}

detekt {
Expand Down
2 changes: 2 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ formatting:
NoEmptyFirstLineInMethodBlock:
active: true
autoCorrect: true
NoWildcardImports:
packagesToUseImportOnDemandProperty: ""
PackageName:
active: true
autoCorrect: true
Expand Down
22 changes: 22 additions & 0 deletions docs/changelogs/4.4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# LilyBot 4.4.0

This update fixes a number of exceptions thrown by the bot under certain conditions, as well as changes to info commands
and the moderation commands.
You can find the full changelog below.

New:
* Completely rewritten moderation commands, now with a Message command for quick moderation actions. This also comes with
complete PluralKit support out of the box
* A Security Policy has been written to show users where to send security reports if necessary

Change:
* Info commands have been rewritten and restructured to make more sense and provide useful information
* auto-ban anyone who says the word Kotlin

Fix:
* Fixes for reminders to reduce the amount of exceptions thrown
* Switch to using `OrNull` statements and catching nulls rather than letting exceptions fly
* Update KordEx to fix an issue with PluralKit Extension


You can find a list of all the commits in this update [here](https://github.com/hyacinthbots/LilyBot/compare/v4.3.0...v4.4.0)
4 changes: 2 additions & 2 deletions docs/commanddocs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions = "Manage Guild"
[[command]]
category = "Administration commands"
name = "config moderation"
args = "* `enable` - Whether to enable the moderation system or not - Boolean\n* `moderator-role` - The role of the guild moderators, used for pinging in message logs and adding to threads\n* `mod-action-log` - The channel to store the moderation actions in - Channel\n*`log-publicly` - Whether to log moderation actions in the channel they were run in as well as the action log. Defaults to false - Optional Boolean"
args = "* `enable` - Whether to enable the moderation system or not - Boolean\n* `moderator-role` - The role of the guild moderators, used for pinging in message logs and adding to threads\n* `mod-action-log` - The channel to store the moderation actions in - Channel\n* `quick-timeout-length` - The length of timeout to set when using the `Moderate` message command - Optional Duration\n* `warn-auto-punishments` - Whether to automatically punish users for reaching a certain warn strike count - Optional Boolean\n* `log-publicly` - Whether to log moderation actions in the channel they were run in as well as the action log. Defaults to false - Optional Boolean"
result = "The config is set for moderation."
permissions = "Manage Guild"

Expand Down Expand Up @@ -82,7 +82,7 @@ permissions = "Ban Members"
category = "Moderation commands"
name = "warn"
args = "* `user` - Person to warn - User\n* `reason` - Reason for warn - Optional String\n* `image` - An image to provide extra context for the action - Optional Attachment\n* `dm` - Whether to DM the user or not. Default: True - Optional Boolean"
result = "Warns `warnUser` with a DM and adds a strike to their points total. Depending on their new points total, action is taken based on the below table.\n\n| Points | Sanction |\n|:------:|:----------------:|\n| 1 | None. |\n| 2 | 3 hour timeout. |\n| 3 | 12 hour timeout. |\n| 3+ | 3 day timeout. |"
result = "Warns `warnUser` with a DM and adds a strike to their points total. Depending on their new points total and if auto-punishments is enabled in the config, action is taken based on the below table.\n\n| Points | Sanction |\n|:------:|:----------------:|\n| 1 | None. |\n| 2 | 3 hour timeout. |\n| 3 | 12 hour timeout. |\n| 3+ | 3 day timeout. |"
permissions = "Moderate Members"

[[command]]
Expand Down
6 changes: 4 additions & 2 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ These are commands for the maintenance of LilyBot. The can only be run by Server
* `enable` - Whether to enable the moderation system or not - Boolean
* `moderator-role` - The role of the guild moderators, used for pinging in message logs and adding to threads
* `mod-action-log` - The channel to store the moderation actions in - Channel
*`log-publicly` - Whether to log moderation actions in the channel they were run in as well as the action log. Defaults to false - Optional Boolean
* `quick-timeout-length` - The length of timeout to set when using the `Moderate` message command - Optional Duration
* `warn-auto-punishments` - Whether to automatically punish users for reaching a certain warn strike count - Optional Boolean
* `log-publicly` - Whether to log moderation actions in the channel they were run in as well as the action log. Defaults to false - Optional Boolean

**Result**: The config is set for moderation.

Expand Down Expand Up @@ -157,7 +159,7 @@ These commands are for use by moderators. They utilize built-in permission check
* `image` - An image to provide extra context for the action - Optional Attachment
* `dm` - Whether to DM the user or not. Default: True - Optional Boolean

**Result**: Warns `warnUser` with a DM and adds a strike to their points total. Depending on their new points total, action is taken based on the below table.
**Result**: Warns `warnUser` with a DM and adds a strike to their points total. Depending on their new points total and if auto-punishments is enabled in the config, action is taken based on the below table.

| Points | Sanction |
|:------:|:----------------:|
Expand Down
3 changes: 1 addition & 2 deletions docs/usage-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ If you have issues with this guide, please join [our discord](https://discord.gg
# Step 1 - Obtain an invitation link
Click on the official LilyBot instance, where you'll be able to use the `Add To Server` button

Alternatively, use [this link](
https://discord.com/api/oauth2/authorize?client_id=876278900836139008&permissions=1428479371270&scope=bot%20applications.commands)
Alternatively, use [this link](https://discord.com/api/oauth2/authorize?client_id=876278900836139008&permissions=1151990787078&scope=bot%20applications.commands)
to invite LilyBot.

# Step 2 - Using your invitation link
Expand Down
6 changes: 4 additions & 2 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[versions]
kotlin = "1.7.20" # Note: Plugin versions must be updated in the settings.gradle.kts too

kord-extensions = "1.5.5-20221019.205922-33"
logging = "3.0.2"
kord-extensions = "1.5.5-20221107.093708-35"
logging = "3.0.4"
logback = "1.4.4"
github-api = "1.313"
kmongo = "4.7.1"
detekt = "1.21.0"
koma = "1.1.0"
cozy-welcome = "1.0-SNAPSHOT"
dma = "0.1.0"

[libraries]
kord-extensions = { module = "com.kotlindiscord.kord.extensions:kord-extensions", version.ref = "kord-extensions" }
Expand All @@ -23,3 +24,4 @@ kmongo = { module = "org.litote.kmongo:kmongo-coroutine-serialization", version.
detekt = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt"}
koma = { module = "cc.ekblad:4koma", version.ref = "koma" }
cozy-welcome = {module = "org.quiltmc.community:module-welcome", version.ref = "cozy-welcome"}
dma = { module = "com.github.nocomment1105:discord-moderation-actions", version.ref = "dma"}
8 changes: 4 additions & 4 deletions src/main/kotlin/org/hyacinthbots/lilybot/LilyBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import org.hyacinthbots.lilybot.extensions.events.MemberLogging
import org.hyacinthbots.lilybot.extensions.events.MessageDelete
import org.hyacinthbots.lilybot.extensions.events.MessageEdit
import org.hyacinthbots.lilybot.extensions.events.ThreadInviter
import org.hyacinthbots.lilybot.extensions.moderation.LockingCommands
import org.hyacinthbots.lilybot.extensions.moderation.ModerationCommands
import org.hyacinthbots.lilybot.extensions.moderation.Report
import org.hyacinthbots.lilybot.extensions.moderation.TemporaryModeration
import org.hyacinthbots.lilybot.extensions.moderation.TerminalModeration
import org.hyacinthbots.lilybot.extensions.util.GalleryChannel
import org.hyacinthbots.lilybot.extensions.util.Github
import org.hyacinthbots.lilybot.extensions.util.GuildAnnouncements
Expand Down Expand Up @@ -86,19 +86,19 @@ suspend fun main() {
add(::InfoCommands)
add(::GuildAnnouncements)
add(::GuildLogging)
add(::LockingCommands)
add(::LogUploading)
add(::MemberLogging)
add(::MessageDelete)
add(::MessageEdit)
add(::ModerationCommands)
add(::ModUtilities)
add(::PublicUtilities)
add(::Reminders)
add(::Report)
add(::RoleMenu)
add(::StartupHooks)
add(::Tags)
add(::TemporaryModeration)
add(::TerminalModeration)
add(::ThreadControl)
add(::ThreadInviter)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ object Cleanups : KordExKoinComponent {
deletedThreads++
return
}
val guild = kordInstance.getGuild(it.guildId) ?: return
val guild = kordInstance.getGuildOrNull(it.guildId) ?: return
val thread = guild.getChannelOfOrNull<ThreadChannel>(it.threadId) ?: continue
val latestMessage = thread.getLastMessage() ?: continue
val timeSinceLatestMessage = Clock.System.now() - latestMessage.id.timestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.hyacinthbots.lilybot.database.collections

import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent
import kotlinx.datetime.Instant
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.UptimeData
import org.koin.core.component.inject
import org.litote.kmongo.ne
import org.litote.kmongo.setValue

/**
* Stores the functions for interacting with [the uptime database][UptimeData]. This class contains the functions for
* getting, setting and updating the data
*
* @see get
* @see set
* @see update
* @since 4.2.0
*/
class UptimeCollection : KordExKoinComponent {
private val db: Database by inject()

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

/**
* Gets the uptime data from the database.
*
* @return the main metadata
* @author NoComment1105
* @since 4.2.0
*/
suspend fun get(): UptimeData? =
collection.findOne()

/**
* Sets the on time.
*
* @author NoComment1105
* @since 4.2.0
*/
suspend fun set(onTime: Instant) =
collection.insertOne(UptimeData(onTime))

/**
* Updates the uptime data in the database with the new [data][UptimeData].
*
* @author NoComment1105
* @since 4.2.0
*/
suspend fun update(onTime: Instant) =
collection.updateOne(UptimeData::onTime ne null, setValue(UptimeData::onTime, onTime))
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WelcomeChannelCollection : KordExKoinComponent, CozyWelcomeChannelData {
}

suspend fun removeWelcomeChannelsForGuild(guildId: Snowflake, kord: Kord) {
val guild = kord.getGuild(guildId) ?: return
val guild = kord.getGuildOrNull(guildId) ?: return
guild.channels.collect {
collection.deleteOne(WelcomeChannelData::channelId eq it.id)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hyacinthbots.lilybot.database.entities

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

/**
Expand Down Expand Up @@ -33,6 +34,9 @@ data class LoggingConfigData(
* @property enabled If the support module is enabled or not
* @property channel The ID of the action log for the guild
* @property role The ID of the moderation role for the guild
* @property quickTimeoutLength The length of timeout to apply when using the moderate menu
* @property autoPunishOnWarn Whether to automatically apply punishments for reaching certain warn strike counts
* @property publicLogging Whether to log moderation actions publicly in the channel the command was run in
* @since 4.0.0
*/
@Serializable
Expand All @@ -41,6 +45,8 @@ data class ModerationConfigData(
val enabled: Boolean,
val channel: Snowflake?,
val role: Snowflake?,
val quickTimeoutLength: DateTimePeriod?,
val autoPunishOnWarn: Boolean?,
val publicLogging: Boolean?,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.hyacinthbots.lilybot.database.entities

import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

/**
* The data to help calculate bot uptime.
*
* @property onTime The instant the bot turned on
* @since 4.2.0
*/
@Serializable
data class UptimeData(
val onTime: Instant
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.hyacinthbots.lilybot.database.collections.MainMetaCollection
import org.hyacinthbots.lilybot.database.entities.ConfigMetaData
import org.hyacinthbots.lilybot.database.entities.MainMetaData
import org.hyacinthbots.lilybot.database.migrations.config.configV1
import org.hyacinthbots.lilybot.database.migrations.config.configV2
import org.hyacinthbots.lilybot.database.migrations.main.mainV1
import org.hyacinthbots.lilybot.database.migrations.main.mainV2
import org.hyacinthbots.lilybot.database.migrations.main.mainV3
Expand Down Expand Up @@ -101,6 +102,7 @@ object Migrator : KordExKoinComponent {
@Suppress("UseIfInsteadOfWhen")
when (nextVersion) {
1 -> ::configV1
2 -> ::configV2
else -> break
}(db.configDatabase)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.hyacinthbots.lilybot.database.migrations.config

import org.hyacinthbots.lilybot.database.entities.ModerationConfigData
import org.litote.kmongo.coroutine.CoroutineDatabase
import org.litote.kmongo.exists
import org.litote.kmongo.setValue

suspend fun configV2(db: CoroutineDatabase) {
with(db.getCollection<ModerationConfigData>("moderationConfigData")) {
updateMany(
ModerationConfigData::quickTimeoutLength exists false,
setValue(ModerationConfigData::quickTimeoutLength, null)
)

updateMany(
ModerationConfigData::autoPunishOnWarn exists false,
setValue(ModerationConfigData::autoPunishOnWarn, null)
)
}
}
Loading

0 comments on commit 84b2f7e

Please sign in to comment.