Skip to content

Commit 643d285

Browse files
committed
WIP
1 parent 94b6b98 commit 643d285

File tree

25 files changed

+246
-42
lines changed

25 files changed

+246
-42
lines changed

.deploy/lambda/lib/JProfByBotStack.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ export class JProfByBotStack extends cdk.Stack {
1515
constructor(scope: Construct, id: string, props: JProfByBotStackProps) {
1616
super(scope, id, props);
1717

18-
const secretPaymentProviderTokens = new secrets.Secret(this, 'jprof-by-bot-secret-payment-provider-tokens');
18+
const secretPaymentProviderTokens = new secrets.Secret(this, 'jprof-by-bot-secret-payment-provider-tokens', {
19+
secretName: 'jprof-by-bot-secret-payment-provider-tokens',
20+
secretObjectValue: {
21+
test: cdk.SecretValue.unsafePlainText('test'),
22+
production: cdk.SecretValue.unsafePlainText('production'),
23+
}
24+
});
1925

2026
const votesTable = new dynamodb.Table(this, 'jprof-by-bot-table-votes', {
2127
tableName: 'jprof-by-bot-table-votes',
@@ -107,7 +113,7 @@ export class JProfByBotStack extends cdk.Stack {
107113
code: lambda.Code.fromAsset('../../pins/unpin/build/libs/jprof_by_bot-pins-unpin-all.jar'),
108114
handler: 'by.jprof.telegram.bot.pins.unpin.Handler',
109115
environment: {
110-
'LOG_THRESHOLD': 'DEBUG',
116+
'LOG_THRESHOLD': 'INFO',
111117
'TABLE_PINS': pinsTable.tableName,
112118
'TOKEN_TELEGRAM_BOT': props.telegramToken,
113119
},
@@ -129,12 +135,12 @@ export class JProfByBotStack extends cdk.Stack {
129135
const layerLibGL = new lambda.LayerVersion(this, 'jprof-by-bot-lambda-layer-libGL', {
130136
layerVersionName: 'libGL',
131137
code: lambda.Code.fromAsset('layers/libGL.zip'),
132-
compatibleArchitectures: [Architecture.ARM_64],
138+
compatibleArchitectures: [Architecture.X86_64],
133139
});
134140
const layerLibfontconfig = new lambda.LayerVersion(this, 'jprof-by-bot-lambda-layer-libfontconfig', {
135141
layerVersionName: 'libfontconfig',
136142
code: lambda.Code.fromAsset('layers/libfontconfig.zip'),
137-
compatibleArchitectures: [Architecture.ARM_64],
143+
compatibleArchitectures: [Architecture.X86_64],
138144
});
139145
const layerParametersAndSecretsLambdaExtension = lambda.LayerVersion.fromLayerVersionArn(
140146
this,
@@ -158,7 +164,7 @@ export class JProfByBotStack extends cdk.Stack {
158164
code: lambda.Code.fromAsset('../../launchers/lambda/build/libs/jprof_by_bot-launchers-lambda-all.jar'),
159165
handler: 'by.jprof.telegram.bot.launchers.lambda.JProf',
160166
environment: {
161-
'LOG_THRESHOLD': 'DEBUG',
167+
'LOG_THRESHOLD': 'INFO',
162168
'TABLE_VOTES': votesTable.tableName,
163169
'TABLE_YOUTUBE_CHANNELS_WHITELIST': youtubeChannelsWhitelistTable.tableName,
164170
'TABLE_KOTLIN_MENTIONS': kotlinMentionsTable.tableName,
@@ -189,7 +195,7 @@ export class JProfByBotStack extends cdk.Stack {
189195
code: lambda.Code.fromAsset('../../english/urban-dictionary-daily/build/libs/jprof_by_bot-english-urban-dictionary-daily-all.jar'),
190196
handler: 'by.jprof.telegram.bot.english.urban_dictionary_daily.Handler',
191197
environment: {
192-
'LOG_THRESHOLD': 'DEBUG',
198+
'LOG_THRESHOLD': 'INFO',
193199
'TABLE_URBAN_WORDS_OF_THE_DAY': urbanWordsOfTheDayTable.tableName,
194200
'TABLE_LANGUAGE_ROOMS': languageRoomsTable.tableName,
195201
'TOKEN_TELEGRAM_BOT': props.telegramToken,

core/src/main/kotlin/by/jprof/telegram/bot/core/UpdateProcessingPipeline.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class UpdateProcessingPipeline(
2323
processors
2424
.map {
2525
launch(exceptionHandler(it)) {
26-
logger.debug("Processing update with ${it::class.simpleName}")
26+
logger.trace("Processing update with ${it::class.simpleName}")
2727
it.process(update)
2828
}
2929
}

deploy.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
source .env &&
4+
./gradlew clean shadowJar &&
5+
pushd .deploy/lambda &&
6+
npm install &&
7+
cdk deploy --outputs-file=cdk.out/outputs.json --require-approval=never &&
8+
popd

kotlin/src/main/kotlin/by/jprof/telegram/bot/kotlin/KotlinMentionsUpdateProcessor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class KotlinMentionsUpdateProcessor(
5050
else -> return
5151
}
5252

53-
logger.info("Kotlin mentioned!")
53+
logger.debug("Kotlin mentioned!")
5454

5555
val now = Instant.now()
5656
val user = (message as? FromUserMessage)?.user ?: return
@@ -128,6 +128,6 @@ class KotlinMentionsUpdateProcessor(
128128
replyToMessageId = message.messageId,
129129
)
130130

131-
logger.info("Kotlin mention reported!")
131+
logger.debug("Kotlin mention reported!")
132132
}
133133
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ class JProf : RequestHandler<APIGatewayV2HTTPEvent, APIGatewayV2HTTPResponse>, K
6666

6767
override fun handleRequest(input: APIGatewayV2HTTPEvent, context: Context): APIGatewayV2HTTPResponse {
6868
logger.debug("Incoming request: {}", input)
69+
logger.info(input.body)
6970

7071
val update = json.decodeFromString(UpdateDeserializationStrategy, input.body ?: return OK)
7172

72-
logger.debug("Parsed update: {}", update)
73+
logger.info("{}", update)
7374

7475
pipeline.process(update)
7576

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ val envModule = module {
4949
System.getenv(TIMEOUT)!!.toLong()
5050
}
5151

52-
single {
52+
single<ChatProviderTokens> {
5353
val json: Json = get()
5454
val secrets: SecretsManagerClient = get()
5555
val secret = secrets.getSecretValue {
5656
it.secretId(SECRET_PAYMENT_PROVIDER_TOKENS)
5757
}
5858

59-
json.decodeFromString<ChatProviderTokens>(secret.secretString())
59+
json.decodeFromString(secret.secretString())
6060
}
6161
}

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ import by.jprof.telegram.bot.quizoji.QuizojiStartCommandUpdateProcessor
2323
import by.jprof.telegram.bot.quizoji.QuizojiVoteUpdateProcessor
2424
import by.jprof.telegram.bot.shop.ForwardedPaymentStartCommandUpdateProcessor
2525
import by.jprof.telegram.bot.shop.PinsPreCheckoutQueryUpdateProcessor
26+
import by.jprof.telegram.bot.shop.PinsSuccessfulPaymentUpdateProcessor
2627
import by.jprof.telegram.bot.shop.RichCommandUpdateProcessor
2728
import by.jprof.telegram.bot.shop.RichPreCheckoutQueryUpdateProcessor
29+
import by.jprof.telegram.bot.shop.RichSuccessfulPaymentUpdateProcessor
2830
import by.jprof.telegram.bot.shop.SupportCommandUpdateProcessor
2931
import by.jprof.telegram.bot.shop.SupportPreCheckoutQueryUpdateProcessor
32+
import by.jprof.telegram.bot.shop.SupportSuccessfulPaymentUpdateProcessor
3033
import by.jprof.telegram.bot.times.TimeCommandUpdateProcessor
3134
import by.jprof.telegram.bot.times.TimeZoneCommandUpdateProcessor
3235
import by.jprof.telegram.bot.youtube.YouTubeUpdateProcessor
@@ -215,6 +218,13 @@ val pipelineModule = module {
215218
)
216219
}
217220

221+
single<UpdateProcessor>(named("RichSuccessfulPaymentUpdateProcessor")) {
222+
RichSuccessfulPaymentUpdateProcessor(
223+
bot = get(),
224+
json = get(),
225+
)
226+
}
227+
218228
single<UpdateProcessor>(named("SupportCommandUpdateProcessor")) {
219229
SupportCommandUpdateProcessor(
220230
bot = get(),
@@ -230,9 +240,10 @@ val pipelineModule = module {
230240
)
231241
}
232242

233-
single<UpdateProcessor>(named("ForwardedPaymentStartCommandUpdateProcessor")) {
234-
ForwardedPaymentStartCommandUpdateProcessor(
243+
single<UpdateProcessor>(named("SupportSuccessfulPaymentUpdateProcessor")) {
244+
SupportSuccessfulPaymentUpdateProcessor(
235245
bot = get(),
246+
json = get(),
236247
)
237248
}
238249

@@ -243,4 +254,18 @@ val pipelineModule = module {
243254
moniesDAO = get(),
244255
)
245256
}
257+
258+
single<UpdateProcessor>(named("PinsSuccessfulPaymentUpdateProcessor")) {
259+
PinsSuccessfulPaymentUpdateProcessor(
260+
bot = get(),
261+
json = get(),
262+
moniesDAO = get(),
263+
)
264+
}
265+
266+
single<UpdateProcessor>(named("ForwardedPaymentStartCommandUpdateProcessor")) {
267+
ForwardedPaymentStartCommandUpdateProcessor(
268+
bot = get(),
269+
)
270+
}
246271
}

pins/src/main/kotlin/by/jprof/telegram/bot/pins/PinCommandUpdateProcessor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import by.jprof.telegram.bot.pins.utils.negativeDuration
1717
import by.jprof.telegram.bot.pins.utils.tooManyPinnedMessages
1818
import by.jprof.telegram.bot.pins.utils.tooPositiveDuration
1919
import by.jprof.telegram.bot.pins.utils.unrecognizedDuration
20+
import by.jprof.telegram.bot.shop.payload.Payload
2021
import by.jprof.telegram.bot.shop.payload.PinsPayload
2122
import by.jprof.telegram.bot.shop.provider.ChatProviderTokens
2223
import dev.inmo.tgbotapi.bot.RequestsExecutor
@@ -49,7 +50,7 @@ class PinCommandUpdateProcessor(
4950

5051
override suspend fun process(update: Update) {
5152
pinRequestFinder(update)?.let { pin ->
52-
logger.info("Pin requested: {}", pin)
53+
logger.debug("Pin requested: {}", pin)
5354

5455
val monies = moniesDAO.get(pin.user.id.chatId, pin.chat.id.chatId) ?: Monies(pin.user.id.chatId, pin.chat.id.chatId)
5556
val pins = monies.pins ?: 0
@@ -119,7 +120,7 @@ class PinCommandUpdateProcessor(
119120
chatId = pin.request.chat.id,
120121
title = "168 пинов",
121122
description = "Неделя закрепа",
122-
payload = json.encodeToString(PinsPayload(
123+
payload = json.encodeToString<Payload>(PinsPayload(
123124
pins = 168,
124125
chat = pin.request.chat.id.chatId,
125126
)),

pins/src/main/kotlin/by/jprof/telegram/bot/pins/PinReplyUpdateProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PinReplyUpdateProcessor(
2828
return
2929
}
3030

31-
logger.info("{} replied to {}", replier, pin)
31+
logger.debug("{} replied to {}", replier, pin)
3232

3333
val monies = moniesDAO.get(pin.userId, replyTo.chat.id.chatId) ?: Monies(pin.userId, replyTo.chat.id.chatId)
3434

shop/payload/src/main/kotlin/by/jprof/telegram/bot/shop/payload/Payload.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package by.jprof.telegram.bot.shop.payload
33
import kotlinx.serialization.Serializable
44

55
@Serializable
6-
sealed class Payload
6+
sealed interface Payload

0 commit comments

Comments
 (0)