Compare commits
8 commits
5a39f49824
...
ccf5ef4f0d
Author | SHA1 | Date | |
---|---|---|---|
ccf5ef4f0d | |||
3021d4a0f7 | |||
c733bf14d1 | |||
32b3321968 | |||
b8b878a54b | |||
3654649f98 | |||
8f4585f1e9 | |||
613d16ef62 |
8 changed files with 93 additions and 4 deletions
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -46,6 +46,27 @@ object SubscriptionRepository {
|
|||
return dataList
|
||||
}
|
||||
|
||||
fun getAllChannel(channelId: Long): List<SubscriptionData> {
|
||||
val dataList = mutableListOf<SubscriptionData>()
|
||||
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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue