Skip to content

Commit

Permalink
refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
demidko committed Sep 23, 2024
1 parent 7c0b95e commit 719f2cb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import kotlin.time.toKotlinDuration
open class ApplicationFactory {
data class Config(
val botToken: String,
val storageId: Long,
val healingConstant: Long = 7,
val healingTimeZone: String = "Asia/Jerusalem",
val restrictionsDuration: Duration = ofMinutes(5)
Expand Down Expand Up @@ -47,7 +46,6 @@ open class ApplicationFactory {
open val glockBot by lazy {
GlockBot(
config.botToken,
fromId(config.storageId),
restrictions,
config.restrictionsDuration,
config.healingConstant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import java.time.Duration.ofSeconds

fun main(args: Array<String>) {
val glockBot = ApplicationFactory().glockBot
glockBot.startPollingAsync()
startLoopWithFixedRate(ofSeconds(2), glockBot::cleanTempMessages)
glockBot.startPolling()
}

private fun startLoopWithFixedRate(every: Duration, action: () -> Unit) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/com/github/demidko/glock/GlockBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.github.kotlintelegrambot.dispatcher.command
import com.github.kotlintelegrambot.dispatcher.handlers.HandleCommand
import com.github.kotlintelegrambot.dispatcher.handlers.HandleMessage
import com.github.kotlintelegrambot.dispatcher.message
import com.github.kotlintelegrambot.entities.ChatId
import com.github.kotlintelegrambot.entities.ChatId.Companion.fromId
import com.github.kotlintelegrambot.entities.ChatPermissions
import com.github.kotlintelegrambot.entities.Message
Expand All @@ -20,7 +19,6 @@ import java.util.concurrent.ConcurrentHashMap

class GlockBot(
apiKey: String,
storageId: ChatId,
private val restrictions: ChatPermissions,
private val restrictionsDuration: Duration,
private val healingConstant: Long,
Expand Down Expand Up @@ -54,8 +52,8 @@ class GlockBot(
forEachChat(ChatOps::cleanTempMessages)
}

fun startPollingAsync() {
startVirtualThread(bot::startPolling)
fun startPolling() {
bot.startPolling()
}

private fun getChatOps(chatId: Long): ChatOps {
Expand Down

0 comments on commit 719f2cb

Please sign in to comment.