|
| 1 | +package by.jprof.telegram.bot.english |
| 2 | + |
| 3 | +import by.jprof.telegram.bot.core.UpdateProcessor |
| 4 | +import by.jprof.telegram.bot.english.language_rooms.dao.LanguageRoomDAO |
| 5 | +import by.jprof.telegram.bot.english.language_rooms.model.Language |
| 6 | +import by.jprof.telegram.bot.english.language_rooms.model.Violence |
| 7 | +import dev.inmo.tgbotapi.bot.RequestsExecutor |
| 8 | +import dev.inmo.tgbotapi.extensions.api.send.media.sendAnimation |
| 9 | +import dev.inmo.tgbotapi.extensions.utils.asBaseMessageUpdate |
| 10 | +import dev.inmo.tgbotapi.extensions.utils.asContentMessage |
| 11 | +import dev.inmo.tgbotapi.extensions.utils.asTextContent |
| 12 | +import dev.inmo.tgbotapi.requests.abstracts.MultipartFile |
| 13 | +import dev.inmo.tgbotapi.types.update.abstracts.Update |
| 14 | +import io.ktor.utils.io.streams.asInput |
| 15 | +import org.apache.logging.log4j.LogManager |
| 16 | + |
| 17 | +class WhatWordUpdateProcessor( |
| 18 | + private val languageRoomDAO: LanguageRoomDAO, |
| 19 | + private val bot: RequestsExecutor, |
| 20 | +) : UpdateProcessor { |
| 21 | + companion object { |
| 22 | + private val logger = LogManager.getLogger(WhatWordUpdateProcessor::class.java)!! |
| 23 | + } |
| 24 | + |
| 25 | + override suspend fun process(update: Update) { |
| 26 | + val update = update.asBaseMessageUpdate() ?: return |
| 27 | + val roomId = update.data.chat.id |
| 28 | + val message = update.data.asContentMessage() ?: return |
| 29 | + val content = message.content.asTextContent() ?: return |
| 30 | + |
| 31 | + if ( |
| 32 | + languageRoomDAO.get(roomId.chatId, roomId.threadId)?.takeIf { it.language == Language.ENGLISH && it.violence == Violence.MOTHERFUCKER } == null |
| 33 | + ) { |
| 34 | + return |
| 35 | + } |
| 36 | + |
| 37 | + if (content.text.contains(Regex("w((ha)|(a)|(o)|(u))t\\?", RegexOption.IGNORE_CASE))) { |
| 38 | + bot.sendAnimation( |
| 39 | + chat = message.chat, |
| 40 | + animation = MultipartFile( |
| 41 | + filename = "say what again.gif", |
| 42 | + inputSource = { |
| 43 | + this::class.java.getResourceAsStream("/say what again.gif").asInput() |
| 44 | + }, |
| 45 | + ), |
| 46 | + replyToMessageId = message.messageId, |
| 47 | + ) |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments