put bot initialization in separate file
This commit is contained in:
parent
24d43c4a7f
commit
da8b717831
|
@ -0,0 +1,30 @@
|
||||||
|
package moe.kageru.kagebot
|
||||||
|
|
||||||
|
import moe.kageru.kagebot.Config.Companion.config
|
||||||
|
import moe.kageru.kagebot.Log.log
|
||||||
|
import org.javacord.api.DiscordApiBuilder
|
||||||
|
import org.javacord.api.event.message.MessageCreateEvent
|
||||||
|
|
||||||
|
class Kagebot {
|
||||||
|
companion object {
|
||||||
|
fun processMessage(event: MessageCreateEvent) {
|
||||||
|
for (command in config.commands) {
|
||||||
|
if (command.matches(event.messageContent)) {
|
||||||
|
event.channel.sendMessage(command.respond(event.messageAuthor))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
val api = DiscordApiBuilder().setToken(Config.secret).login().join()
|
||||||
|
println(config.system.admins)
|
||||||
|
Runtime.getRuntime().addShutdownHook(Thread {
|
||||||
|
log.info("Bot has been interrupted. Shutting down.")
|
||||||
|
api.disconnect()
|
||||||
|
})
|
||||||
|
log.info("kagebot Mk II running")
|
||||||
|
api.addMessageCreateListener { processMessage(it) }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,33 +1,13 @@
|
||||||
package moe.kageru.kagebot
|
package moe.kageru.kagebot
|
||||||
|
|
||||||
import moe.kageru.kagebot.Config.Companion.config
|
|
||||||
import moe.kageru.kagebot.Log.log
|
import moe.kageru.kagebot.Log.log
|
||||||
import org.javacord.api.DiscordApiBuilder
|
|
||||||
import java.lang.System
|
import java.lang.System
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
try {
|
try {
|
||||||
createBot()
|
Kagebot()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
log.warning("An exception occurred in the main thread, exiting. ${e.stackTrace.joinToString("\n")}")
|
log.warning("An exception occurred in the main thread, exiting. ${e.stackTrace.joinToString("\n")}")
|
||||||
System.exit(1)
|
System.exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createBot() {
|
|
||||||
val api = DiscordApiBuilder().setToken(Config.secret).login().join()
|
|
||||||
println(config.system.admins)
|
|
||||||
Runtime.getRuntime().addShutdownHook(Thread {
|
|
||||||
log.info("Bot has been interrupted. Shutting down.")
|
|
||||||
api.disconnect()
|
|
||||||
})
|
|
||||||
log.info("kagebot Mk II running")
|
|
||||||
api.addMessageCreateListener { event ->
|
|
||||||
for (command in config.commands) {
|
|
||||||
if (command.matches(event.messageContent)) {
|
|
||||||
event.channel.sendMessage(command.respond(event.messageAuthor))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,6 +13,17 @@ trigger = "somewhere"
|
||||||
response = "found it"
|
response = "found it"
|
||||||
matchType = "CONTAINS"
|
matchType = "CONTAINS"
|
||||||
|
|
||||||
|
[[commands]]
|
||||||
|
trigger = "A.+B"
|
||||||
|
response = "regex matched"
|
||||||
|
matchType = "REGEX"
|
||||||
|
|
||||||
|
[[commands]]
|
||||||
|
trigger = "answer me"
|
||||||
|
# this will @mention the user who triggered the command,
|
||||||
|
# i.e. “@author there you go”
|
||||||
|
response = "@@ there you go"
|
||||||
|
|
||||||
[[commands]]
|
[[commands]]
|
||||||
trigger = "^[^`]*([()|DoOvVcC][-=^']?;|;[-=^']?[()|DoOpPvVcC3]|:wink:|😉)[^`]*$"
|
trigger = "^[^`]*([()|DoOvVcC][-=^']?;|;[-=^']?[()|DoOpPvVcC3]|:wink:|😉)[^`]*$"
|
||||||
response = "@@ Oboe!"
|
response = "@@ Oboe!"
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
package moe.kageru.kagebot
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
package moe.kageru.kagebot
|
||||||
|
|
Loading…
Reference in New Issue
Block a user