mirror of
https://github.com/HMCore/Orbot.git
synced 2025-12-12 13:56:18 +00:00
Add cli rework
This commit is contained in:
@@ -23,6 +23,8 @@ dependencies {
|
|||||||
implementation 'org.jsoup:jsoup:1.13.1'
|
implementation 'org.jsoup:jsoup:1.13.1'
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.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 'com.github.redouane59.twitter:twittered:1.20'
|
||||||
implementation group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.2'
|
implementation group: 'org.quartz-scheduler', name: 'quartz', version: '2.3.2'
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.hmcore
|
package org.hmcore
|
||||||
|
|
||||||
|
import kotlinx.cli.ArgParser
|
||||||
import org.hmcore.web.fakeUpdateBlogPost
|
import org.hmcore.web.fakeUpdateBlogPost
|
||||||
import org.hmcore.web.fakeUpdateJobListings
|
import org.hmcore.web.fakeUpdateJobListings
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
import net.dv8tion.jda.api.hooks.ListenerAdapter
|
||||||
@@ -12,6 +13,7 @@ class AdminCli : ListenerAdapter() {
|
|||||||
val prefix = "!"
|
val prefix = "!"
|
||||||
|
|
||||||
override fun onPrivateMessageReceived(event: PrivateMessageReceivedEvent) {
|
override fun onPrivateMessageReceived(event: PrivateMessageReceivedEvent) {
|
||||||
|
|
||||||
val msg = event.message.contentRaw
|
val msg = event.message.contentRaw
|
||||||
if (event.author.idLong != Admin.userId ||
|
if (event.author.idLong != Admin.userId ||
|
||||||
!msg.startsWith(prefix)
|
!msg.startsWith(prefix)
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ object Main {
|
|||||||
getNewJobListings()?.forEach {
|
getNewJobListings()?.forEach {
|
||||||
Channels.sentToAll(MessageBuilder().setEmbed(it.toMessageEmbed()).build(), MessageType.JOB_LISTING)
|
Channels.sentToAll(MessageBuilder().setEmbed(it.toMessageEmbed()).build(), MessageType.JOB_LISTING)
|
||||||
}
|
}
|
||||||
|
getNewJobListings()?.forEach {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val scheduler = StdSchedulerFactory.getDefaultScheduler()
|
val scheduler = StdSchedulerFactory.getDefaultScheduler()
|
||||||
|
|||||||
4
src/main/kotlin/org/hmcore/cli/Commands.kt
Normal file
4
src/main/kotlin/org/hmcore/cli/Commands.kt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package org.hmcore.cli
|
||||||
|
|
||||||
|
class Commands {
|
||||||
|
}
|
||||||
29
src/main/kotlin/org/hmcore/cli/admin/FakeUpdateCommand.kt
Normal file
29
src/main/kotlin/org/hmcore/cli/admin/FakeUpdateCommand.kt
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/main/kotlin/org/hmcore/cli/admin/InfoCommand.kt
Normal file
13
src/main/kotlin/org/hmcore/cli/admin/InfoCommand.kt
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/main/kotlin/org/hmcore/cli/admin/StopCommand.kt
Normal file
13
src/main/kotlin/org/hmcore/cli/admin/StopCommand.kt
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user