Skip to content

Commit 2ee7c6f

Browse files
committed
What word update processor
1 parent d1ba7e3 commit 2ee7c6f

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

english/README.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ This is an umbrella feature for several smaller sub-features:
44

55
* The bot sends https://www.urbandictionary.com[Urban Word of the Day] into English rooms.
66
* The bot explains emphasised text parts in English rooms.
7+
* The bot tolerates no stupid questions.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}
374 KB
Loading

launchers/lambda/src/main/kotlin/by/jprof/telegram/bot/launchers/lambda/config/pipeline.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import by.jprof.telegram.bot.currencies.CurrenciesUpdateProcessor
66
import by.jprof.telegram.bot.english.EnglishCommandUpdateProcessor
77
import by.jprof.telegram.bot.english.ExplainerUpdateProcessor
88
import by.jprof.telegram.bot.english.UrbanWordOfTheDayUpdateProcessor
9+
import by.jprof.telegram.bot.english.WhatWordUpdateProcessor
910
import by.jprof.telegram.bot.eval.EvalUpdateProcessor
1011
import by.jprof.telegram.bot.jep.JEPUpdateProcessor
1112
import by.jprof.telegram.bot.jep.JsoupJEPSummary
@@ -175,4 +176,11 @@ val pipelineModule = module {
175176
bot = get(),
176177
)
177178
}
179+
180+
single<UpdateProcessor>(named("WhatWordUpdateProcessor")) {
181+
WhatWordUpdateProcessor(
182+
languageRoomDAO = get(),
183+
bot = get(),
184+
)
185+
}
178186
}

0 commit comments

Comments
 (0)