-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d222987
commit 427b577
Showing
10 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...pi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/verifications/VerifyChat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.inmo.tgbotapi.extensions.api.verifications | ||
|
||
import dev.inmo.tgbotapi.bot.TelegramBot | ||
import dev.inmo.tgbotapi.requests.verifications.VerifyChat | ||
import dev.inmo.tgbotapi.types.ChatIdentifier | ||
import dev.inmo.tgbotapi.types.chat.* | ||
import dev.inmo.tgbotapi.types.chatIdField | ||
import dev.inmo.tgbotapi.types.customDescriptionField | ||
import kotlinx.serialization.SerialName | ||
|
||
public suspend fun TelegramBot.verifyChat( | ||
chatId: ChatIdentifier, | ||
description: String? = null | ||
): Boolean = execute( | ||
VerifyChat( | ||
chatId = chatId, | ||
description = description | ||
) | ||
) | ||
|
||
/** | ||
* This method may call [verifyUser] in case when [chat] is [PrivateChat] | ||
*/ | ||
public suspend fun TelegramBot.verifyChat( | ||
chat: Chat, | ||
description: String? = null | ||
): Boolean = when (chat) { | ||
is PrivateChat -> verifyUser( | ||
chat = chat, | ||
description = description | ||
) | ||
is UnknownExtendedChat, | ||
is UnknownChatType, | ||
is BusinessChat, | ||
is PublicChat -> verifyChat( | ||
chatId = chat.id, | ||
description = description | ||
) | ||
} |
2 changes: 2 additions & 0 deletions
2
...src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/verifications/VerifyChatAndUser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package dev.inmo.tgbotapi.extensions.api.verifications | ||
|
26 changes: 26 additions & 0 deletions
26
...pi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/verifications/VerifyUser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.inmo.tgbotapi.extensions.api.verifications | ||
|
||
import dev.inmo.tgbotapi.bot.TelegramBot | ||
import dev.inmo.tgbotapi.requests.verifications.VerifyChat | ||
import dev.inmo.tgbotapi.requests.verifications.VerifyUser | ||
import dev.inmo.tgbotapi.types.* | ||
import dev.inmo.tgbotapi.types.chat.Chat | ||
import kotlinx.serialization.SerialName | ||
|
||
public suspend fun TelegramBot.verifyUser( | ||
userId: UserId, | ||
description: String? = null | ||
): Boolean = execute( | ||
VerifyUser( | ||
userId = userId, | ||
description = description | ||
) | ||
) | ||
|
||
public suspend fun TelegramBot.verifyUser( | ||
chat: Chat, | ||
description: String? = null | ||
): Boolean = verifyUser( | ||
userId = chat.id.toChatId(), | ||
description = description | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
.../src/commonMain/kotlin/dev/inmo/tgbotapi/requests/verifications/RemoveChatVerification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.inmo.tgbotapi.requests.verifications | ||
|
||
import dev.inmo.tgbotapi.abstracts.types.ChatRequest | ||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest | ||
import dev.inmo.tgbotapi.types.* | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerializationStrategy | ||
import kotlinx.serialization.builtins.serializer | ||
|
||
|
||
@Serializable | ||
data class RemoveChatVerification( | ||
@SerialName(chatIdField) | ||
override val chatId: ChatIdentifier, | ||
): ChatRequest, SimpleRequest<Boolean> { | ||
override fun method(): String = "removeChatVerification" | ||
override val resultDeserializer: DeserializationStrategy<Boolean> | ||
get() = Boolean.serializer() | ||
override val requestSerializer: SerializationStrategy<*> | ||
get() = serializer() | ||
} |
23 changes: 23 additions & 0 deletions
23
.../src/commonMain/kotlin/dev/inmo/tgbotapi/requests/verifications/RemoveUserVerification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.inmo.tgbotapi.requests.verifications | ||
|
||
import dev.inmo.tgbotapi.abstracts.types.ChatRequest | ||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest | ||
import dev.inmo.tgbotapi.types.* | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerializationStrategy | ||
import kotlinx.serialization.builtins.serializer | ||
|
||
|
||
@Serializable | ||
data class RemoveUserVerification( | ||
@SerialName(userIdField) | ||
val userId: UserId, | ||
): SimpleRequest<Boolean> { | ||
override fun method(): String = "removeUserVerification" | ||
override val resultDeserializer: DeserializationStrategy<Boolean> | ||
get() = Boolean.serializer() | ||
override val requestSerializer: SerializationStrategy<*> | ||
get() = serializer() | ||
} |
28 changes: 28 additions & 0 deletions
28
tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/verifications/VerifyChat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.inmo.tgbotapi.requests.verifications | ||
|
||
import dev.inmo.tgbotapi.abstracts.types.ChatRequest | ||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest | ||
import dev.inmo.tgbotapi.types.ChatIdentifier | ||
import dev.inmo.tgbotapi.types.chatIdField | ||
import dev.inmo.tgbotapi.types.customDescriptionField | ||
import dev.inmo.tgbotapi.types.descriptionField | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerializationStrategy | ||
import kotlinx.serialization.builtins.serializer | ||
|
||
|
||
@Serializable | ||
data class VerifyChat( | ||
@SerialName(chatIdField) | ||
override val chatId: ChatIdentifier, | ||
@SerialName(customDescriptionField) | ||
val description: String? = null | ||
): ChatRequest, SimpleRequest<Boolean> { | ||
override fun method(): String = "verifyChat" | ||
override val resultDeserializer: DeserializationStrategy<Boolean> | ||
get() = Boolean.serializer() | ||
override val requestSerializer: SerializationStrategy<*> | ||
get() = serializer() | ||
} |
25 changes: 25 additions & 0 deletions
25
tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/verifications/VerifyUser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.inmo.tgbotapi.requests.verifications | ||
|
||
import dev.inmo.tgbotapi.abstracts.types.ChatRequest | ||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest | ||
import dev.inmo.tgbotapi.types.* | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.SerializationStrategy | ||
import kotlinx.serialization.builtins.serializer | ||
|
||
|
||
@Serializable | ||
data class VerifyUser( | ||
@SerialName(userIdField) | ||
val userId: UserId, | ||
@SerialName(customDescriptionField) | ||
val description: String? = null | ||
): SimpleRequest<Boolean> { | ||
override fun method(): String = "verifyUser" | ||
override val resultDeserializer: DeserializationStrategy<Boolean> | ||
get() = Boolean.serializer() | ||
override val requestSerializer: SerializationStrategy<*> | ||
get() = serializer() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters