Skip to content

Commit b7c0b01

Browse files
committed
Add shop module
1 parent 5659445 commit b7c0b01

File tree

11 files changed

+185
-0
lines changed

11 files changed

+185
-0
lines changed

README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Official Telegram bot of Java Professionals BY community.
1212
* Converts some currencies to EUR and USD
1313
* Posts scheduled messages from this repo's `posts` branch
1414
* Expand LeetCode links
15+
* Tell users' local times
16+
* Sell pins and custom statuses 🤑
1517

1618
So, it just brings some fun and interactivity in our chat.
1719

launchers/lambda/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ dependencies {
2424
implementation(project.projects.leetcode)
2525
implementation(project.projects.times.timezones.dynamodb)
2626
implementation(project.projects.times)
27+
implementation(project.projects.shop)
2728
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import by.jprof.telegram.bot.quizoji.QuizojiOptionUpdateProcessor
1717
import by.jprof.telegram.bot.quizoji.QuizojiQuestionUpdateProcessor
1818
import by.jprof.telegram.bot.quizoji.QuizojiStartCommandUpdateProcessor
1919
import by.jprof.telegram.bot.quizoji.QuizojiVoteUpdateProcessor
20+
import by.jprof.telegram.bot.shop.PinsShopCommandUpdateProcessor
21+
import by.jprof.telegram.bot.shop.RichCommandUpdateProcessor
22+
import by.jprof.telegram.bot.shop.SupportCommandUpdateProcessor
23+
import by.jprof.telegram.bot.shop.TitleCommandUpdateProcessor
2024
import by.jprof.telegram.bot.times.TimeCommandUpdateProcessor
2125
import by.jprof.telegram.bot.times.TimeZoneCommandUpdateProcessor
2226
import by.jprof.telegram.bot.youtube.YouTubeUpdateProcessor
@@ -153,4 +157,28 @@ val pipelineModule = module {
153157
bot = get(),
154158
)
155159
}
160+
161+
single<UpdateProcessor>(named("PinsShopCommandUpdateProcessor")) {
162+
PinsShopCommandUpdateProcessor(
163+
bot = get(),
164+
)
165+
}
166+
167+
single<UpdateProcessor>(named("RichCommandUpdateProcessor")) {
168+
RichCommandUpdateProcessor(
169+
bot = get(),
170+
)
171+
}
172+
173+
single<UpdateProcessor>(named("TitleCommandUpdateProcessor")) {
174+
TitleCommandUpdateProcessor(
175+
bot = get(),
176+
)
177+
}
178+
179+
single<UpdateProcessor>(named("SupportCommandUpdateProcessor")) {
180+
SupportCommandUpdateProcessor(
181+
bot = get(),
182+
)
183+
}
156184
}

pins/src/main/kotlin/by/jprof/telegram/bot/pins/utils/messages.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package by.jprof.telegram.bot.pins.utils
33
import java.text.ChoiceFormat
44
import java.text.MessageFormat
55

