瀏覽代碼

Updated telegrambots library

Vadik Sirekanyan 4 年之前
父節點
當前提交
6c8301a661

+ 1 - 1
build.gradle.kts

@@ -18,7 +18,7 @@ repositories {
 }
 
 dependencies {
-    implementation("org.telegram:telegrambots:4.9.1")
+    implementation("org.telegram:telegrambots:5.3.0")
     implementation("io.ktor:ktor-client-cio:1.4.0")
     implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0")
     implementation("org.jetbrains.exposed:exposed-jdbc:0.28.1")

+ 1 - 1
src/main/kotlin/com/sirekanyan/andersrobot/AndersRobot.kt

@@ -15,7 +15,7 @@ import org.telegram.telegrambots.meta.generics.LongPollingBot
 import org.telegram.telegrambots.util.WebhookUtils
 
 val botName = Config[BOT_USERNAME]
-val adminId = Config[ADMIN_ID].toLong()
+val adminId = Config[ADMIN_ID]
 val delayedCommands = mutableMapOf<Long, Command>()
 private val primaryCommands: List<Command> =
     listOf(

+ 2 - 3
src/main/kotlin/com/sirekanyan/andersrobot/Main.kt

@@ -2,10 +2,9 @@
 
 package com.sirekanyan.andersrobot
 
-import org.telegram.telegrambots.ApiContextInitializer
 import org.telegram.telegrambots.meta.TelegramBotsApi
+import org.telegram.telegrambots.updatesreceivers.DefaultBotSession
 
 fun main() {
-    ApiContextInitializer.init()
-    TelegramBotsApi().registerBot(AndersRobot())
+    TelegramBotsApi(DefaultBotSession::class.java).registerBot(AndersRobot())
 }

+ 3 - 3
src/main/kotlin/com/sirekanyan/andersrobot/extensions/AbsSender.kt

@@ -12,13 +12,13 @@ import java.util.concurrent.ConcurrentHashMap
 private val cachedFileIds: MutableMap<File, String> = ConcurrentHashMap()
 
 fun AbsSender.sendText(chatId: Long, text: String): Message =
-    execute(SendMessage(chatId, text))
+    execute(SendMessage(chatId.toString(), text))
 
 fun AbsSender.sendPhoto(chatId: Long, file: File): Message =
-    execute(SendPhoto().setChatId(chatId).setPhoto(file))
+    execute(SendPhoto(chatId.toString(), InputFile(file)))
 
 fun AbsSender.sendSticker(chatId: Long, file: File) {
-    fun send(f: InputFile) = execute(SendSticker().setChatId(chatId).setSticker(f))
+    fun send(f: InputFile) = execute(SendSticker(chatId.toString(), f))
     val cachedFileId = cachedFileIds[file]
     if (cachedFileId == null) {
         println("sending file $file")

+ 1 - 1
src/main/kotlin/com/sirekanyan/andersrobot/extensions/Logger.kt

@@ -27,7 +27,7 @@ fun AbsSender.logError(update: Update) {
     try {
         val input = update.toString().byteInputStream()
         val document = InputFile(input, "update.txt")
-        execute(SendDocument().setChatId(adminId).setDocument(document))
+        execute(SendDocument(adminId, document))
     } catch (exception: Exception) {
         exception.printStackTrace()
     }