Add cli rework

This commit is contained in:
Wieland Schöbl
2021-06-02 21:31:41 +02:00
parent 4e2186026c
commit e773419986
7 changed files with 66 additions and 0 deletions

View File

@@ -23,6 +23,8 @@ dependencies {
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1'
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.2'
implementation 'com.github.redouane59.twitter:twittered:1.20'
implementation group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.2'

View File

@@ -1,5 +1,6 @@
package org.hmcore
import kotlinx.cli.ArgParser
import org.hmcore.web.fakeUpdateBlogPost
import org.hmcore.web.fakeUpdateJobListings
import net.dv8tion.jda.api.hooks.ListenerAdapter
@@ -12,6 +13,7 @@ class AdminCli : ListenerAdapter() {
val prefix = "!"
override fun onPrivateMessageReceived(event: PrivateMessageReceivedEvent) {
val msg = event.message.contentRaw
if (event.author.idLong != Admin.userId ||
!msg.startsWith(prefix)

View File

@@ -92,6 +92,9 @@ object Main {
getNewJobListings()?.forEach {
Channels.sentToAll(MessageBuilder().setEmbed(it.toMessageEmbed()).build(), MessageType.JOB_LISTING)
}
getNewJobListings()?.forEach {
}
}
val scheduler = StdSchedulerFactory.getDefaultScheduler()

View File

@@ -0,0 +1,4 @@
package org.hmcore.cli
class Commands {
}

View File

@@ -0,0 +1,29 @@
@file:OptIn(ExperimentalCli::class)
package org.hmcore.cli.admin
import kotlinx.cli.ArgType
import kotlinx.cli.ExperimentalCli
import kotlinx.cli.Subcommand
import kotlinx.cli.optional
import org.hmcore.TwitterJob
import org.hmcore.web.fakeUpdateBlogPost
import org.hmcore.web.fakeUpdateJobListings
class FakeUpdateCommand : Subcommand("fakeUpdate", "Cause a fake update. Use with great caution.") {
private val twitter by option(ArgType.Boolean,
"twitter",
"Cause a fake update for Twitter")
private val jobs by argument(ArgType.Int,
"jobs",
"Cause a fake update for Job Listings for the x amount of last jobs").optional()
private val blog by argument(ArgType.Int,
"blogs",
"Cause a fake update for Blogs for the x amount of last blogs").optional()
override fun execute() {
blog?.let { fakeUpdateBlogPost(it) }
jobs?.let { fakeUpdateJobListings(it) }
if (twitter == true) TwitterJob.lastTweetID = "empty"
}
}

View File

@@ -0,0 +1,13 @@
@file:OptIn(ExperimentalCli::class)
package org.hmcore.cli.admin
import kotlinx.cli.ExperimentalCli
import kotlinx.cli.Subcommand
import org.hmcore.Admin
class InfoCommand : Subcommand("info", "Print an overview of all servers") {
override fun execute() {
Admin.info()
}
}

View File

@@ -0,0 +1,13 @@
@file:OptIn(ExperimentalCli::class)
package org.hmcore.cli.admin
import kotlinx.cli.ExperimentalCli
import kotlinx.cli.Subcommand
import kotlin.system.exitProcess
class StopCommand : Subcommand("stop", "Stop the bot") {
override fun execute() {
exitProcess(1)
}
}