diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 185d141..24fd5d2 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,23 +4,13 @@
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
+
@@ -229,7 +219,7 @@
1597322033373
-
+
1597437833375
@@ -287,7 +277,28 @@
1622226400158
-
+
+ 1622232573135
+
+
+
+ 1622232573135
+
+
+ 1622232601071
+
+
+
+ 1622232601071
+
+
+ 1622232613740
+
+
+
+ 1622232613740
+
+
@@ -314,7 +325,9 @@
-
+
+
+
diff --git a/src/main/kotlin/de/wulkanat/AdminCli.kt b/src/main/kotlin/de/wulkanat/AdminCli.kt
index 9f78167..610e576 100644
--- a/src/main/kotlin/de/wulkanat/AdminCli.kt
+++ b/src/main/kotlin/de/wulkanat/AdminCli.kt
@@ -1,6 +1,7 @@
package de.wulkanat
import de.wulkanat.web.fakeUpdateBlogPost
+import de.wulkanat.web.fakeUpdateJobListings
import net.dv8tion.jda.api.hooks.ListenerAdapter
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent
@@ -23,13 +24,19 @@ class AdminCli : ListenerAdapter() {
when (command[0].value) {
"stop" -> exitProcess(1)
"fakeUpdate" -> {
- // TODO: implement fake update for blog posts
- // BLOG_POST_WATCHER.current = setOf()
- fakeUpdateBlogPost()
+ if (command.size < 2) {
+ Admin.println("Specify type")
+ } else {
+ val amount = command.getOrNull(2)?.value?.trim('`')?.toIntOrNull() ?: 1
+ when (command[1].value.trim('`')) {
+ "blog" -> fakeUpdateBlogPost(amount)
+ "twitter" -> TwitterJob.lastTweetID = "poggers"
+ "jobs" -> fakeUpdateJobListings(amount)
+ else -> Admin.println("Must be blog|twitter|jobs")
+ }
- TwitterJob.lastTweetID = "poggers"
-
- Admin.println("Posting on next update cycle.")
+ Admin.println("Posting $amount on next update cycle.")
+ }
}
"info" -> {
Admin.info()
@@ -66,7 +73,7 @@ class AdminCli : ListenerAdapter() {
"""
**${prefix}stop**
Stop the bot
- **${prefix}fakeUpdate**
+ **${prefix}fakeUpdate [blog|twitter|jobs] [amount]**
Post a fake update to every registered channel (can be used if bot missed the update)
**${prefix}info**
Show an overview over all registered channels
diff --git a/src/main/kotlin/de/wulkanat/web/Parser.kt b/src/main/kotlin/de/wulkanat/web/Parser.kt
index 6086163..ccbc02b 100644
--- a/src/main/kotlin/de/wulkanat/web/Parser.kt
+++ b/src/main/kotlin/de/wulkanat/web/Parser.kt
@@ -8,7 +8,7 @@ import de.wulkanat.model.BlogPostPreview
import de.wulkanat.model.JobListingPreview
private const val BLOG_POST_STATE_FILE_NAME = "blog_state.json"
-fun fakeUpdateBlogPost() = removeFirstFromSiteSave(BLOG_POST_STATE_FILE_NAME)
+fun fakeUpdateBlogPost(amount: Int = 1) = removeFromSiteSave(BLOG_POST_STATE_FILE_NAME, amount)
fun getNewBlogPosts() = updateSite("https://hytale.com/news", BLOG_POST_STATE_FILE_NAME) { doc ->
doc["postWrapper"].map {
BlogPostPreview(
@@ -23,7 +23,7 @@ fun getNewBlogPosts() = updateSite("https://hytale.com/news", BLOG_POST_STATE_FI
}
private const val JOB_LISTING_STATE_FILE_NAME = "jobs_state.json"
-fun fakeUpdateJobListings() = removeFirstFromSiteSave(JOB_LISTING_STATE_FILE_NAME)
+fun fakeUpdateJobListings(amount: Int = 1) = removeFromSiteSave(JOB_LISTING_STATE_FILE_NAME, amount)
fun getNewJobListings() = updateSite("https://hypixelstudios.com/jobs/", JOB_LISTING_STATE_FILE_NAME) { doc ->
doc["current-jobs__departments"].flatMap { jobDepartment ->
val jobDepartmentName = jobDepartment["current-jobs__department-name"].text
diff --git a/src/main/kotlin/de/wulkanat/web/SiteWatcher.kt b/src/main/kotlin/de/wulkanat/web/SiteWatcher.kt
index fe0ad2f..1584619 100644
--- a/src/main/kotlin/de/wulkanat/web/SiteWatcher.kt
+++ b/src/main/kotlin/de/wulkanat/web/SiteWatcher.kt
@@ -11,10 +11,15 @@ import java.io.IOException
/**
* Removes the first element of a saved JSON list file
*/
-inline fun
- removeFirstFromSiteSave(fileName: String) = File(fileName).takeIf { it.exists() }?.let {
- it.writeText(Json.encodeToString(Json.decodeFromString>(it.readText()).toMutableList().apply { removeFirst() }))
-}
+inline fun removeFromSiteSave(fileName: String, amount: Int = 1) =
+ File(fileName).takeIf { it.exists() }?.let {
+ it.writeText(
+ if (amount >= 0) Json.encodeToString(
+ Json.decodeFromString>(it.readText()).subList(0, amount)
+ )
+ else "[]"
+ )
+ }
inline fun updateSite(url: String, fileName: String, parser: (Document) -> List) = try {
val currentStateFile = File(fileName)