From 613d16ef623f9f96b17b9b4053315f603003e1c4 Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 13:18:05 +0200 Subject: [PATCH 1/8] feat: improved SubscriptionRepository --- .../repository/SubscriptionRepository.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/kotlin/net/moonleay/rssbot/data/database/repository/SubscriptionRepository.kt b/src/main/kotlin/net/moonleay/rssbot/data/database/repository/SubscriptionRepository.kt index 4bf6b15..f80d96b 100644 --- a/src/main/kotlin/net/moonleay/rssbot/data/database/repository/SubscriptionRepository.kt +++ b/src/main/kotlin/net/moonleay/rssbot/data/database/repository/SubscriptionRepository.kt @@ -46,6 +46,27 @@ object SubscriptionRepository { return dataList } + fun getAllChannel(channelId: Long): List { + val dataList = mutableListOf() + transaction { + SubscriptionsTable.select { + SubscriptionsTable.channelId eq channelId + }.forEach { + dataList.add( + SubscriptionData( + it[SubscriptionsTable.id], + it[SubscriptionsTable.serverId], + it[SubscriptionsTable.channelId], + EmbedUtil.getColorFromString(it[SubscriptionsTable.subscriptionColor]), + it[SubscriptionsTable.subscriptionName], + it[SubscriptionsTable.feedUrl] + ) + ) + } + } + return dataList + } + fun get(channelId: Long, feedName: String): SubscriptionData? { var data: SubscriptionData? = null @@ -66,6 +87,16 @@ object SubscriptionRepository { return data } + fun existsWithUrl(channelId: Long, feedUrl: String): Boolean { + var exists = false + transaction { + exists = SubscriptionsTable.select { + (SubscriptionsTable.channelId eq channelId) and (SubscriptionsTable.feedUrl eq feedUrl) + }.count() > 0 + } + return exists + } + fun exists(channelId: Long, feedName: String): Boolean { var exists = false transaction { From 8f4585f1e99a4af6184543c55f6ba8f83ef46746 Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 13:18:33 +0200 Subject: [PATCH 2/8] feat!: removed uniqueIndex from guid --- .../kotlin/net/moonleay/rssbot/data/database/tables/RSSTable.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/moonleay/rssbot/data/database/tables/RSSTable.kt b/src/main/kotlin/net/moonleay/rssbot/data/database/tables/RSSTable.kt index f1976b7..c9e0286 100644 --- a/src/main/kotlin/net/moonleay/rssbot/data/database/tables/RSSTable.kt +++ b/src/main/kotlin/net/moonleay/rssbot/data/database/tables/RSSTable.kt @@ -22,7 +22,7 @@ import org.jetbrains.exposed.sql.Table object RSSTable : Table(name = "rss") { - val guid = text("guid").uniqueIndex() + val guid = text("guid") val subscriptionId = integer("subscription_id") references SubscriptionsTable.id override val primaryKey = PrimaryKey(guid, subscriptionId, name = "PK_RSS") } From 3654649f9882e50fab1209f66420af2a381dc00b Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 13:22:52 +0200 Subject: [PATCH 3/8] feat: added existence check to FeedExtension --- .../net/moonleay/rssbot/extensions/FeedExtension.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/kotlin/net/moonleay/rssbot/extensions/FeedExtension.kt b/src/main/kotlin/net/moonleay/rssbot/extensions/FeedExtension.kt index 8b0bf0b..06b40d1 100644 --- a/src/main/kotlin/net/moonleay/rssbot/extensions/FeedExtension.kt +++ b/src/main/kotlin/net/moonleay/rssbot/extensions/FeedExtension.kt @@ -86,6 +86,19 @@ class FeedExtension : Extension() { } return@action } + if (SubscriptionRepository.exists(this.channel.id.value.toLong(), feedName) || SubscriptionRepository.existsWithUrl(this.channel.id.value.toLong(), feedUrl)) { + this.respond { + this.embeds.add( + MessageUtil.getEmbed( + EmbedColor.ERROR, + "Feed already exists", + "The feed \"${feedName}\" already exists", + user.username + ) + ) + } + return@action + } val id = SubscriptionRepository.write( SubscriptionData( 0, From b8b878a54bc79fa6a5346674a84eab5705cc224a Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 13:23:03 +0200 Subject: [PATCH 4/8] feat: added FeedsExtension --- .../rssbot/extensions/FeedsExtension.kt | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/kotlin/net/moonleay/rssbot/extensions/FeedsExtension.kt diff --git a/src/main/kotlin/net/moonleay/rssbot/extensions/FeedsExtension.kt b/src/main/kotlin/net/moonleay/rssbot/extensions/FeedsExtension.kt new file mode 100644 index 0000000..93cded4 --- /dev/null +++ b/src/main/kotlin/net/moonleay/rssbot/extensions/FeedsExtension.kt @@ -0,0 +1,40 @@ +package net.moonleay.rssbot.extensions + +import com.kotlindiscord.kord.extensions.commands.Arguments +import com.kotlindiscord.kord.extensions.commands.converters.impl.string +import com.kotlindiscord.kord.extensions.extensions.Extension +import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand +import com.kotlindiscord.kord.extensions.types.respond +import net.moonleay.rssbot.data.database.repository.RSSRepository +import net.moonleay.rssbot.data.database.repository.SubscriptionRepository +import net.moonleay.rssbot.util.EmbedColor +import net.moonleay.rssbot.util.MessageUtil + +class FeedsExtension : Extension() { + + override val name = "feeds" + override val allowApplicationCommandInDMs: Boolean + get() = false + + + override suspend fun setup() { + ephemeralSlashCommand() { + name = "feeds" + description = "Show all active feeds for this channel" + this.action { + val user = this.user.asUser() + val subscriptions = SubscriptionRepository.getAllChannel(this.channel.id.value.toLong()) + this.respond { + this.embeds.add( + MessageUtil.getEmbed( + EmbedColor.INFO, + "Feeds", + subscriptions.joinToString("\n") { it.feedName + " [[feed url](" + it.feedUrl + ")]" }, + user.username + ) + ) + } + } + } + } +} From 32b332196807a4c06def473421229478356db2bc Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 13:23:24 +0200 Subject: [PATCH 5/8] fix: fixed name in FeedUpdater --- src/main/kotlin/net/moonleay/rssbot/jobs/FeedUpdater.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/moonleay/rssbot/jobs/FeedUpdater.kt b/src/main/kotlin/net/moonleay/rssbot/jobs/FeedUpdater.kt index 14d812d..ff712b6 100644 --- a/src/main/kotlin/net/moonleay/rssbot/jobs/FeedUpdater.kt +++ b/src/main/kotlin/net/moonleay/rssbot/jobs/FeedUpdater.kt @@ -38,7 +38,7 @@ import net.moonleay.rssbot.util.MessageUtil object FeedUpdater : ICronjob { override val jobName: String - get() = "StatusUpdater" + get() = "FeedUpdater" override val jobIncoming: String get() = "0 /20 * * * * 0o *" //Every 20 seconds override val jobType: CronjobType From c733bf14d12fb30060b8424dc4ce3ea0737f539e Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 13:29:30 +0200 Subject: [PATCH 6/8] fix: shoten title when its too long --- src/main/kotlin/net/moonleay/rssbot/util/MessageUtil.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/moonleay/rssbot/util/MessageUtil.kt b/src/main/kotlin/net/moonleay/rssbot/util/MessageUtil.kt index 1402431..d6d8ace 100644 --- a/src/main/kotlin/net/moonleay/rssbot/util/MessageUtil.kt +++ b/src/main/kotlin/net/moonleay/rssbot/util/MessageUtil.kt @@ -177,7 +177,10 @@ object MessageUtil { ): EmbedBuilder { val ebb = EmbedBuilder() val now: LocalDateTime = LocalDateTime.now() - ebb.title = title + if (title.length > 250) + ebb.title = title.substring(0, 250) + "[...]" + else + ebb.title = title ebb.author { this.name = author this.icon = logo From 3021d4a0f70164f0e7afe28d4a9eb1f9a62b8e09 Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 13:29:46 +0200 Subject: [PATCH 7/8] feat: add FeedsExtension --- src/main/kotlin/net/moonleay/rssbot/Bot.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/net/moonleay/rssbot/Bot.kt b/src/main/kotlin/net/moonleay/rssbot/Bot.kt index 735ecf3..ee2decd 100644 --- a/src/main/kotlin/net/moonleay/rssbot/Bot.kt +++ b/src/main/kotlin/net/moonleay/rssbot/Bot.kt @@ -25,6 +25,7 @@ import dev.kord.core.on import net.moonleay.rssbot.data.CredentialManager import net.moonleay.rssbot.data.database.DB import net.moonleay.rssbot.extensions.FeedExtension +import net.moonleay.rssbot.extensions.FeedsExtension import net.moonleay.rssbot.extensions.StuffExtension import net.moonleay.rssbot.jobs.FeedUpdater import net.moonleay.rssbot.jobs.component.JobManager @@ -75,6 +76,7 @@ object Bot { extensions { add(::FeedExtension) add(::StuffExtension) + add(::FeedsExtension) } this.presence { From ccf5ef4f0d1ef7c9a27fac70f7c5894e3a62a6b1 Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 13:29:56 +0200 Subject: [PATCH 8/8] chore: bump version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0eb54ca..c675a62 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ val ownerID = 372703841151614976L group = "net.moonleay.rssbot" version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" } ?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" } - ?: "0.1.0" + ?: "0.2.1" val kordver = "1.5.10-SNAPSHOT" val coroutinesver = "1.7.3"