diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyName.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyName.kt new file mode 100644 index 0000000000..7db1ff1716 --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/GetMyName.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.extensions.api.bot + +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.bot.GetMyCommands +import dev.inmo.tgbotapi.requests.bot.GetMyName +import dev.inmo.tgbotapi.types.commands.BotCommandScope +import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault + +suspend fun TelegramBot.getMyName( + languageCode: IetfLanguageCode? = null +) = execute(GetMyName(languageCode)) + +suspend fun TelegramBot.getMyName( + languageCode: String? +) = getMyName(languageCode ?.let(::IetfLanguageCode)) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyName.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyName.kt new file mode 100644 index 0000000000..3af8abcbda --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/bot/SetMyName.kt @@ -0,0 +1,19 @@ +package dev.inmo.tgbotapi.extensions.api.bot + +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.bot.GetMyCommands +import dev.inmo.tgbotapi.requests.bot.GetMyName +import dev.inmo.tgbotapi.requests.bot.SetMyName +import dev.inmo.tgbotapi.types.commands.BotCommandScope +import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault + +suspend fun TelegramBot.setMyName( + name: String? = null, + languageCode: IetfLanguageCode? = null +) = execute(SetMyName(name, languageCode)) + +suspend fun TelegramBot.setMyName( + name: String?, + languageCode: String? +) = setMyName(name, languageCode ?.let(::IetfLanguageCode)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyName.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyName.kt new file mode 100644 index 0000000000..94c606ef2b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/GetMyName.kt @@ -0,0 +1,23 @@ +package dev.inmo.tgbotapi.requests.bot + +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode +import dev.inmo.tgbotapi.types.commands.* +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +class GetMyName( + @SerialName(languageCodeField) + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null +) : SimpleRequest, WithOptionalLanguageCode { + override fun method(): String = "getMyName" + override val resultDeserializer: DeserializationStrategy + get() = BotName.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyName.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyName.kt new file mode 100644 index 0000000000..f1d867dd5e --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/bot/SetMyName.kt @@ -0,0 +1,25 @@ +package dev.inmo.tgbotapi.requests.bot + +import dev.inmo.micro_utils.language_codes.IetfLanguageCode +import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode +import dev.inmo.tgbotapi.types.commands.* +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +class SetMyName( + @SerialName(nameField) + val name: String? = null, + @SerialName(languageCodeField) + @Serializable(IetfLanguageCodeSerializer::class) + override val ietfLanguageCode: IetfLanguageCode? = null +) : SimpleRequest, WithOptionalLanguageCode { + override fun method(): String = "setMyName" + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/BotName.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/BotName.kt new file mode 100644 index 0000000000..59f5a7db57 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/BotName.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class BotName( + @SerialName(nameField) + val name: String +)