mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
fix warnings
This commit is contained in:
parent
2974a33e51
commit
313068543f
@ -16,7 +16,7 @@ import io.ktor.client.engine.okhttp.OkHttp
|
||||
import io.ktor.util.cio.toByteArray
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.io.charsets.Charset
|
||||
import kotlinx.serialization.json.JSON
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class KtorRequestsExecutor(
|
||||
token: String,
|
||||
@ -25,7 +25,7 @@ class KtorRequestsExecutor(
|
||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||
excludeDefaultFactories: Boolean = false,
|
||||
private val requestsLimiter: RequestLimiter = EmptyLimiter,
|
||||
private val jsonFormatter: JSON = JSON.nonstrict
|
||||
private val jsonFormatter: Json = Json.nonstrict
|
||||
) : BaseRequestsExecutor(token, hostUrl) {
|
||||
constructor(
|
||||
token: String,
|
||||
|
@ -23,8 +23,8 @@ fun String.toInputFile(): InputFile = FileId(this)
|
||||
|
||||
@Serializer(FileId::class)
|
||||
object FileIdSerializer : KSerializer<FileId> {
|
||||
override fun serialize(output: Encoder, obj: FileId) = output.encodeString(obj.fileId)
|
||||
override fun deserialize(input: Decoder): FileId = FileId(input.decodeString())
|
||||
override fun serialize(encoder: Encoder, obj: FileId) = encoder.encodeString(obj.fileId)
|
||||
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())
|
||||
}
|
||||
|
||||
// TODO:: add checks for files size
|
||||
|
@ -4,10 +4,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequ
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJson
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonTreeMapper
|
||||
|
||||
@Serializable
|
||||
data class SetChatPhoto (
|
||||
@ -19,5 +19,5 @@ data class SetChatPhoto (
|
||||
override fun method(): String = "setChatPhoto"
|
||||
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||
override val paramsJson: JsonObject = JsonTreeMapper().writeTree(this, serializer()).jsonObject
|
||||
override val paramsJson: JsonObject = this.toJson(serializer())
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ fun String.asUsername(): Username = Username(this)
|
||||
|
||||
@Serializer(ChatIdentifier::class)
|
||||
internal class ChatIdentifierSerializer: KSerializer<ChatIdentifier> {
|
||||
override fun deserialize(input: Decoder): ChatIdentifier {
|
||||
val id = input.decodeString()
|
||||
override fun deserialize(decoder: Decoder): ChatIdentifier {
|
||||
val id = decoder.decodeString()
|
||||
return id.toLongOrNull() ?.let {
|
||||
ChatId(it)
|
||||
} ?: if (!id.startsWith("@")) {
|
||||
@ -43,10 +43,10 @@ internal class ChatIdentifierSerializer: KSerializer<ChatIdentifier> {
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(output: Encoder, obj: ChatIdentifier) {
|
||||
override fun serialize(encoder: Encoder, obj: ChatIdentifier) {
|
||||
when (obj) {
|
||||
is ChatId -> output.encodeString(obj.chatId.toString())
|
||||
is Username -> output.encodeString(obj.username)
|
||||
is ChatId -> encoder.encodeString(obj.chatId.toString())
|
||||
is Username -> encoder.encodeString(obj.username)
|
||||
}
|
||||
}
|
||||
}
|
@ -8,32 +8,32 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException
|
||||
@Serializer(InlineQueryResult::class)
|
||||
object InlineQueryResultSerializer :
|
||||
KSerializer<InlineQueryResult> {
|
||||
override fun serialize(output: Encoder, obj: InlineQueryResult) {
|
||||
override fun serialize(encoder: Encoder, obj: InlineQueryResult) {
|
||||
when(obj) {
|
||||
is InlineQueryResultArticle -> InlineQueryResultArticle.serializer().serialize(output, obj)
|
||||
is InlineQueryResultAudioCachedImpl -> InlineQueryResultAudioCachedImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultAudioImpl -> InlineQueryResultAudioImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultContact -> InlineQueryResultContact.serializer().serialize(output, obj)
|
||||
is InlineQueryResultDocumentCachedImpl -> InlineQueryResultDocumentCachedImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultDocumentImpl -> InlineQueryResultDocumentImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultGame -> InlineQueryResultGame.serializer().serialize(output, obj)
|
||||
is InlineQueryResultGifCachedImpl -> InlineQueryResultGifCachedImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultGifImpl -> InlineQueryResultGifImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultLocation -> InlineQueryResultLocation.serializer().serialize(output, obj)
|
||||
is InlineQueryResultMpeg4GifCachedImpl -> InlineQueryResultMpeg4GifCachedImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultMpeg4GifImpl -> InlineQueryResultMpeg4GifImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultPhotoCachedImpl -> InlineQueryResultPhotoCachedImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultPhotoImpl -> InlineQueryResultPhotoImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultStickerCached -> InlineQueryResultStickerCached.serializer().serialize(output, obj)
|
||||
is InlineQueryResultVenue -> InlineQueryResultVenue.serializer().serialize(output, obj)
|
||||
is InlineQueryResultVideoCachedImpl -> InlineQueryResultVideoCachedImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultVideoImpl -> InlineQueryResultVideoImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultVoiceCachedImpl -> InlineQueryResultVoiceCachedImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultVoiceImpl -> InlineQueryResultVoiceImpl.serializer().serialize(output, obj)
|
||||
is InlineQueryResultArticle -> InlineQueryResultArticle.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultAudioCachedImpl -> InlineQueryResultAudioCachedImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultAudioImpl -> InlineQueryResultAudioImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultContact -> InlineQueryResultContact.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultDocumentCachedImpl -> InlineQueryResultDocumentCachedImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultDocumentImpl -> InlineQueryResultDocumentImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultGame -> InlineQueryResultGame.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultGifCachedImpl -> InlineQueryResultGifCachedImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultGifImpl -> InlineQueryResultGifImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultLocation -> InlineQueryResultLocation.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultMpeg4GifCachedImpl -> InlineQueryResultMpeg4GifCachedImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultMpeg4GifImpl -> InlineQueryResultMpeg4GifImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultPhotoCachedImpl -> InlineQueryResultPhotoCachedImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultPhotoImpl -> InlineQueryResultPhotoImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultStickerCached -> InlineQueryResultStickerCached.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultVenue -> InlineQueryResultVenue.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultVideoCachedImpl -> InlineQueryResultVideoCachedImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultVideoImpl -> InlineQueryResultVideoImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultVoiceCachedImpl -> InlineQueryResultVoiceCachedImpl.serializer().serialize(encoder, obj)
|
||||
is InlineQueryResultVoiceImpl -> InlineQueryResultVoiceImpl.serializer().serialize(encoder, obj)
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserialize(input: Decoder): InlineQueryResult {
|
||||
override fun deserialize(decoder: Decoder): InlineQueryResult {
|
||||
throw NotImplementedException()
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ object HTMLParseMode : ParseMode() {
|
||||
|
||||
@Serializer(ParseMode::class)
|
||||
internal class ParseModeSerializerObject: KSerializer<ParseMode> {
|
||||
override fun deserialize(input: Decoder): ParseMode {
|
||||
val mode = input.decodeString()
|
||||
override fun deserialize(decoder: Decoder): ParseMode {
|
||||
val mode = decoder.decodeString()
|
||||
return when (mode) {
|
||||
MarkdownParseMode.parseModeName -> MarkdownParseMode
|
||||
HTMLParseMode.parseModeName -> HTMLParseMode
|
||||
@ -34,7 +34,7 @@ internal class ParseModeSerializerObject: KSerializer<ParseMode> {
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(output: Encoder, obj: ParseMode) {
|
||||
output.encodeString(obj.parseModeName)
|
||||
override fun serialize(encoder: Encoder, obj: ParseMode) {
|
||||
encoder.encodeString(obj.parseModeName)
|
||||
}
|
||||
}
|
||||
|
@ -22,15 +22,15 @@ fun DateTime.toTelegramDate(): TelegramDate = TelegramDate(this)
|
||||
|
||||
@Serializer(TelegramDate::class)
|
||||
internal class TelegramDateSerializer: KSerializer<TelegramDate> {
|
||||
override fun serialize(output: Encoder, obj: TelegramDate) {
|
||||
output.encodeLong(
|
||||
override fun serialize(encoder: Encoder, obj: TelegramDate) {
|
||||
encoder.encodeLong(
|
||||
TimeUnit.MILLISECONDS.toSeconds(obj.asDate.millis)
|
||||
)
|
||||
}
|
||||
|
||||
override fun deserialize(input: Decoder): TelegramDate {
|
||||
override fun deserialize(decoder: Decoder): TelegramDate {
|
||||
return TelegramDate(
|
||||
input.decodeLong()
|
||||
decoder.decodeLong()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ sealed class BotAction {
|
||||
|
||||
@Serializer(BotAction::class)
|
||||
class BotActionSerializer: KSerializer<BotAction> {
|
||||
override fun serialize(output: Encoder, obj: BotAction) {
|
||||
output.encodeString(obj.actionName)
|
||||
override fun serialize(encoder: Encoder, obj: BotAction) {
|
||||
encoder.encodeString(obj.actionName)
|
||||
}
|
||||
|
||||
override fun deserialize(input: Decoder): BotAction {
|
||||
val actionName = input.decodeString()
|
||||
override fun deserialize(decoder: Decoder): BotAction {
|
||||
val actionName = decoder.decodeString()
|
||||
return actions.firstOrNull { it.actionName == actionName } ?: throw IllegalStateException("Unknown action type: $actionName")
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,12 @@ interface Currencied {
|
||||
|
||||
@Serializer(Currency::class)
|
||||
object CurrencySerializer : KSerializer<Currency> {
|
||||
override fun serialize(output: Encoder, obj: Currency) {
|
||||
output.encodeString(obj.currencyCode)
|
||||
override fun serialize(encoder: Encoder, obj: Currency) {
|
||||
encoder.encodeString(obj.currencyCode)
|
||||
}
|
||||
|
||||
override fun deserialize(input: Decoder): Currency {
|
||||
return input.decodeString().let {
|
||||
override fun deserialize(decoder: Decoder): Currency {
|
||||
return decoder.decodeString().let {
|
||||
Currency.getInstance(it)
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,15 @@ import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
@ImplicitReflectionSerializer
|
||||
inline fun <reified T: Any> T.toJsonWithoutNulls(): JsonObject = toJson(serializerByValue(this)).withoutNulls()
|
||||
inline fun <reified T: Any> T.toJsonWithoutNulls(): JsonObject = Json.nonstrict.toJson(
|
||||
this
|
||||
).jsonObject.withoutNulls()
|
||||
|
||||
inline fun <reified T: Any> T.toJsonWithoutNulls(serializer: KSerializer<T>): JsonObject = toJson(serializer).withoutNulls()
|
||||
|
||||
inline fun <reified T: Any> T.toJson(serializer: KSerializer<T>): JsonObject = JsonTreeMapper().writeTree(
|
||||
this,
|
||||
serializer
|
||||
inline fun <reified T: Any> T.toJson(serializer: KSerializer<T>): JsonObject = Json.nonstrict.toJson(
|
||||
serializer,
|
||||
this
|
||||
).jsonObject
|
||||
|
||||
fun JsonArray.withoutNulls(): JsonArray {
|
||||
|
Loading…
Reference in New Issue
Block a user