mirror of
https://github.com/HMCore/Orbot.git
synced 2026-01-03 08:12:51 +00:00
Add more extensive fake update capabilities
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<BlogPostPreview>(BLOG_POST_STATE_FILE_NAME)
|
||||
fun fakeUpdateBlogPost(amount: Int = 1) = removeFromSiteSave<BlogPostPreview>(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<JobListingPreview>(JOB_LISTING_STATE_FILE_NAME)
|
||||
fun fakeUpdateJobListings(amount: Int = 1) = removeFromSiteSave<JobListingPreview>(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
|
||||
|
||||
@@ -11,10 +11,15 @@ import java.io.IOException
|
||||
/**
|
||||
* Removes the first element of a saved JSON list file
|
||||
*/
|
||||
inline fun <reified T>
|
||||
removeFirstFromSiteSave(fileName: String) = File(fileName).takeIf { it.exists() }?.let {
|
||||
it.writeText(Json.encodeToString(Json.decodeFromString<List<T>>(it.readText()).toMutableList().apply { removeFirst() }))
|
||||
}
|
||||
inline fun <reified T> removeFromSiteSave(fileName: String, amount: Int = 1) =
|
||||
File(fileName).takeIf { it.exists() }?.let {
|
||||
it.writeText(
|
||||
if (amount >= 0) Json.encodeToString(
|
||||
Json.decodeFromString<List<T>>(it.readText()).subList(0, amount)
|
||||
)
|
||||
else "[]"
|
||||
)
|
||||
}
|
||||
|
||||
inline fun <reified T> updateSite(url: String, fileName: String, parser: (Document) -> List<T>) = try {
|
||||
val currentStateFile = File(fileName)
|
||||
|
||||
Reference in New Issue
Block a user