mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-29 22:27:31 +00:00
refactor(bot): 按照 Kotlin 官方代码规范, 修正代码格式错误.
Kotlin 官方代码规范建议把 Companion object 放在类的最后面, 确实应该如此.
This commit is contained in:
parent
4bc3776717
commit
6df9f1b3c7
@ -34,6 +34,47 @@ internal class ScalaBot(
|
|||||||
) :
|
) :
|
||||||
AbilityBot(token, name, db, if (disableBuiltInAbility) BareboneToggle() else DefaultToggle(), options) {
|
AbilityBot(token, name, db, if (disableBuiltInAbility) BareboneToggle() else DefaultToggle(), options) {
|
||||||
|
|
||||||
|
private val extensionLoader = ExtensionLoader(this)
|
||||||
|
|
||||||
|
init {
|
||||||
|
val extensionEntries = extensionLoader.getExtensions()
|
||||||
|
for (entry in extensionEntries) {
|
||||||
|
addExtension(entry.extension)
|
||||||
|
log.debug {
|
||||||
|
"[Bot ${botUsername}] 扩展包 `${entry.extensionArtifact}` 中的扩展 `${entry.extension::class.qualifiedName}` " +
|
||||||
|
"(由工厂类 `${entry.factoryClass.name}` 创建) 已注册."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun creatorId(): Long = creatorId
|
||||||
|
|
||||||
|
override fun onUpdateReceived(update: Update?) {
|
||||||
|
botUpdateCounter.labels(botUsername).inc()
|
||||||
|
botUpdateGauge.labels(botUsername).inc()
|
||||||
|
|
||||||
|
val timer = updateProcessTime.labels(botUsername).startTimer()
|
||||||
|
try {
|
||||||
|
super.onUpdateReceived(update)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
exceptionHandlingCounter.labels(botUsername).inc()
|
||||||
|
throw e
|
||||||
|
} finally {
|
||||||
|
timer.observeDuration()
|
||||||
|
botUpdateGauge.labels(botUsername).dec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRegister() {
|
||||||
|
super.onRegister()
|
||||||
|
onlineBotGauge.inc()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onClosing() {
|
||||||
|
super.onClosing()
|
||||||
|
onlineBotGauge.dec()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
private val log = KotlinLogging.logger { }
|
private val log = KotlinLogging.logger { }
|
||||||
@ -83,45 +124,4 @@ internal class ScalaBot(
|
|||||||
.subsystem("telegrambots")
|
.subsystem("telegrambots")
|
||||||
.register()
|
.register()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val extensionLoader = ExtensionLoader(this)
|
|
||||||
|
|
||||||
init {
|
|
||||||
val extensionEntries = extensionLoader.getExtensions()
|
|
||||||
for (entry in extensionEntries) {
|
|
||||||
addExtension(entry.extension)
|
|
||||||
log.debug {
|
|
||||||
"[Bot ${botUsername}] 扩展包 `${entry.extensionArtifact}` 中的扩展 `${entry.extension::class.qualifiedName}` " +
|
|
||||||
"(由工厂类 `${entry.factoryClass.name}` 创建) 已注册."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun creatorId(): Long = creatorId
|
|
||||||
|
|
||||||
override fun onUpdateReceived(update: Update?) {
|
|
||||||
botUpdateCounter.labels(botUsername).inc()
|
|
||||||
botUpdateGauge.labels(botUsername).inc()
|
|
||||||
|
|
||||||
val timer = updateProcessTime.labels(botUsername).startTimer()
|
|
||||||
try {
|
|
||||||
super.onUpdateReceived(update)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
exceptionHandlingCounter.labels(botUsername).inc()
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
timer.observeDuration()
|
|
||||||
botUpdateGauge.labels(botUsername).dec()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onRegister() {
|
|
||||||
super.onRegister()
|
|
||||||
onlineBotGauge.inc()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClosing() {
|
|
||||||
super.onClosing()
|
|
||||||
onlineBotGauge.dec()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user