Add optional !welcome command for welcome feature (closes #7)
This commit is contained in:
parent
b08deb6e8d
commit
ac75239197
|
@ -78,5 +78,12 @@ object Kagebot {
|
|||
}
|
||||
}
|
||||
}
|
||||
Globals.config.features.welcome?.let { welcome ->
|
||||
if (welcome.commandEnabled) {
|
||||
Globals.api.addMessageCreateListener {
|
||||
welcome.handle(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ class RawWelcomeFeature(
|
|||
val enabled: Boolean,
|
||||
val content: Map<String, String>?,
|
||||
val fallbackChannel: String?,
|
||||
val fallbackMessage: String?
|
||||
val fallbackMessage: String?,
|
||||
@SerializedName("command") val commandEnabled: Boolean
|
||||
)
|
||||
class RawDebugFeatures(var enabled: Boolean)
|
|
@ -10,10 +10,10 @@ import java.lang.management.ManagementFactory
|
|||
import java.time.Duration
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
class DebugFeatures(rawDebugFeatures: RawDebugFeatures) {
|
||||
class DebugFeatures(rawDebugFeatures: RawDebugFeatures): MessageFeature() {
|
||||
val enabled: Boolean = rawDebugFeatures.enabled
|
||||
|
||||
fun handle(message: MessageCreateEvent) {
|
||||
override fun handleInternal(message: MessageCreateEvent) {
|
||||
if (message.messageAuthor.isBotOwner) {
|
||||
if (message.readableMessageContent.startsWith("!debugstats")) {
|
||||
message.channel.sendMessage(getPerformanceStats())
|
||||
|
@ -47,7 +47,7 @@ class DebugFeatures(rawDebugFeatures: RawDebugFeatures) {
|
|||
}
|
||||
|
||||
private fun getBotStats() = "kagebot has been running for ${getBotUptime()}.\n" +
|
||||
"During this time, ${Globals.commandCounter.incrementAndGet()} commands have been executed."
|
||||
"During this time, ${Globals.commandCounter.get()} commands have been executed."
|
||||
|
||||
private fun getBotUptime(): String {
|
||||
val uptime = Duration.of(ManagementFactory.getRuntimeMXBean().uptime, ChronoUnit.MILLIS)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package moe.kageru.kagebot.features
|
||||
|
||||
import moe.kageru.kagebot.Globals
|
||||
import org.javacord.api.event.message.MessageCreateEvent
|
||||
|
||||
abstract class MessageFeature {
|
||||
fun handle(message: MessageCreateEvent) {
|
||||
Globals.commandCounter.incrementAndGet()
|
||||
handleInternal(message)
|
||||
}
|
||||
|
||||
abstract fun handleInternal(message: MessageCreateEvent)
|
||||
}
|
|
@ -5,8 +5,15 @@ import moe.kageru.kagebot.Util
|
|||
import moe.kageru.kagebot.config.RawWelcomeFeature
|
||||
import org.javacord.api.entity.channel.TextChannel
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder
|
||||
import org.javacord.api.event.message.MessageCreateEvent
|
||||
|
||||
class WelcomeFeature(rawWelcome: RawWelcomeFeature) : MessageFeature() {
|
||||
override fun handleInternal(message: MessageCreateEvent) {
|
||||
if (message.readableMessageContent == "!welcome") {
|
||||
message.channel.sendMessage(embed)
|
||||
}
|
||||
}
|
||||
|
||||
class WelcomeFeature(rawWelcome: RawWelcomeFeature) {
|
||||
val enabled: Boolean = rawWelcome.enabled
|
||||
val embed: EmbedBuilder? by lazy {
|
||||
rawWelcome.content?.let(MessageUtil::mapToEmbed)
|
||||
|
@ -18,4 +25,5 @@ class WelcomeFeature(rawWelcome: RawWelcomeFeature) {
|
|||
Util.findChannel(it)
|
||||
}
|
||||
val fallbackMessage: String? = rawWelcome.fallbackMessage
|
||||
val commandEnabled: Boolean = rawWelcome.commandEnabled
|
||||
}
|
|
@ -14,6 +14,8 @@ messageDeleted = "Your message was deleted because it contained a banned word or
|
|||
# If no fallback channel or message is specified, no fallback will be sent.
|
||||
[feature.welcome]
|
||||
enabled = true
|
||||
# enable the !welcome command which will print the welcome embed
|
||||
command = true
|
||||
fallbackChannel = "555097559023222825"
|
||||
fallbackMessage = "@@ I would like to greet you, but I can’t. :("
|
||||
# This is a list of pairs where the key is the title and the value the content of the paragraph.
|
||||
|
|
Loading…
Reference in New Issue
Block a user