mirror of
https://github.com/pischule/memevizor.git
synced 2025-12-19 06:56:42 +00:00
Format code
This commit is contained in:
@@ -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)
|
||||
@@ -47,12 +47,13 @@ class BotService(
|
||||
fileUploaderService.uploadFile(it)
|
||||
log.info { "Uploaded a file $maxResPhoto to s3" }
|
||||
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" }
|
||||
}
|
||||
chatId = ChatId.fromId(message.chat.id),
|
||||
messageId = message.messageId,
|
||||
reaction = listOf(ReactionType.Emoji("👍")),
|
||||
)
|
||||
.onError { error ->
|
||||
log.warn { "Failed to react to message: $error" }
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Error) {
|
||||
@@ -64,34 +65,27 @@ class BotService(
|
||||
|
||||
if (message.chat.id != botProps.destinationChatId) {
|
||||
bot.forwardMessage(
|
||||
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" }
|
||||
}
|
||||
)
|
||||
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" } },
|
||||
)
|
||||
}
|
||||
|
||||
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" }
|
||||
}
|
||||
|
||||
chatId = ChatId.fromId(message.chat.id),
|
||||
messageId = message.messageId,
|
||||
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" }
|
||||
}
|
||||
@@ -101,4 +95,4 @@ class BotService(
|
||||
bot.stopPolling()
|
||||
log.info { "Stopped 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{
|
||||
body = ByteStream.fromBytes(fileBytes)
|
||||
bucket = s3Props.bucket
|
||||
key = "_.jpeg"
|
||||
})
|
||||
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)
|
||||
|
||||
@@ -21,4 +21,4 @@ class S3Config {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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