package info.mechyrdia.lore
+import com.mongodb.client.model.Sorts
import info.mechyrdia.Configuration
+import info.mechyrdia.data.*
+import io.ktor.server.application.*
import io.ktor.util.*
+import kotlinx.coroutines.flow.filterNot
+import kotlinx.coroutines.flow.take
+import kotlinx.coroutines.flow.toList
import java.io.File
import java.time.Instant
import java.time.ZoneOffset
RssChannel(
title = "Recently Edited Factbooks | The Hour of Decision",
link = "https://mechyrdia.info",
- description = "A RSS news feed containing all factbooks in The Hour of Decision, in order of most recently edited.",
+ description = "An RSS feed containing all factbooks in The Hour of Decision, in order of most recently edited.",
pubDate = mostRecentChange,
lastBuildDate = mostRecentChange,
ttl = 30,
).toXml(this)
}
+suspend fun ApplicationCall.recentCommentsRssFeedGenerator(): Appendable.() -> Unit {
+ val currNation = currentNation()
+
+ val limit = request.queryParameters["limit"]?.toIntOrNull() ?: 10
+
+ val validLimits = 1..100
+
+ if (limit !in validLimits)
+ return RssChannel(
+ title = "Recent Comments - Error | The Hour of Decision",
+ link = "https://mechyrdia.info/comment/recent",
+ description = "Comment limit must be between ${validLimits.first} and ${validLimits.last}, got $limit",
+ pubDate = null,
+ lastBuildDate = Instant.now(),
+ ttl = 120,
+ )::toXml
+
+ val comments = CommentRenderData(
+ Comment.Table
+ .sorted(Sorts.descending(Comment::submittedAt.serialName))
+ .filterNot { comment ->
+ comment.submittedBy != currNation?.id && NationData.get(comment.submittedBy).isBanned
+ }
+ .take(limit)
+ .toList(),
+ nationCache
+ )
+
+ val mostRecentComment = comments.firstOrNull()?.submittedAt
+
+ return RssChannel(
+ title = "Recent Comments | The Hour of Decision",
+ link = "https://mechyrdia.info/comment/recent",
+ description = "An RSS feed containing the $limit most recently-submitted comments",
+ pubDate = mostRecentComment,
+ lastBuildDate = mostRecentComment,
+ ttl = 60,
+ categories = listOf(
+ RssCategory(domain = "https://nationstates.net", category = "Mechyrdia")
+ ),
+ items = comments.map { comment ->
+ RssItem(
+ title = "Comment by ${comment.submittedBy.name} on https://mechyrdia.info/lore/${comment.submittedIn}",
+ description = comment.contentsRaw.replace(INSIDE_TAG_TEXT, "").escapeHTML(),
+ link = "https://mechyrdia.info/comment/view/${comment.id}",
+ author = null,
+ comments = "https://mechyrdia.info/lore/${comment.submittedIn}#comments",
+ pubDate = comment.lastEdit ?: comment.submittedAt,
+ categories = listOf(
+ RssCategory(domain = "https://nationstates.net", category = comment.submittedBy.name)
+ )
+ )
+ }
+ )::toXml
+}
+
data class RssCategory(
val category: String,
val domain: String? = null