org.fuchss.matrix.bots.command.HelpCommand.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of matrix-bot-base Show documentation
Show all versions of matrix-bot-base Show documentation
Base project for matrix bots
package org.fuchss.matrix.bots.command
import net.folivo.trixnity.core.model.EventId
import net.folivo.trixnity.core.model.RoomId
import net.folivo.trixnity.core.model.UserId
import net.folivo.trixnity.core.model.events.m.room.RoomMessageEventContent
import org.fuchss.matrix.bots.IConfig
import org.fuchss.matrix.bots.MatrixBot
import org.fuchss.matrix.bots.markdown
class HelpCommand(
private val config: IConfig,
private val botName: String,
private val commandGetter: () -> List
) : Command() {
override val name: String = "help"
override val help: String = "shows this help message"
/**
* Show the help message.
* @param[matrixBot] The bot to show the help message.
* @param[sender] The sender of the command.
* @param[roomId] The room to show the help message in.
* @param[parameters] The parameters of the command.
* @param[textEventId] The event of the command.
* @param[textEvent] The event of the command.
*/
override suspend fun execute(
matrixBot: MatrixBot,
sender: UserId,
roomId: RoomId,
parameters: String,
textEventId: EventId,
textEvent: RoomMessageEventContent.TextBased.Text
) {
var helpMessage = "This is $botName. You can use the following commands:\n"
for (command in commandGetter()) {
helpMessage += "\n* `!${config.prefix} ${command.name} ${command.params} - ${command.help}`"
}
matrixBot.room().sendMessage(roomId) { markdown(helpMessage) }
}
}