From c76eeb3ecc8737b656e7871c1d6584cd2c49bfe6 Mon Sep 17 00:00:00 2001 From: Ruslan Ibragimov Date: Sat, 7 Nov 2020 14:25:32 +0300 Subject: [PATCH] Part of #3: Gather chat ids --- .../io/heapy/kotbot/bot/command/Commands.kt | 21 +++++++++++++++++++ .../kotlin/io/heapy/kotbot/Application.kt | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bot/src/main/kotlin/io/heapy/kotbot/bot/command/Commands.kt b/bot/src/main/kotlin/io/heapy/kotbot/bot/command/Commands.kt index d350843..18cdca2 100644 --- a/bot/src/main/kotlin/io/heapy/kotbot/bot/command/Commands.kt +++ b/bot/src/main/kotlin/io/heapy/kotbot/bot/command/Commands.kt @@ -72,3 +72,24 @@ class HelloWorldCommand( ) } } + +class ChatInfoCommand( + override val info: Info = INFO +) : Command { + override fun execute(update: Update, args: List): Flow { + return flowOf(ReplyAction( + chatId = update.message.chatId, + message = """ + Chat id: ${update.message.chatId} + """.trimIndent() + )) + } + + companion object { + private val INFO = CommandInfo( + name = "!chat-info", + context = Context.GROUP_CHAT, + access = Access.ADMIN + ) + } +} diff --git a/src/main/kotlin/io/heapy/kotbot/Application.kt b/src/main/kotlin/io/heapy/kotbot/Application.kt index 1c27004..5e77d13 100644 --- a/src/main/kotlin/io/heapy/kotbot/Application.kt +++ b/src/main/kotlin/io/heapy/kotbot/Application.kt @@ -4,6 +4,7 @@ import com.typesafe.config.ConfigFactory import io.github.config4k.extract import io.heapy.kotbot.bot.KotBot import io.heapy.kotbot.bot.command.HelloWorldCommand +import io.heapy.kotbot.bot.command.ChatInfoCommand import io.heapy.kotbot.bot.rule.CombotCasRule import io.heapy.kotbot.bot.rule.DeleteHelloRule import io.heapy.kotbot.bot.rule.DeleteJoinRule @@ -48,7 +49,8 @@ object Application { CombotCasRule(client, configuration.cas) ) val commands = listOf( - HelloWorldCommand() + HelloWorldCommand(), + ChatInfoCommand() ) startServer(