Make all log methods static
This commit is contained in:
parent
6069795caa
commit
c8123cca4e
|
@ -1,6 +1,5 @@
|
|||
package moe.kageru.kagebot
|
||||
|
||||
import moe.kageru.kagebot.Log.log
|
||||
import moe.kageru.kagebot.Util.checked
|
||||
import moe.kageru.kagebot.config.Config
|
||||
import moe.kageru.kagebot.config.ConfigParser
|
||||
|
@ -19,7 +18,7 @@ object Kagebot {
|
|||
fun processMessage(event: MessageCreateEvent) {
|
||||
if (event.messageAuthor.isBotUser) {
|
||||
if (event.messageAuthor.isYourself) {
|
||||
log.info("<Self> ${event.readableMessageContent}")
|
||||
Log.info("<Self> ${event.readableMessageContent}")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -60,10 +59,10 @@ object Kagebot {
|
|||
exitProcess(1)
|
||||
}
|
||||
Runtime.getRuntime().addShutdownHook(Thread {
|
||||
log.info("Bot has been interrupted. Shutting down.")
|
||||
Log.info("Bot has been interrupted. Shutting down.")
|
||||
Globals.api.disconnect()
|
||||
})
|
||||
log.info("kagebot Mk II running")
|
||||
Log.info("kagebot Mk II running")
|
||||
Globals.api.addMessageCreateListener { checked { processMessage(it) } }
|
||||
Config.features.welcome?.let {
|
||||
Globals.api.addServerMemberJoinListener {
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.logging.LogRecord
|
|||
import java.util.logging.Logger
|
||||
|
||||
object Log {
|
||||
val log: Logger by lazy {
|
||||
private val log: Logger by lazy {
|
||||
val log = Logger.getGlobal()
|
||||
val fh = FileHandler("kagebot.log", true)
|
||||
val formatter = LogFormatter()
|
||||
|
@ -16,6 +16,14 @@ object Log {
|
|||
log.addHandler(fh)
|
||||
return@lazy log
|
||||
}
|
||||
|
||||
fun info(message: String) {
|
||||
log.info(message)
|
||||
}
|
||||
|
||||
fun warn(message: String) {
|
||||
log.warning(message)
|
||||
}
|
||||
}
|
||||
|
||||
private class LogFormatter : Formatter() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package moe.kageru.kagebot
|
||||
|
||||
import moe.kageru.kagebot.Log.log
|
||||
import moe.kageru.kagebot.config.Config
|
||||
import moe.kageru.kagebot.config.Config.server
|
||||
import org.javacord.api.entity.channel.TextChannel
|
||||
|
@ -94,8 +93,9 @@ object Util {
|
|||
try {
|
||||
op()
|
||||
} catch (e: Exception) {
|
||||
log.warning("An uncaught exception occurred.\n$e")
|
||||
MessageUtil.sendEmbed(Globals.api.owner.get(),
|
||||
Log.warn("An uncaught exception occurred.\n$e")
|
||||
MessageUtil.sendEmbed(
|
||||
Globals.api.owner.get(),
|
||||
EmbedBuilder()
|
||||
.setTimestampToNow()
|
||||
.setColor(Color.RED)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package moe.kageru.kagebot.command
|
||||
|
||||
import moe.kageru.kagebot.Globals
|
||||
import moe.kageru.kagebot.Log.log
|
||||
import moe.kageru.kagebot.Log
|
||||
import moe.kageru.kagebot.MessageUtil
|
||||
import moe.kageru.kagebot.Util.doIf
|
||||
import moe.kageru.kagebot.config.Config
|
||||
|
@ -44,10 +44,10 @@ class Command(cmd: RawCommand) {
|
|||
if (Config.localization.permissionDenied.isNotBlank()) {
|
||||
message.channel.sendMessage(Config.localization.permissionDenied)
|
||||
}
|
||||
log.info("Denying command ${this.trigger} to user ${message.messageAuthor.discriminatedName} (ID: ${message.messageAuthor.id})")
|
||||
Log.info("Denying command ${this.trigger} to user ${message.messageAuthor.discriminatedName} (ID: ${message.messageAuthor.id})")
|
||||
return
|
||||
}
|
||||
log.info("Executing command ${this.trigger} triggered by user ${message.messageAuthor.discriminatedName} (ID: ${message.messageAuthor.id})")
|
||||
Log.info("Executing command ${this.trigger} triggered by user ${message.messageAuthor.discriminatedName} (ID: ${message.messageAuthor.id})")
|
||||
Globals.commandCounter.incrementAndGet()
|
||||
this.actions?.run(message, this)
|
||||
this.response?.let {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package moe.kageru.kagebot.command
|
||||
|
||||
import moe.kageru.kagebot.Log.log
|
||||
import moe.kageru.kagebot.Log
|
||||
import moe.kageru.kagebot.MessageUtil
|
||||
import moe.kageru.kagebot.config.Config
|
||||
import moe.kageru.kagebot.config.RawMessageActions
|
||||
|
@ -31,7 +31,7 @@ class MessageActions(rawActions: RawMessageActions) {
|
|||
)
|
||||
}
|
||||
} else {
|
||||
log.info("Tried to delete a message without the necessary permissions. Channel: ${message.channel.id}")
|
||||
Log.info("Tried to delete a message without the necessary permissions. Channel: ${message.channel.id}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package moe.kageru.kagebot.command
|
||||
|
||||
import moe.kageru.kagebot.Log.log
|
||||
import moe.kageru.kagebot.Log
|
||||
import moe.kageru.kagebot.MessageUtil
|
||||
import moe.kageru.kagebot.Util
|
||||
import moe.kageru.kagebot.config.Config
|
||||
|
@ -35,7 +35,7 @@ internal class MessageRedirect(rawRedirect: RawRedirect) {
|
|||
}
|
||||
|
||||
if (!Util.wasSuccessful(MessageUtil.sendEmbed(target, embed))) {
|
||||
log.warning("Could not redirect message to channel $target")
|
||||
Log.warn("Could not redirect message to channel $target")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package moe.kageru.kagebot.command
|
||||
|
||||
import moe.kageru.kagebot.Log.log
|
||||
import moe.kageru.kagebot.Log
|
||||
import moe.kageru.kagebot.Util
|
||||
import moe.kageru.kagebot.config.RawAssignment
|
||||
import org.javacord.api.event.message.MessageCreateEvent
|
||||
|
@ -12,6 +12,6 @@ internal class RoleAssignment(rawAssignment: RawAssignment) {
|
|||
|
||||
fun assign(message: MessageCreateEvent) {
|
||||
Util.userFromMessage(message)?.addRole(role, "Requested via command.")
|
||||
?: log.warning("Could not find user ${message.messageAuthor.name} for role assign")
|
||||
?: Log.warn("Could not find user ${message.messageAuthor.name} for role assign")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import moe.kageru.kagebot.MessageUtil
|
|||
import moe.kageru.kagebot.config.ConfigParser
|
||||
import moe.kageru.kagebot.config.RawConfig
|
||||
import org.javacord.api.event.message.MessageCreateEvent
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
class SetConfigFeature : MessageFeature() {
|
||||
@ExperimentalStdlibApi
|
||||
|
@ -26,7 +25,7 @@ class SetConfigFeature : MessageFeature() {
|
|||
"```$e: ${e.message}"
|
||||
)
|
||||
)
|
||||
Log.log.info("Could not parse new config: $e: ${e.message}")
|
||||
Log.info("Could not parse new config: $e: ${e.message}")
|
||||
return
|
||||
}
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue
Block a user