6+
// TODO: Add a link to the `/pinshop` command here when it's ready
67
private val helpMessages = listOf(
78
"""Эту команду нужно вызывать реплаем на какое\-нибудь сообщение\.
89
|

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ include(":leetcode")
3535
include(":times:timezones")
3636
include(":times:timezones:dynamodb")
3737
include(":times")
38+
include(":shop")
3839
include(":launchers:lambda")

shop/README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= Shop
2+
3+
This feature allows users to buy link:../pins[pins] and custom titles.

shop/build.gradle.kts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
kotlin("jvm")
3+
}
4+
5+
dependencies {
6+
api(project.projects.core)
7+
api(libs.tgbotapi.core)
8+
implementation(libs.tgbotapi.extensions.api)
9+
implementation(libs.tgbotapi.extensions.utils)
10+
implementation(libs.log4j.api)
11+
12+
testImplementation(libs.junit.jupiter.api)
13+
testImplementation(libs.junit.jupiter.params)
14+
testImplementation(libs.mockk)
15+
testRuntimeOnly(libs.junit.jupiter.engine)
16+
testRuntimeOnly(libs.log4j.core)
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package by.jprof.telegram.bot.shop
2+
3+
import by.jprof.telegram.bot.core.UpdateProcessor
4+
import dev.inmo.tgbotapi.bot.RequestsExecutor
5+
import dev.inmo.tgbotapi.extensions.api.send.reply
6+
import dev.inmo.tgbotapi.extensions.utils.asBaseMessageUpdate
7+
import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource
8+
import dev.inmo.tgbotapi.extensions.utils.asContentMessage
9+
import dev.inmo.tgbotapi.extensions.utils.asTextContent
10+
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2ParseMode
11+
import dev.inmo.tgbotapi.types.update.abstracts.Update
12+
import dev.inmo.tgbotapi.utils.PreviewFeature
13+
14+
@OptIn(PreviewFeature::class)
15+
class PinsShopCommandUpdateProcessor(
16+
private val bot: RequestsExecutor,
17+
) : UpdateProcessor {
18+
override suspend fun process(update: Update) {
19+
@Suppress("NAME_SHADOWING") val update = update.asBaseMessageUpdate() ?: return
20+
val message = update.data.asContentMessage() ?: return
21+
val text = message.content.asTextContent() ?: return
22+
23+
if (text.textSources.mapNotNull { it.asBotCommandTextSource() }.none { it.command == "pinsshop" || it.command == "pinshop" }) {
24+
return
25+
}
26+
27+
val reply = """
28+
TODO: Sell pins
29+
""".trimIndent().trim()
30+
31+
bot.reply(to = message, text = reply, parseMode = MarkdownV2ParseMode)
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package by.jprof.telegram.bot.shop
2+
3+
import by.jprof.telegram.bot.core.UpdateProcessor
4+
import dev.inmo.tgbotapi.bot.RequestsExecutor
5+
import dev.inmo.tgbotapi.extensions.api.send.reply
6+
import dev.inmo.tgbotapi.extensions.utils.asBaseMessageUpdate
7+
import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource
8+
import dev.inmo.tgbotapi.extensions.utils.asContentMessage
9+
import dev.inmo.tgbotapi.extensions.utils.asTextContent
10+
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2ParseMode
11+
import dev.inmo.tgbotapi.types.update.abstracts.Update
12+
import dev.inmo.tgbotapi.utils.PreviewFeature
13+
14+
@OptIn(PreviewFeature::class)
15+
class RichCommandUpdateProcessor(
16+
private val bot: RequestsExecutor,
17+
) : UpdateProcessor {
18+
override suspend fun process(update: Update) {
19+
@Suppress("NAME_SHADOWING") val update = update.asBaseMessageUpdate() ?: return
20+
val message = update.data.asContentMessage() ?: return
21+
val text = message.content.asTextContent() ?: return
22+
23+
if (text.textSources.mapNotNull { it.asBotCommandTextSource() }.none { it.command == "rich" || it.command == "vip" }) {
24+
return
25+
}
26+
27+
val reply = """
28+
TODO: Sell "I AM RICH" \/ "V\.I\.P\." custom titles
29+
""".trimIndent().trim()
30+
31+
bot.reply(to = message, text = reply, parseMode = MarkdownV2ParseMode)
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package by.jprof.telegram.bot.shop
2+
3+
import by.jprof.telegram.bot.core.UpdateProcessor
4+
import dev.inmo.tgbotapi.bot.RequestsExecutor
5+
import dev.inmo.tgbotapi.extensions.api.send.reply
6+
import dev.inmo.tgbotapi.extensions.utils.asBaseMessageUpdate
7+
import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource
8+
import dev.inmo.tgbotapi.extensions.utils.asContentMessage
9+
import dev.inmo.tgbotapi.extensions.utils.asTextContent
10+
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2ParseMode
11+
import dev.inmo.tgbotapi.types.update.abstracts.Update
12+
import dev.inmo.tgbotapi.utils.PreviewFeature
13+
14+
@OptIn(PreviewFeature::class)
15+
class SupportCommandUpdateProcessor(
16+
private val bot: RequestsExecutor,
17+
) : UpdateProcessor {
18+
override suspend fun process(update: Update) {
19+
@Suppress("NAME_SHADOWING") val update = update.asBaseMessageUpdate() ?: return
20+
val message = update.data.asContentMessage() ?: return
21+
val text = message.content.asTextContent() ?: return
22+
23+
if (text.textSources.mapNotNull { it.asBotCommandTextSource() }.none { it.command == "support" }) {
24+
return
25+
}
26+
27+
val reply = """
28+
TODO: Sell "Supporter" custom title
29+
""".trimIndent().trim()
30+
31+
bot.reply(to = message, text = reply, parseMode = MarkdownV2ParseMode)
32+
}
33+
}

0 commit comments

Comments
 (0)