mirror of
https://github.com/pischule/memevizor.git
synced 2025-12-19 06:56:42 +00:00
Initial commit
This commit is contained in:
9
src/main/kotlin/com/pischule/memestv/BotProps.kt
Normal file
9
src/main/kotlin/com/pischule/memestv/BotProps.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.pischule.memestv
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
|
||||
@ConfigurationProperties("bot")
|
||||
data class BotProps(
|
||||
val token: String,
|
||||
val destinationChatId: Long,
|
||||
)
|
||||
66
src/main/kotlin/com/pischule/memestv/BotService.kt
Normal file
66
src/main/kotlin/com/pischule/memestv/BotService.kt
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.pischule.memestv
|
||||
|
||||
import com.github.kotlintelegrambot.Bot
|
||||
import com.github.kotlintelegrambot.bot
|
||||
import com.github.kotlintelegrambot.dispatch
|
||||
import com.github.kotlintelegrambot.dispatcher.photos
|
||||
import com.github.kotlintelegrambot.entities.ChatId
|
||||
import com.github.kotlintelegrambot.entities.reaction.ReactionType
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import jakarta.annotation.PostConstruct
|
||||
import jakarta.annotation.PreDestroy
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
val log = KotlinLogging.logger {}
|
||||
|
||||
@Profile("!test")
|
||||
@EnableConfigurationProperties(BotProps::class)
|
||||
@Service
|
||||
class BotService(val botProps: BotProps) {
|
||||
private lateinit var bot: Bot
|
||||
|
||||
@PostConstruct
|
||||
fun start() {
|
||||
bot = bot {
|
||||
token = botProps.token
|
||||
dispatch {
|
||||
photos {
|
||||
val message = this.message
|
||||
|
||||
bot.setMessageReaction(
|
||||
chatId = ChatId.fromId(message.chat.id),
|
||||
messageId = message.messageId,
|
||||
reaction = listOf(ReactionType.Emoji("👀"))
|
||||
)
|
||||
|
||||
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" }
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Thread {
|
||||
bot.startPolling()
|
||||
}.start()
|
||||
|
||||
log.info { "Initialized bot" }
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
fun stop() {
|
||||
bot.stopPolling()
|
||||
log.info { "Stopped bot" }
|
||||
}
|
||||
}
|
||||
12
src/main/kotlin/com/pischule/memestv/MemesTvApplication.kt
Normal file
12
src/main/kotlin/com/pischule/memestv/MemesTvApplication.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
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
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<MemesTvApplication>(*args)
|
||||
}
|
||||
2
src/main/resources/application-local.properties.dist
Normal file
2
src/main/resources/application-local.properties.dist
Normal file
@@ -0,0 +1,2 @@
|
||||
bot.destination-chat-id=<destination chat id>
|
||||
bot.token=<bot token>
|
||||
2
src/main/resources/application.properties
Normal file
2
src/main/resources/application.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
spring.application.name=memes-tv
|
||||
logging.structured.format.console=ecs
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.pischule.memestv
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.test.context.ActiveProfiles
|
||||
|
||||
@ActiveProfiles("test")
|
||||
@SpringBootTest
|
||||
class MemesTvApplicationTests {
|
||||
|
||||
@Test
|
||||
fun contextLoads() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user