From 013a6b2f963ab56e9eaa9e9a0467e28316fb5038 Mon Sep 17 00:00:00 2001 From: kraftwerk28 Date: Sun, 4 Jul 2021 14:58:19 +0300 Subject: [PATCH] Run ktLintFormat --- build.gradle.kts | 8 ++--- .../spigot_tg_bridge/BotCommands.kt | 2 +- .../spigot_tg_bridge/CommandHandler.kt | 2 +- .../spigot_tg_bridge/Configuration.kt | 19 +++++++----- .../kraftwerk28/spigot_tg_bridge/Plugin.kt | 4 +-- .../{ApiService.kt => TgApiService.kt} | 6 ++-- .../org/kraftwerk28/spigot_tg_bridge/TgBot.kt | 30 +++++++++++-------- 7 files changed, 39 insertions(+), 32 deletions(-) rename src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/{ApiService.kt => TgApiService.kt} (95%) diff --git a/build.gradle.kts b/build.gradle.kts index 760e0a0..a80e99b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ -import org.yaml.snakeyaml.Yaml -import java.io.* import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.yaml.snakeyaml.Yaml +import java.io.File +import java.io.FileInputStream buildscript { repositories { @@ -58,7 +58,7 @@ defaultTasks("shadowJar") tasks { named("shadowJar") { archiveFileName.set( - "spigot-tg-bridge-${spigotApiVersion}-v${pluginVersion}.jar" + "spigot-tg-bridge-$spigotApiVersion-v$pluginVersion.jar" ) } register("copyArtifacts") { diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/BotCommands.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/BotCommands.kt index e3030b4..638c79e 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/BotCommands.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/BotCommands.kt @@ -2,7 +2,7 @@ package org.kraftwerk28.spigot_tg_bridge import org.bukkit.configuration.file.FileConfiguration -class Commands(cfg: FileConfiguration) { +class BotCommands(cfg: FileConfiguration) { val time: String? val online: String? val chatID: String? diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/CommandHandler.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/CommandHandler.kt index a0af498..a3d79ce 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/CommandHandler.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/CommandHandler.kt @@ -22,4 +22,4 @@ class CommandHandler(private val plugin: Plugin) : CommandExecutor { else -> false } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Configuration.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Configuration.kt index 8f08045..ddaad24 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Configuration.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Configuration.kt @@ -1,6 +1,5 @@ package org.kraftwerk28.spigot_tg_bridge -import org.bukkit.configuration.file.YamlConfiguration import java.io.File import org.kraftwerk28.spigot_tg_bridge.Constants as C @@ -26,10 +25,10 @@ class Configuration(plugin: Plugin) { val allowWebhook: Boolean val webhookConfig: Map? - var commands: Commands + var commands: BotCommands init { - val cfgFile = File(plugin.dataFolder, C.configFilename); + val cfgFile = File(plugin.dataFolder, C.configFilename) if (!cfgFile.exists()) { cfgFile.parentFile.mkdirs() plugin.saveDefaultConfig() @@ -40,20 +39,24 @@ class Configuration(plugin: Plugin) { pluginConfig.load(cfgFile) pluginConfig.getString("minecraftMessageFormat")?.let { - plugin.logger.warning(""" + plugin.logger.warning( + """ Config option "minecraftMessageFormat" is deprecated. Moved it to new key "telegramFormat" - """.trimIndent().replace('\n', ' ')) + """.trimIndent().replace('\n', ' ') + ) pluginConfig.set("telegramFormat", it) pluginConfig.set("minecraftMessageFormat", null) plugin.saveConfig() } pluginConfig.getString("telegramMessageFormat")?.let { - plugin.logger.warning(""" + plugin.logger.warning( + """ Config option "telegramMessageFormat" is deprecated. Moved it to new key "minecraftFormat" - """.trimIndent().replace('\n', ' ')) + """.trimIndent().replace('\n', ' ') + ) pluginConfig.set("minecraftFormat", it) pluginConfig.set("telegramMessageFormat", null) plugin.saveConfig() @@ -92,7 +95,7 @@ class Configuration(plugin: Plugin) { leaveString = getString("strings.left", "%username% left.")!! logDeath = getBoolean("logPlayerDeath", false) logPlayerAsleep = getBoolean("logPlayerAsleep", false) - commands = Commands(this) + commands = BotCommands(this) } } diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Plugin.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Plugin.kt index b6ccce9..7e16833 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Plugin.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Plugin.kt @@ -1,8 +1,7 @@ package org.kraftwerk28.spigot_tg_bridge -import com.vdurmont.emoji.EmojiParser -import org.bukkit.plugin.java.JavaPlugin import org.bukkit.event.HandlerList +import org.bukkit.plugin.java.JavaPlugin import java.lang.Exception import org.kraftwerk28.spigot_tg_bridge.Constants as C @@ -33,7 +32,6 @@ class Plugin : JavaPlugin() { tgBot?.sendMessageToTelegram(message) } } - } override fun onDisable() { diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/ApiService.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgApiService.kt similarity index 95% rename from src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/ApiService.kt rename to src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgApiService.kt index fd06cef..7a3aaf1 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/ApiService.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgApiService.kt @@ -1,8 +1,10 @@ package org.kraftwerk28.spigot_tg_bridge +import retrofit2.http.Body +import retrofit2.http.GET +import retrofit2.http.POST +import retrofit2.http.Query import com.google.gson.annotations.SerializedName as Name -import retrofit2.Call -import retrofit2.http.* interface TgApiService { data class TgResponse(val ok: Boolean, val result: T?, val description: String?) diff --git a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt index 427ec86..66951cc 100644 --- a/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt +++ b/src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/TgBot.kt @@ -1,18 +1,20 @@ package org.kraftwerk28.spigot_tg_bridge -import org.kraftwerk28.spigot_tg_bridge.Constants as C -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.* +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import okhttp3.OkHttpClient -import okhttp3.logging.HttpLoggingInterceptor -import retrofit2.Retrofit import retrofit2.Call +import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import java.time.Duration +import org.kraftwerk28.spigot_tg_bridge.Constants as C -typealias UpdateRequest = Call< - TgApiService.TgResponse> ->? +typealias UpdateRequest = Call>>? class TgBot( private val plugin: Plugin, @@ -40,7 +42,7 @@ class TgBot( client = OkHttpClient .Builder() .readTimeout(Duration.ZERO) - .build(); + .build() api = Retrofit.Builder() .baseUrl("https://api.telegram.org/bot${config.botToken}/") @@ -55,9 +57,11 @@ class TgBot( // since bot is only used in group chats commandRegex = """^\/(\w+)(?:@${me.username})$""".toRegex() val commands = config.commands.run { listOf(time, online, chatID) } - .zip(C.COMMAND_DESC.run { + .zip( + C.COMMAND_DESC.run { listOf(timeDesc, onlineDesc, chatIDDesc) - }) + } + ) .map { TgApiService.BotCommand(it.first!!, it.second) } .let { TgApiService.SetMyCommands(it) } @@ -174,12 +178,12 @@ class TgBot( val msg = update.message!! val chatId = msg.chat.id val text = """ - |Chat ID: ${chatId}. + |Chat ID: $chatId. |Copy this id to chats section in your config.yml file so it will look like this: | |
chats:
         |  # other ids...
-        |  - ${chatId}
+ | - $chatId """.trimMargin() api.sendMessage(chatId, text, replyToMessageId = msg.messageId) }