move main function to kagebot class

This commit is contained in:
kageru 2019-06-15 12:55:47 +02:00
parent cefadba58f
commit d6d45f8df6
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
3 changed files with 34 additions and 37 deletions

View File

@ -10,7 +10,7 @@ sourceSets {
sourceSets["main"].resources.srcDir("src/main/resources") sourceSets["main"].resources.srcDir("src/main/resources")
application { application {
mainClassName = "moe.kageru.kagebot.MainKt" mainClassName = "moe.kageru.kagebot.KagebotKt"
} }
group = "moe.kageru.kagebot" group = "moe.kageru.kagebot"

View File

@ -9,40 +9,44 @@ import org.javacord.api.event.message.MessageCreateEvent
import org.javacord.api.event.server.member.ServerMemberJoinEvent import org.javacord.api.event.server.member.ServerMemberJoinEvent
import java.io.File import java.io.File
class Kagebot { fun main() {
companion object { Kagebot.init()
fun processMessage(event: MessageCreateEvent) { }
if (event.messageAuthor.isBotUser) {
return
}
for (command in Globals.config.commands) {
if (command.matches(event.messageContent)) {
command.execute(event)
break
}
}
}
fun welcomeUser(event: ServerMemberJoinEvent) { object Kagebot {
Globals.config.features.welcome!!.let { welcome -> fun processMessage(event: MessageCreateEvent) {
val message = event.user.sendMessage(welcome.embed) if (event.messageAuthor.isBotUser) {
// If the user disabled direct messages, try the fallback (if defined) return
if (!Util.wasSuccessful(message) && }
welcome.fallbackChannel != null && for (command in Globals.config.commands) {
welcome.fallbackMessage != null if (command.matches(event.messageContent)) {
) { command.execute(event)
welcome.fallbackChannel.sendMessage( break
welcome.fallbackMessage.replace(
"@@",
MessageUtil.mention(event.user)
)
)
}
} }
} }
} }
init { fun welcomeUser(event: ServerMemberJoinEvent) {
Globals.config.features.welcome!!.let { welcome ->
val message = event.user.sendMessage(welcome.embed)
// If the user disabled direct messages, try the fallback (if defined)
if (!Util.wasSuccessful(message) &&
welcome.fallbackChannel != null &&
welcome.fallbackMessage != null
) {
welcome.fallbackChannel.sendMessage(
welcome.fallbackMessage.replace(
"@@",
MessageUtil.mention(event.user)
)
)
}
}
}
private fun getSecret() = File("secret").readText().replace("\n", "")
fun init() {
Globals.api = DiscordApiBuilder().setToken(getSecret()).login().join() Globals.api = DiscordApiBuilder().setToken(getSecret()).login().join()
try { try {
Globals.config = Config(RawConfig.read()) Globals.config = Config(RawConfig.read())
@ -64,6 +68,4 @@ class Kagebot {
} }
} }
} }
private fun getSecret() = File("secret").readText().replace("\n", "")
} }

View File

@ -1,5 +0,0 @@
package moe.kageru.kagebot
fun main() {
Kagebot()
}