Skip to content

Commit 1815ce5

Browse files
author
Simon Naumov
committed
🐛 fixing clear command
1 parent da924c9 commit 1815ce5

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ flyway = { id = "org.flywaydb.flyway", version.ref = "flyway" }
1717

1818
kotlin-std = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version.ref = "kotlin" }
1919
kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlin" }
20-
kotlin-serialization = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version = "1.5.0" }
20+
kotlin-serialization = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-protobuf", version = "1.5.0" }
2121

2222
exposed-core = { group = "org.jetbrains.exposed", name = "exposed-core", version.ref = "exposed" }
2323
exposed-dao = { group = "org.jetbrains.exposed", name = "exposed-dao", version.ref = "exposed" }

src/main/kotlin/com/github/poolParty/pullPartyBot/handler/interaction/InitHandlers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ suspend fun Bot.initHandlers() {
3333
ListCommand(partyDaoImpl),
3434
PartyCommand(partyDaoImpl),
3535
DeleteCommand(partyDaoImpl),
36-
ClearCommand(chatDaoImpl),
36+
ClearCommand(),
3737
CreateCommand(partyDaoImpl),
3838
AliasCommand(partyDaoImpl),
3939
ChangeCommand(partyDaoImpl),

src/main/kotlin/com/github/poolParty/pullPartyBot/handler/interaction/callback/Callback.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import com.github.poolParty.pullPartyBot.database.dao.PartyDao
77
import com.github.poolParty.pullPartyBot.handler.interaction.Interaction
88
import kotlinx.serialization.Serializable
99
import kotlinx.serialization.SerializationException
10-
import kotlinx.serialization.decodeFromString
11-
import kotlinx.serialization.encodeToString
12-
import kotlinx.serialization.json.Json
10+
import kotlinx.serialization.protobuf.ProtoBuf
11+
import kotlinx.serialization.encodeToByteArray
12+
import kotlinx.serialization.decodeFromByteArray
1313
import mu.two.KotlinLogging
1414

1515
@Serializable
1616
sealed class Callback {
1717

1818
val encoded: String
19-
get() = Json.encodeToString(this)
19+
get() = ProtoBuf.encodeToByteArray(this).asSequence().map { it.toInt().toChar() }.joinToString("")
2020

2121
abstract suspend fun Bot.process(callbackQuery: CallbackQuery, partyDao: PartyDao, chatDao: ChatDao)
2222

2323
companion object {
2424
fun of(string: String) = try {
25-
Json.decodeFromString<Callback>(string)
25+
ProtoBuf.decodeFromByteArray<Callback>(string.map { it.code.toByte() }.toByteArray())
2626
} catch (e: SerializationException) {
2727
null
2828
}

src/main/kotlin/com/github/poolParty/pullPartyBot/handler/interaction/command/ClearCommand.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.poolParty.pullPartyBot.handler.interaction.command
33
import com.elbekd.bot.Bot
44
import com.elbekd.bot.types.Message
55
import com.github.poolParty.pullPartyBot.Configuration
6-
import com.github.poolParty.pullPartyBot.database.dao.ChatDao
76
import com.github.poolParty.pullPartyBot.handler.Button
87
import com.github.poolParty.pullPartyBot.handler.deleteMessageLogging
98
import com.github.poolParty.pullPartyBot.handler.interaction.callback.ClearConfirmationCallback
@@ -12,15 +11,15 @@ import com.github.poolParty.pullPartyBot.handler.message.HelpMessages
1211
import com.github.poolParty.pullPartyBot.handler.sendMessageLogging
1312
import kotlinx.coroutines.delay
1413

15-
class ClearCommand(private val chatDao: ChatDao) :
14+
class ClearCommand() :
1615
AdministratorCommand("clear", "shut down all the parties ever existed", HelpMessages.clear) {
1716

1817
override suspend fun Bot.administratorAction(message: Message, args: List<String>) {
1918
val chatId = message.chat.id
2019

2120
val sentMessage = sendMessageLogging(
2221
chatId,
23-
DeleteMessages.clearSuccess,
22+
DeleteMessages.clearConfirmation,
2423
buttons = listOf(
2524
Button("No, I changed my mind", ClearConfirmationCallback(chatId, message.from?.id, false)),
2625
Button("Yes, I am pretty sure", ClearConfirmationCallback(chatId, message.from?.id, true)),

src/main/kotlin/com/github/poolParty/pullPartyBot/handler/message/DeleteMessages.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ object DeleteMessages {
5151
"""
5252
Action is available for admins only. 🙅‍
5353
""".trimIndent()
54+
55+
val clearConfirmation =
56+
"""
57+
Are you completely sure you have an undeniable intention to proceed? 🤯
58+
""".trimIndent()
5459
}

0 commit comments

Comments
 (0)