Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bir committed Oct 10, 2023
1 parent 3a3ad53 commit 7d8ab24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import kotlinx.coroutines.sync.withLock
import org.joda.time.DateTime
import kotlin.time.Duration.Companion.hours

/**
* This object stores one-time tokens for WS connections
* UI sends request to open socket with ?$token parameter
*/
object InboundSessionHandler {
private data class InboundConnection(val token: String, val expires: DateTime) {
constructor(token: String) : this(
Expand Down
12 changes: 11 additions & 1 deletion tele-rps-server/src/main/kotlin/com/polygon/tg/BotDispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.github.kotlintelegrambot.dispatcher.handlers.Handler
import com.github.kotlintelegrambot.dispatcher.text
import com.github.kotlintelegrambot.entities.ChatId
import com.github.kotlintelegrambot.entities.InlineKeyboardMarkup
import com.github.kotlintelegrambot.entities.ParseMode
import com.github.kotlintelegrambot.entities.Update
import com.github.kotlintelegrambot.entities.keyboard.InlineKeyboardButton
import com.polygon.ChallengeResult
Expand Down Expand Up @@ -64,6 +63,12 @@ val tgDispatcher: Dispatcher.() -> Unit = {
}
}

/**
* This handler executes when user clicks play?gameId button.
* It processes game status and sends according messages
* @param text - locale of current TG user
* @param result - results of the check of the game and ref to a game
*/
private fun CommandHandlerEnvironment.processChallengeResult(text: TextResolver, result: Pair<ChallengeResult, Game?>) {
when (result.first) {
ChallengeResult.SAME_PLAYER -> bot.sendMessage(
Expand Down Expand Up @@ -97,6 +102,11 @@ private fun CommandHandlerEnvironment.processChallengeResult(text: TextResolver,
}

typealias HandleCommandWithCtx = suspend CommandHandlerEnvironment.(userId: Long, text: TextResolver) -> Unit

/**
* This wrapper validates TG user id and passes it to underlying block along with user locale
* @param block function to execute with user context
*/
suspend fun CommandHandlerEnvironment.withValidUserId(block: HandleCommandWithCtx) {
update.consume()
if (message.from?.id == null) {
Expand Down

0 comments on commit 7d8ab24

Please sign in to comment.