mirror of
https://github.com/pischule/memevizor.git
synced 2025-12-19 06:56:42 +00:00
Format code
This commit is contained in:
@@ -4,3 +4,7 @@ java = "temurin-17"
|
||||
[tasks.release]
|
||||
description = 'Build and push docker image'
|
||||
run = './gradlew build && ./gradlew jib --image=cr.yandex/crph26nr2d2ds65t2m7b/memes-tv:0.0.1-SNAPSHOT'
|
||||
|
||||
[tasks.fmt]
|
||||
description = 'Fourmat source code'
|
||||
run = './gradlew :spotlessApply'
|
||||
@@ -4,6 +4,7 @@ plugins {
|
||||
id("org.springframework.boot") version "3.4.4"
|
||||
id("io.spring.dependency-management") version "1.1.7"
|
||||
id("com.google.cloud.tools.jib") version "3.4.5"
|
||||
id("com.diffplug.spotless") version "7.0.3"
|
||||
}
|
||||
|
||||
group = "com.pischule"
|
||||
@@ -48,3 +49,9 @@ kotlin {
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
spotless {
|
||||
kotlin {
|
||||
ktfmt("0.54").kotlinlangStyle()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,4 @@ package com.pischule.memestv
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
|
||||
@ConfigurationProperties("bot")
|
||||
data class BotProps(
|
||||
val token: String,
|
||||
val destinationChatId: Long,
|
||||
)
|
||||
@ConfigurationProperties("bot") data class BotProps(val token: String, val destinationChatId: Long)
|
||||
|
||||
@@ -33,12 +33,12 @@ class BotService(
|
||||
message {
|
||||
try {
|
||||
val chatId = message.chat.id
|
||||
val replyToPhotos = message.replyToMessage
|
||||
?.photo
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
if (chatId == botProps.destinationChatId
|
||||
&& message.text?.lowercase() == "this"
|
||||
&& replyToPhotos != null
|
||||
val replyToPhotos =
|
||||
message.replyToMessage?.photo?.takeIf { it.isNotEmpty() }
|
||||
if (
|
||||
chatId == botProps.destinationChatId &&
|
||||
message.text?.lowercase() == "this" &&
|
||||
replyToPhotos != null
|
||||
) {
|
||||
val maxResPhoto = replyToPhotos.last().fileId
|
||||
val fileBytes = bot.downloadFileBytes(maxResPhoto)
|
||||
@@ -49,8 +49,9 @@ class BotService(
|
||||
bot.setMessageReaction(
|
||||
chatId = ChatId.fromId(message.chat.id),
|
||||
messageId = message.messageId,
|
||||
reaction = listOf(ReactionType.Emoji("👍"))
|
||||
).onError { error ->
|
||||
reaction = listOf(ReactionType.Emoji("👍")),
|
||||
)
|
||||
.onError { error ->
|
||||
log.warn { "Failed to react to message: $error" }
|
||||
}
|
||||
}
|
||||
@@ -67,31 +68,24 @@ class BotService(
|
||||
chatId = ChatId.fromId(botProps.destinationChatId),
|
||||
fromChatId = ChatId.fromId(message.chat.id),
|
||||
messageId = message.messageId,
|
||||
).fold(
|
||||
{
|
||||
log.info { "Forwarded pictures message: $it" }
|
||||
},
|
||||
{
|
||||
log.error { "Failed to forward message: $it" }
|
||||
}
|
||||
)
|
||||
.fold(
|
||||
{ log.info { "Forwarded pictures message: $it" } },
|
||||
{ log.error { "Failed to forward message: $it" } },
|
||||
)
|
||||
}
|
||||
|
||||
bot.setMessageReaction(
|
||||
chatId = ChatId.fromId(message.chat.id),
|
||||
messageId = message.messageId,
|
||||
reaction = listOf(ReactionType.Emoji("👀"))
|
||||
).onError { error ->
|
||||
log.warn { "Failed to react to message: $error" }
|
||||
}
|
||||
|
||||
reaction = listOf(ReactionType.Emoji("👀")),
|
||||
)
|
||||
.onError { error -> log.warn { "Failed to react to message: $error" } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Thread {
|
||||
bot.startPolling()
|
||||
}.start()
|
||||
Thread { bot.startPolling() }.start()
|
||||
|
||||
log.info { "Initialized bot" }
|
||||
}
|
||||
|
||||
@@ -6,16 +6,15 @@ import aws.smithy.kotlin.runtime.content.ByteStream
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class FileUploaderService(
|
||||
private val s3Client: S3Client,
|
||||
private val s3Props: S3Props,
|
||||
) {
|
||||
class FileUploaderService(private val s3Client: S3Client, private val s3Props: S3Props) {
|
||||
|
||||
suspend fun uploadFile(fileBytes: ByteArray) {
|
||||
s3Client.putObject(PutObjectRequest{
|
||||
s3Client.putObject(
|
||||
PutObjectRequest {
|
||||
body = ByteStream.fromBytes(fileBytes)
|
||||
bucket = s3Props.bucket
|
||||
key = "_.jpeg"
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.pischule.memestv
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.boot.runApplication
|
||||
|
||||
@SpringBootApplication
|
||||
class MemesTvApplication
|
||||
@SpringBootApplication class MemesTvApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<MemesTvApplication>(*args)
|
||||
|
||||
@@ -3,8 +3,4 @@ package com.pischule.memestv
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
|
||||
@ConfigurationProperties("s3")
|
||||
data class S3Props(
|
||||
val accessKeyId: String,
|
||||
val secretAccessKey: String,
|
||||
val bucket: String,
|
||||
)
|
||||
data class S3Props(val accessKeyId: String, val secretAccessKey: String, val bucket: String)
|
||||
|
||||
@@ -10,7 +10,5 @@ import org.springframework.test.context.ActiveProfiles
|
||||
@SpringBootTest
|
||||
class MemesTvApplicationTests {
|
||||
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
@Test fun contextLoads() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user