Skip to content

Commit

Permalink
Who uses this?
Browse files Browse the repository at this point in the history
  • Loading branch information
demidko committed Jan 3, 2025
1 parent 48a4e43 commit 4c1df68
Showing 1 changed file with 46 additions and 29 deletions.
75 changes: 46 additions & 29 deletions src/main/kotlin/com/github/demidko/glock/GlockBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.github.kotlintelegrambot.entities.Chat
import com.github.kotlintelegrambot.entities.ChatId.Companion.fromId
import com.github.kotlintelegrambot.entities.ChatPermissions
import com.github.kotlintelegrambot.entities.Message
import com.github.kotlintelegrambot.entities.User
import java.lang.Thread.startVirtualThread
import java.time.Duration
import java.time.Duration.ofDays
Expand Down Expand Up @@ -46,7 +47,7 @@ class GlockBot(
message(handleMessage(ChatOps::tryProcessStatuette))
text {
if (message.chat.id != -1002388072333) {
println(text)
println("${format(message.chat)}${format(message.from)} - $text")
}
}
}
Expand All @@ -64,7 +65,7 @@ class GlockBot(

private fun getChatOps(chat: Chat): ChatOps {
return idToChatOps.computeIfAbsent(chat.id) {
display(chat)
println("I - detected new chat ${format(chat)}")
ChatOps(
bot,
fromId(chat.id),
Expand Down Expand Up @@ -115,34 +116,50 @@ class GlockBot(
}
}

private fun display(chat: Chat) {
val info =
buildString {
with(chat) {
append("new chat id ").append(id).append(' ')
if (firstName != null) {
append(firstName).append(' ')
}
if (lastName != null) {
append(lastName).append(' ')
}
if (username != null) {
append('@').append(username).append(' ')
}
if (inviteLink != null) {
append(inviteLink).append(' ')
}
if (bio != null) {
appendLine(bio).appendLine("***")
}
if (description != null) {
appendLine(description).appendLine("***")
}
if (pinnedMessage != null) {
appendLine(pinnedMessage).appendLine("***")
}
private fun format(user: User?): String {
if (user == null) {
return ""
}
return buildString {
with(user) {
append("id ").append(id).append(' ')
append(firstName).append(' ')
if (lastName != null) {
append(lastName).append(' ')
}
if (username != null) {
append('@').append(username).append(' ')
}
}
println(info)
}
}

private fun format(chat: Chat): String {
return buildString {
with(chat) {
append("id ").append(id).append(' ')
if (firstName != null) {
append(firstName).append(' ')
}
if (lastName != null) {
append(lastName).append(' ')
}
if (username != null) {
append('@').append(username).append(' ')
}
if (inviteLink != null) {
append(inviteLink).append(' ')
}
if (bio != null) {
append(bio).append(" - ")
}
if (description != null) {
append(description).append(" - ")
}
if (pinnedMessage != null) {
append(pinnedMessage).append(" - ")
}
}
}
}
}

0 comments on commit 4c1df68

Please sign in to comment.