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 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 { buildscript {
repositories { repositories {
@ -58,7 +58,7 @@ defaultTasks("shadowJar")
tasks { tasks {
named<ShadowJar>("shadowJar") { named<ShadowJar>("shadowJar") {
archiveFileName.set( archiveFileName.set(
"spigot-tg-bridge-${spigotApiVersion}-v${pluginVersion}.jar" "spigot-tg-bridge-$spigotApiVersion-v$pluginVersion.jar"
) )
} }
register<Copy>("copyArtifacts") { register<Copy>("copyArtifacts") {

View File

@ -2,7 +2,7 @@ package org.kraftwerk28.spigot_tg_bridge
import org.bukkit.configuration.file.FileConfiguration import org.bukkit.configuration.file.FileConfiguration
class Commands(cfg: FileConfiguration) { class BotCommands(cfg: FileConfiguration) {
val time: String? val time: String?
val online: String? val online: String?
val chatID: String? val chatID: String?

View File

@ -22,4 +22,4 @@ class CommandHandler(private val plugin: Plugin) : CommandExecutor {
else -> false else -> false
} }
} }
} }

View File

@ -1,6 +1,5 @@
package org.kraftwerk28.spigot_tg_bridge package org.kraftwerk28.spigot_tg_bridge
import org.bukkit.configuration.file.YamlConfiguration
import java.io.File import java.io.File
import org.kraftwerk28.spigot_tg_bridge.Constants as C import org.kraftwerk28.spigot_tg_bridge.Constants as C
@ -26,10 +25,10 @@ class Configuration(plugin: Plugin) {
val allowWebhook: Boolean val allowWebhook: Boolean
val webhookConfig: Map<String, Any>? val webhookConfig: Map<String, Any>?
var commands: Commands var commands: BotCommands
init { init {
val cfgFile = File(plugin.dataFolder, C.configFilename); val cfgFile = File(plugin.dataFolder, C.configFilename)
if (!cfgFile.exists()) { if (!cfgFile.exists()) {
cfgFile.parentFile.mkdirs() cfgFile.parentFile.mkdirs()
plugin.saveDefaultConfig() plugin.saveDefaultConfig()
@ -40,20 +39,24 @@ class Configuration(plugin: Plugin) {
pluginConfig.load(cfgFile) pluginConfig.load(cfgFile)
pluginConfig.getString("minecraftMessageFormat")?.let { pluginConfig.getString("minecraftMessageFormat")?.let {
plugin.logger.warning(""" plugin.logger.warning(
"""
Config option "minecraftMessageFormat" is deprecated. Config option "minecraftMessageFormat" is deprecated.
Moved it to new key "telegramFormat" Moved it to new key "telegramFormat"
""".trimIndent().replace('\n', ' ')) """.trimIndent().replace('\n', ' ')
)
pluginConfig.set("telegramFormat", it) pluginConfig.set("telegramFormat", it)
pluginConfig.set("minecraftMessageFormat", null) pluginConfig.set("minecraftMessageFormat", null)
plugin.saveConfig() plugin.saveConfig()
} }
pluginConfig.getString("telegramMessageFormat")?.let { pluginConfig.getString("telegramMessageFormat")?.let {
plugin.logger.warning(""" plugin.logger.warning(
"""
Config option "telegramMessageFormat" is deprecated. Config option "telegramMessageFormat" is deprecated.
Moved it to new key "minecraftFormat" Moved it to new key "minecraftFormat"
""".trimIndent().replace('\n', ' ')) """.trimIndent().replace('\n', ' ')
)
pluginConfig.set("minecraftFormat", it) pluginConfig.set("minecraftFormat", it)
pluginConfig.set("telegramMessageFormat", null) pluginConfig.set("telegramMessageFormat", null)
plugin.saveConfig() plugin.saveConfig()
@ -92,7 +95,7 @@ class Configuration(plugin: Plugin) {
leaveString = getString("strings.left", "<i>%username%</i> left.")!! leaveString = getString("strings.left", "<i>%username%</i> left.")!!
logDeath = getBoolean("logPlayerDeath", false) logDeath = getBoolean("logPlayerDeath", false)
logPlayerAsleep = getBoolean("logPlayerAsleep", false) logPlayerAsleep = getBoolean("logPlayerAsleep", false)
commands = Commands(this) commands = BotCommands(this)
} }
} }

View File

@ -1,8 +1,7 @@
package org.kraftwerk28.spigot_tg_bridge 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.event.HandlerList
import org.bukkit.plugin.java.JavaPlugin
import java.lang.Exception import java.lang.Exception
import org.kraftwerk28.spigot_tg_bridge.Constants as C import org.kraftwerk28.spigot_tg_bridge.Constants as C
@ -33,7 +32,6 @@ class Plugin : JavaPlugin() {
tgBot?.sendMessageToTelegram(message) tgBot?.sendMessageToTelegram(message)
} }
} }
} }
override fun onDisable() { override fun onDisable() {

View File

@ -1,8 +1,10 @@
package org.kraftwerk28.spigot_tg_bridge 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 com.google.gson.annotations.SerializedName as Name
import retrofit2.Call
import retrofit2.http.*
interface TgApiService { interface TgApiService {
data class TgResponse<T>(val ok: Boolean, val result: T?, val description: String?) 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 package org.kraftwerk28.spigot_tg_bridge
import org.kraftwerk28.spigot_tg_bridge.Constants as C import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.* 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.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.Call import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
import java.time.Duration import java.time.Duration
import org.kraftwerk28.spigot_tg_bridge.Constants as C
typealias UpdateRequest = Call< typealias UpdateRequest = Call<TgApiService.TgResponse<List<TgApiService.Update>>>?
TgApiService.TgResponse<List<TgApiService.Update>>
>?
class TgBot( class TgBot(
private val plugin: Plugin, private val plugin: Plugin,
@ -40,7 +42,7 @@ class TgBot(
client = OkHttpClient client = OkHttpClient
.Builder() .Builder()
.readTimeout(Duration.ZERO) .readTimeout(Duration.ZERO)
.build(); .build()
api = Retrofit.Builder() api = Retrofit.Builder()
.baseUrl("https://api.telegram.org/bot${config.botToken}/") .baseUrl("https://api.telegram.org/bot${config.botToken}/")
@ -55,9 +57,11 @@ class TgBot(
// since bot is only used in group chats // since bot is only used in group chats
commandRegex = """^\/(\w+)(?:@${me.username})$""".toRegex() commandRegex = """^\/(\w+)(?:@${me.username})$""".toRegex()
val commands = config.commands.run { listOf(time, online, chatID) } val commands = config.commands.run { listOf(time, online, chatID) }
.zip(C.COMMAND_DESC.run { .zip(
C.COMMAND_DESC.run {
listOf(timeDesc, onlineDesc, chatIDDesc) listOf(timeDesc, onlineDesc, chatIDDesc)
}) }
)
.map { TgApiService.BotCommand(it.first!!, it.second) } .map { TgApiService.BotCommand(it.first!!, it.second) }
.let { TgApiService.SetMyCommands(it) } .let { TgApiService.SetMyCommands(it) }
@ -174,12 +178,12 @@ class TgBot(
val msg = update.message!! val msg = update.message!!
val chatId = msg.chat.id val chatId = msg.chat.id
val text = """ 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: |Copy this id to <code>chats</code> section in your <b>config.yml</b> file so it will look like this:
| |
|<pre>chats: |<pre>chats:
| # other ids... | # other ids...
| - ${chatId}</pre> | - $chatId</pre>
""".trimMargin() """.trimMargin()
api.sendMessage(chatId, text, replyToMessageId = msg.messageId) api.sendMessage(chatId, text, replyToMessageId = msg.messageId)
} }