@@ -8,6 +8,7 @@ import by.jprof.telegram.bot.pins.dao.PinDAO
8
8
import by.jprof.telegram.bot.pins.dto.Unpin
9
9
import by.jprof.telegram.bot.pins.model.Pin
10
10
import by.jprof.telegram.bot.pins.model.PinDuration
11
+ import by.jprof.telegram.bot.pins.model.PinRequest
11
12
import by.jprof.telegram.bot.pins.scheduler.UnpinScheduler
12
13
import by.jprof.telegram.bot.pins.utils.PinRequestFinder
13
14
import by.jprof.telegram.bot.pins.utils.beggar
@@ -16,13 +17,20 @@ import by.jprof.telegram.bot.pins.utils.negativeDuration
16
17
import by.jprof.telegram.bot.pins.utils.tooManyPinnedMessages
17
18
import by.jprof.telegram.bot.pins.utils.tooPositiveDuration
18
19
import by.jprof.telegram.bot.pins.utils.unrecognizedDuration
20
+ import by.jprof.telegram.bot.shop.payload.PinsPayload
21
+ import by.jprof.telegram.bot.shop.provider.ChatProviderTokens
19
22
import dev.inmo.tgbotapi.bot.RequestsExecutor
20
23
import dev.inmo.tgbotapi.extensions.api.chat.modify.pinChatMessage
24
+ import dev.inmo.tgbotapi.extensions.api.send.payments.sendInvoice
21
25
import dev.inmo.tgbotapi.extensions.api.send.reply
22
26
import dev.inmo.tgbotapi.types.message.MarkdownV2
27
+ import dev.inmo.tgbotapi.types.payments.LabeledPrice
23
28
import dev.inmo.tgbotapi.types.update.abstracts.Update
24
29
import dev.inmo.tgbotapi.utils.PreviewFeature
25
30
import java.time.Duration
31
+ import kotlin.random.Random
32
+ import kotlinx.serialization.encodeToString
33
+ import kotlinx.serialization.json.Json
26
34
import org.apache.logging.log4j.LogManager
27
35
28
36
@PreviewFeature
@@ -31,6 +39,8 @@ class PinCommandUpdateProcessor(
31
39
private val pinDAO : PinDAO ,
32
40
private val unpinScheduler : UnpinScheduler ,
33
41
private val bot : RequestsExecutor ,
42
+ private val providerTokens : ChatProviderTokens ,
43
+ private val json : Json ,
34
44
private val pinRequestFinder : PinRequestFinder = PinRequestFinder .DEFAULT
35
45
) : UpdateProcessor {
36
46
companion object {
@@ -47,6 +57,7 @@ class PinCommandUpdateProcessor(
47
57
48
58
if (pin.message == null ) {
49
59
bot.reply(to = pin.request, text = help(pins), parseMode = MarkdownV2 )
60
+ pinsShop(pin)
50
61
51
62
return
52
63
}
@@ -71,6 +82,7 @@ class PinCommandUpdateProcessor(
71
82
72
83
if (pins < pin.price) {
73
84
bot.reply(to = pin.request, text = beggar(pins, pin.price), parseMode = MarkdownV2 )
85
+ pinsShop(pin)
74
86
75
87
return
76
88
}
@@ -90,9 +102,36 @@ class PinCommandUpdateProcessor(
90
102
chatId = pin.chat.id.chatId
91
103
ttl = duration.duration.seconds
92
104
})
105
+ if (Random .nextInt(4 ) == 0 ) {
106
+ pinsShop(pin)
107
+ }
93
108
} catch (e: Exception ) {
94
109
logger.error(" Failed to pin a message" , e)
95
110
}
96
111
}
97
112
}
113
+
114
+ private suspend fun pinsShop (pin : PinRequest ) {
115
+ val chatProviderToken = providerTokens[pin.request.chat.id.chatId]
116
+
117
+ if (chatProviderToken != null ) {
118
+ bot.sendInvoice(
119
+ chatId = pin.request.chat.id,
120
+ title = " 168 пинов" ,
121
+ description = " Неделя закрепа" ,
122
+ payload = json.encodeToString(PinsPayload (
123
+ pins = 168 ,
124
+ chat = pin.request.chat.id.chatId,
125
+ )),
126
+ providerToken = chatProviderToken,
127
+ currency = " USD" ,
128
+ prices = listOf (
129
+ LabeledPrice (" Пины × 168" , 200 )
130
+ ),
131
+ startParameter = " forwarded_payment" ,
132
+ replyToMessageId = pin.request.messageId,
133
+ allowSendingWithoutReply = true ,
134
+ )
135
+ }
136
+ }
98
137
}
0 commit comments