From 90e4d10341d2bed60c0533c3864ff1e1f511395b Mon Sep 17 00:00:00 2001 From: Daniil Demidko Date: Fri, 27 Sep 2024 09:52:06 +0600 Subject: [PATCH] Revert "analysis module" This reverts commit aa1e7c9cbb3c1cf6c0d9450fd336514d513c87bd. --- .../demidko/glock/ApplicationFactory.kt | 11 +--- .../com/github/demidko/glock/GlockBot.kt | 11 +--- .../com/github/demidko/glock/SpyModule.kt | 59 ------------------- 3 files changed, 6 insertions(+), 75 deletions(-) delete mode 100644 src/main/kotlin/com/github/demidko/glock/SpyModule.kt diff --git a/src/main/kotlin/com/github/demidko/glock/ApplicationFactory.kt b/src/main/kotlin/com/github/demidko/glock/ApplicationFactory.kt index c5a1e95..dddc31e 100644 --- a/src/main/kotlin/com/github/demidko/glock/ApplicationFactory.kt +++ b/src/main/kotlin/com/github/demidko/glock/ApplicationFactory.kt @@ -1,5 +1,6 @@ package com.github.demidko.glock +import com.github.kotlintelegrambot.entities.ChatId.Companion.fromId import com.github.kotlintelegrambot.entities.ChatPermissions import com.sksamuel.hoplite.ConfigLoaderBuilder import com.sksamuel.hoplite.ExperimentalHoplite @@ -12,10 +13,9 @@ import kotlin.time.toKotlinDuration open class ApplicationFactory { data class Config( val botToken: String, - val excludedChatsUsernames: Set, val healingConstant: Long = 7, val healingTimeZone: String = "Asia/Jerusalem", - val restrictionsDuration: Duration = ofMinutes(5), + val restrictionsDuration: Duration = ofMinutes(5) ) @OptIn(ExperimentalHoplite::class) @@ -43,18 +43,13 @@ open class ApplicationFactory { canPinMessages = false ) - open val spyModule by lazy { - SpyModule(config.excludedChatsUsernames) - } - open val glockBot by lazy { GlockBot( config.botToken, restrictions, config.restrictionsDuration, config.healingConstant, - ZoneId.of(config.healingTimeZone), - spyModule + ZoneId.of(config.healingTimeZone) ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/github/demidko/glock/GlockBot.kt b/src/main/kotlin/com/github/demidko/glock/GlockBot.kt index 8c3df86..7c60d39 100644 --- a/src/main/kotlin/com/github/demidko/glock/GlockBot.kt +++ b/src/main/kotlin/com/github/demidko/glock/GlockBot.kt @@ -9,6 +9,7 @@ import com.github.kotlintelegrambot.dispatcher.message import com.github.kotlintelegrambot.entities.ChatId.Companion.fromId import com.github.kotlintelegrambot.entities.ChatPermissions import com.github.kotlintelegrambot.entities.Message +import java.io.Closeable import java.lang.Thread.startVirtualThread import java.time.Duration import java.time.Duration.ofDays @@ -21,8 +22,7 @@ class GlockBot( private val restrictions: ChatPermissions, private val restrictionsDuration: Duration, private val healingConstant: Long, - private val healingTimeZone: ZoneId, - private val spyModule: SpyModule + private val healingTimeZone: ZoneId ) { init { @@ -43,11 +43,6 @@ class GlockBot( command("help", handleCommand(ChatOps::help)) command("start", handleCommand(ChatOps::help)) message(handleMessage(ChatOps::tryProcessStatuette)) - message { - startVirtualThread { - spyModule.spy(message) - } - } } } @@ -56,7 +51,7 @@ class GlockBot( private var previousChatsCount = 0 fun cleanTempMessages() { - if (idToChatOps.count() > previousChatsCount) { + if(idToChatOps.count() > previousChatsCount) { previousChatsCount = idToChatOps.count() println("Bot has $previousChatsCount chats") } diff --git a/src/main/kotlin/com/github/demidko/glock/SpyModule.kt b/src/main/kotlin/com/github/demidko/glock/SpyModule.kt deleted file mode 100644 index 23ca388..0000000 --- a/src/main/kotlin/com/github/demidko/glock/SpyModule.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.demidko.glock - -import com.github.kotlintelegrambot.entities.Chat -import com.github.kotlintelegrambot.entities.Message - -class SpyModule(private val excludedChatsUsernames: Set) { - - fun spy(m: Message) { - if (isExcludedChat(m)) { - return - } - println(m) - /*val user = readUser(m) - val chat = readChat(m) - val gist = readGist(m) - println("$user — $chat: $gist")*/ - } - - private fun isExcludedChat(m: Message): Boolean { - return m.chat.username in excludedChatsUsernames - } - - private fun readChat(m: Message): String { - return readChat(m.chat) - } - - private fun readChat(chat: Chat): String { - if (chat.username != null) { - return chat.username!! - } - if (chat.inviteLink != null) { - return chat.inviteLink!! - } - if (chat.location != null) { - val location = chat.location!! - return "${location.location} ${location.address}" - } - return buildString { - append("Group id ") - append(chat.id) - if (chat.firstName != null) { - append(' ') - append(chat.firstName) - } - if (chat.lastName != null) { - append(' ') - append(chat.lastName) - } - } - } - - private fun readUser(m: Message): String { - if (m.from == null) { - - } - m.senderChat - TODO() - } -} \ No newline at end of file