Run ktLintFormat

This commit is contained in:
kraftwerk28 2021-07-04 14:58:19 +03:00
parent a115f6e8bd
commit 013a6b2f96
7 changed files with 39 additions and 32 deletions

View File

@ -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>("shadowJar") {
archiveFileName.set(
"spigot-tg-bridge-${spigotApiVersion}-v${pluginVersion}.jar"
"spigot-tg-bridge-$spigotApiVersion-v$pluginVersion.jar"
)
}
register<Copy>("copyArtifacts") {

View File

@ -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?

View File

@ -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<String, Any>?
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", "<i>%username%</i> left.")!!
logDeath = getBoolean("logPlayerDeath", false)
logPlayerAsleep = getBoolean("logPlayerAsleep", false)
commands = Commands(this)
commands = BotCommands(this)
}
}

View File

@ -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() {

View File

@ -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<T>(val ok: Boolean, val result: T?, val description: String?)

View File

@ -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<List<TgApiService.Update>>
>?
typealias UpdateRequest = Call<TgApiService.TgResponse<List<TgApiService.Update>>>?
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: <code>${chatId}</code>.
|Chat ID: <code>$chatId</code>.
|Copy this id to <code>chats</code> section in your <b>config.yml</b> file so it will look like this:
|
|<pre>chats:
| # other ids...
| - ${chatId}</pre>
| - $chatId</pre>
""".trimMargin()
api.sendMessage(chatId, text, replyToMessageId = msg.messageId)
}