mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 19:48:43 +00:00
commit
7f5cd0567b
@ -1,5 +1,12 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 9.2.0
|
||||||
|
|
||||||
|
**Add support of [Telegram Bots API 6.9](https://core.telegram.org/bots/api-changelog#september-22-2023)**
|
||||||
|
|
||||||
|
* Rename `ChatAdministratorRightsImpl` -> `ChatCommonAdministratorRights`
|
||||||
|
* All the request chat keyboards has changed their parameters `ChatAdministratorRights` to `ChatCommonAdministratorRights`
|
||||||
|
|
||||||
## 9.1.2
|
## 9.1.2
|
||||||
|
|
||||||
* `Core`:
|
* `Core`:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-6.8-blue)](https://core.telegram.org/bots/api-changelog#august-18-2023)
|
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-6.9-blue)](https://core.telegram.org/bots/api-changelog#september-22-2023)
|
||||||
|
|
||||||
| Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Mk&message=Docs&color=blue&logo=mkdocs)](https://docs.inmo.dev/tgbotapi/index.html) |
|
| Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Mk&message=Docs&color=blue&logo=mkdocs)](https://docs.inmo.dev/tgbotapi/index.html) |
|
||||||
|:----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
|
|:----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
|
||||||
|
@ -6,4 +6,4 @@ kotlin.incremental=true
|
|||||||
kotlin.incremental.js=true
|
kotlin.incremental.js=true
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=9.1.2
|
library_version=9.2.0
|
||||||
|
@ -2,17 +2,17 @@ package dev.inmo.tgbotapi.extensions.api.bot
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.requests.bot.SetMyDefaultAdministratorRights
|
import dev.inmo.tgbotapi.requests.bot.SetMyDefaultAdministratorRights
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
|
|
||||||
suspend fun TelegramBot.setMyDefaultAdministratorRights(
|
suspend fun TelegramBot.setMyDefaultAdministratorRights(
|
||||||
rights: ChatAdministratorRightsImpl,
|
rights: ChatCommonAdministratorRights,
|
||||||
forChannels: Boolean? = null
|
forChannels: Boolean? = null
|
||||||
) = execute(SetMyDefaultAdministratorRights(rights, forChannels))
|
) = execute(SetMyDefaultAdministratorRights(rights, forChannels))
|
||||||
|
|
||||||
suspend fun TelegramBot.setMyDefaultAdministratorRightsForChannels(
|
suspend fun TelegramBot.setMyDefaultAdministratorRightsForChannels(
|
||||||
rights: ChatAdministratorRightsImpl
|
rights: ChatCommonAdministratorRights
|
||||||
) = setMyDefaultAdministratorRights(rights, forChannels = true)
|
) = setMyDefaultAdministratorRights(rights, forChannels = true)
|
||||||
|
|
||||||
suspend fun TelegramBot.setMyDefaultAdministratorRightsForGroupsAndSupergroups(
|
suspend fun TelegramBot.setMyDefaultAdministratorRightsForGroupsAndSupergroups(
|
||||||
rights: ChatAdministratorRightsImpl
|
rights: ChatCommonAdministratorRights
|
||||||
) = setMyDefaultAdministratorRights(rights, forChannels = false)
|
) = setMyDefaultAdministratorRights(rights, forChannels = false)
|
||||||
|
@ -0,0 +1,157 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.chat.members
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.chat.members.PromoteChannelAdministrator
|
||||||
|
import dev.inmo.tgbotapi.requests.chat.members.PromoteChatMember
|
||||||
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.TelegramDate
|
||||||
|
import dev.inmo.tgbotapi.types.UserId
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteChannelAdministrator(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canPostMessages: Boolean? = null,
|
||||||
|
canEditMessages: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
|
) = execute(
|
||||||
|
PromoteChannelAdministrator(
|
||||||
|
chatId = chatId,
|
||||||
|
userId = userId,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canPostMessages = canPostMessages,
|
||||||
|
canEditMessages = canEditMessages,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteChannelAdministrator(
|
||||||
|
chat: PublicChat,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canPostMessages: Boolean? = null,
|
||||||
|
canEditMessages: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
|
) = promoteChannelAdministrator(
|
||||||
|
chat.id,
|
||||||
|
userId,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canPostMessages = canPostMessages,
|
||||||
|
canEditMessages = canEditMessages,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteChannelAdministrator(
|
||||||
|
chatId: IdChatIdentifier,
|
||||||
|
user: User,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canPostMessages: Boolean? = null,
|
||||||
|
canEditMessages: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
|
) = promoteChannelAdministrator(
|
||||||
|
chatId,
|
||||||
|
user.id,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canPostMessages = canPostMessages,
|
||||||
|
canEditMessages = canEditMessages,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteChannelAdministrator(
|
||||||
|
chat: PublicChat,
|
||||||
|
user: User,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canPostMessages: Boolean? = null,
|
||||||
|
canEditMessages: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
|
) = promoteChannelAdministrator(
|
||||||
|
chat.id,
|
||||||
|
user.id,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canPostMessages = canPostMessages,
|
||||||
|
canEditMessages = canEditMessages,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
|
)
|
@ -0,0 +1,116 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.chat.members
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.chat.members.PromoteChatMember
|
||||||
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.TelegramDate
|
||||||
|
import dev.inmo.tgbotapi.types.UserId
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteChatAdministrator(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
) = execute(
|
||||||
|
PromoteChatMember(
|
||||||
|
chatId,
|
||||||
|
userId,
|
||||||
|
untilDate,
|
||||||
|
isAnonymous,
|
||||||
|
canChangeInfo,
|
||||||
|
canDeleteMessages,
|
||||||
|
canInviteUsers,
|
||||||
|
canRestrictMembers,
|
||||||
|
canPromoteMembers,
|
||||||
|
canManageVideoChats,
|
||||||
|
canManageChat
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteChatAdministrator(
|
||||||
|
chat: PublicChat,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
) = promoteChatAdministrator(
|
||||||
|
chat.id,
|
||||||
|
userId,
|
||||||
|
untilDate,
|
||||||
|
isAnonymous,
|
||||||
|
canChangeInfo,
|
||||||
|
canDeleteMessages,
|
||||||
|
canInviteUsers,
|
||||||
|
canRestrictMembers,
|
||||||
|
canPromoteMembers,
|
||||||
|
canManageVideoChats,
|
||||||
|
canManageChat
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteChatAdministrator(
|
||||||
|
chatId: IdChatIdentifier,
|
||||||
|
user: User,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
) = promoteChatAdministrator(
|
||||||
|
chatId,
|
||||||
|
user.id,
|
||||||
|
untilDate,
|
||||||
|
isAnonymous,
|
||||||
|
canChangeInfo,
|
||||||
|
canDeleteMessages,
|
||||||
|
canInviteUsers,
|
||||||
|
canRestrictMembers,
|
||||||
|
canPromoteMembers,
|
||||||
|
canManageVideoChats,
|
||||||
|
canManageChat
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteChatAdministrator(
|
||||||
|
chat: PublicChat,
|
||||||
|
user: User,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
) = promoteChatAdministrator(
|
||||||
|
chat.id,
|
||||||
|
user.id,
|
||||||
|
untilDate,
|
||||||
|
isAnonymous,
|
||||||
|
canChangeInfo,
|
||||||
|
canDeleteMessages,
|
||||||
|
canInviteUsers,
|
||||||
|
canRestrictMembers,
|
||||||
|
canPromoteMembers,
|
||||||
|
canManageVideoChats,
|
||||||
|
canManageChat
|
||||||
|
)
|
@ -1,14 +1,13 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.api.chat.members
|
package dev.inmo.tgbotapi.extensions.api.chat.members
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.Warning
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.requests.chat.members.PromoteChatMember
|
import dev.inmo.tgbotapi.requests.chat.members.PromoteChatMember
|
||||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
|
||||||
import dev.inmo.tgbotapi.types.TelegramDate
|
|
||||||
import dev.inmo.tgbotapi.types.UserId
|
|
||||||
import dev.inmo.tgbotapi.types.chat.PublicChat
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
import dev.inmo.tgbotapi.types.chat.User
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
|
||||||
|
@Warning("This method is too common. Use it with caution")
|
||||||
suspend fun TelegramBot.promoteChatMember(
|
suspend fun TelegramBot.promoteChatMember(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
@ -24,27 +23,34 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canPromoteMembers: Boolean? = null,
|
canPromoteMembers: Boolean? = null,
|
||||||
canManageVideoChats: Boolean? = null,
|
canManageVideoChats: Boolean? = null,
|
||||||
canManageChat: Boolean? = null,
|
canManageChat: Boolean? = null,
|
||||||
canManageTopics: Boolean? = null
|
canManageTopics: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
) = execute(
|
) = execute(
|
||||||
PromoteChatMember(
|
PromoteChatMember(
|
||||||
chatId,
|
chatId = chatId,
|
||||||
userId,
|
userId = userId,
|
||||||
untilDate,
|
untilDate = untilDate,
|
||||||
isAnonymous,
|
isAnonymous = isAnonymous,
|
||||||
canChangeInfo,
|
canChangeInfo = canChangeInfo,
|
||||||
canPostMessages,
|
canPostMessages = canPostMessages,
|
||||||
canEditMessages,
|
canEditMessages = canEditMessages,
|
||||||
canDeleteMessages,
|
canDeleteMessages = canDeleteMessages,
|
||||||
canInviteUsers,
|
canInviteUsers = canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers = canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages = canPinMessages,
|
||||||
canPromoteMembers,
|
canPromoteMembers = canPromoteMembers,
|
||||||
canManageVideoChats,
|
canManageVideoChats = canManageVideoChats,
|
||||||
canManageChat,
|
canManageChat = canManageChat,
|
||||||
canManageTopics
|
canManageTopics = canManageTopics,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Warning("This method is too common. Use it with caution")
|
||||||
suspend fun TelegramBot.promoteChatMember(
|
suspend fun TelegramBot.promoteChatMember(
|
||||||
chat: PublicChat,
|
chat: PublicChat,
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
@ -60,25 +66,32 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canPromoteMembers: Boolean? = null,
|
canPromoteMembers: Boolean? = null,
|
||||||
canManageVideoChats: Boolean? = null,
|
canManageVideoChats: Boolean? = null,
|
||||||
canManageChat: Boolean? = null,
|
canManageChat: Boolean? = null,
|
||||||
canManageTopics: Boolean? = null
|
canManageTopics: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
) = promoteChatMember(
|
) = promoteChatMember(
|
||||||
chat.id,
|
chat.id,
|
||||||
userId,
|
userId,
|
||||||
untilDate,
|
untilDate = untilDate,
|
||||||
isAnonymous,
|
isAnonymous = isAnonymous,
|
||||||
canChangeInfo,
|
canChangeInfo = canChangeInfo,
|
||||||
canPostMessages,
|
canPostMessages = canPostMessages,
|
||||||
canEditMessages,
|
canEditMessages = canEditMessages,
|
||||||
canDeleteMessages,
|
canDeleteMessages = canDeleteMessages,
|
||||||
canInviteUsers,
|
canInviteUsers = canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers = canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages = canPinMessages,
|
||||||
canPromoteMembers,
|
canPromoteMembers = canPromoteMembers,
|
||||||
canManageVideoChats,
|
canManageVideoChats = canManageVideoChats,
|
||||||
canManageChat,
|
canManageChat = canManageChat,
|
||||||
canManageTopics
|
canManageTopics = canManageTopics,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Warning("This method is too common. Use it with caution")
|
||||||
suspend fun TelegramBot.promoteChatMember(
|
suspend fun TelegramBot.promoteChatMember(
|
||||||
chatId: IdChatIdentifier,
|
chatId: IdChatIdentifier,
|
||||||
user: User,
|
user: User,
|
||||||
@ -94,25 +107,32 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canPromoteMembers: Boolean? = null,
|
canPromoteMembers: Boolean? = null,
|
||||||
canManageVideoChats: Boolean? = null,
|
canManageVideoChats: Boolean? = null,
|
||||||
canManageChat: Boolean? = null,
|
canManageChat: Boolean? = null,
|
||||||
canManageTopics: Boolean? = null
|
canManageTopics: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
) = promoteChatMember(
|
) = promoteChatMember(
|
||||||
chatId,
|
chatId,
|
||||||
user.id,
|
user.id,
|
||||||
untilDate,
|
untilDate = untilDate,
|
||||||
isAnonymous,
|
isAnonymous = isAnonymous,
|
||||||
canChangeInfo,
|
canChangeInfo = canChangeInfo,
|
||||||
canPostMessages,
|
canPostMessages = canPostMessages,
|
||||||
canEditMessages,
|
canEditMessages = canEditMessages,
|
||||||
canDeleteMessages,
|
canDeleteMessages = canDeleteMessages,
|
||||||
canInviteUsers,
|
canInviteUsers = canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers = canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages = canPinMessages,
|
||||||
canPromoteMembers,
|
canPromoteMembers = canPromoteMembers,
|
||||||
canManageVideoChats,
|
canManageVideoChats = canManageVideoChats,
|
||||||
canManageChat,
|
canManageChat = canManageChat,
|
||||||
canManageTopics
|
canManageTopics = canManageTopics,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Warning("This method is too common. Use it with caution")
|
||||||
suspend fun TelegramBot.promoteChatMember(
|
suspend fun TelegramBot.promoteChatMember(
|
||||||
chat: PublicChat,
|
chat: PublicChat,
|
||||||
user: User,
|
user: User,
|
||||||
@ -128,21 +148,27 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canPromoteMembers: Boolean? = null,
|
canPromoteMembers: Boolean? = null,
|
||||||
canManageVideoChats: Boolean? = null,
|
canManageVideoChats: Boolean? = null,
|
||||||
canManageChat: Boolean? = null,
|
canManageChat: Boolean? = null,
|
||||||
canManageTopics: Boolean? = null
|
canManageTopics: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
) = promoteChatMember(
|
) = promoteChatMember(
|
||||||
chat.id,
|
chat.id,
|
||||||
user.id,
|
user.id,
|
||||||
untilDate,
|
untilDate = untilDate,
|
||||||
isAnonymous,
|
isAnonymous = isAnonymous,
|
||||||
canChangeInfo,
|
canChangeInfo = canChangeInfo,
|
||||||
canPostMessages,
|
canPostMessages = canPostMessages,
|
||||||
canEditMessages,
|
canEditMessages = canEditMessages,
|
||||||
canDeleteMessages,
|
canDeleteMessages = canDeleteMessages,
|
||||||
canInviteUsers,
|
canInviteUsers = canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers = canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages = canPinMessages,
|
||||||
canPromoteMembers,
|
canPromoteMembers = canPromoteMembers,
|
||||||
canManageVideoChats,
|
canManageVideoChats = canManageVideoChats,
|
||||||
canManageChat,
|
canManageChat = canManageChat,
|
||||||
canManageTopics
|
canManageTopics = canManageTopics,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,133 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.chat.members
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.chat.members.PromoteChatMember
|
||||||
|
import dev.inmo.tgbotapi.requests.chat.members.PromoteSupergroupAdministrator
|
||||||
|
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.TelegramDate
|
||||||
|
import dev.inmo.tgbotapi.types.UserId
|
||||||
|
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||||
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteSupergroupAdministrator(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPinMessages: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canManageTopics: Boolean? = null,
|
||||||
|
) = execute(
|
||||||
|
PromoteSupergroupAdministrator(
|
||||||
|
chatId = chatId,
|
||||||
|
userId = userId,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPinMessages = canPinMessages,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canManageTopics = canManageTopics
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteSupergroupAdministrator(
|
||||||
|
chat: PublicChat,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPinMessages: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canManageTopics: Boolean? = null,
|
||||||
|
) = promoteSupergroupAdministrator(
|
||||||
|
chat.id,
|
||||||
|
userId,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPinMessages = canPinMessages,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canManageTopics = canManageTopics
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteSupergroupAdministrator(
|
||||||
|
chatId: IdChatIdentifier,
|
||||||
|
user: User,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPinMessages: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canManageTopics: Boolean? = null,
|
||||||
|
) = promoteSupergroupAdministrator(
|
||||||
|
chatId,
|
||||||
|
user.id,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPinMessages = canPinMessages,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canManageTopics = canManageTopics
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.promoteSupergroupAdministrator(
|
||||||
|
chat: PublicChat,
|
||||||
|
user: User,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPinMessages: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canManageTopics: Boolean? = null,
|
||||||
|
) = promoteSupergroupAdministrator(
|
||||||
|
chat.id,
|
||||||
|
user.id,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPinMessages = canPinMessages,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canManageTopics = canManageTopics
|
||||||
|
)
|
@ -174,6 +174,25 @@ suspend fun BehaviourContext.waitWriteAccessAllowed(
|
|||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEvents<WriteAccessAllowed>(initRequest, errorFactory)
|
) = waitEvents<WriteAccessAllowed>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitWriteAccessAllowedFromRequest(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEvents<WriteAccessAllowed.FromRequest>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitWriteAccessAllowedFromAttachmentMenu(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEvents<WriteAccessAllowed.FromAttachmentMenu>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitWriteAccessAllowedFromWebAppLink(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEvents<WriteAccessAllowed.FromWebAppLink>(initRequest, errorFactory)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.waitWriteAccessAllowedOther(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEvents<WriteAccessAllowed.Other>(initRequest, errorFactory)
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChatSharedRequest(
|
suspend fun BehaviourContext.waitChatSharedRequest(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
|
@ -171,6 +171,22 @@ suspend fun BehaviourContext.waitWriteAccessAllowedEventsMessages(
|
|||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitEventsMessages<WriteAccessAllowed>(initRequest, errorFactory)
|
) = waitEventsMessages<WriteAccessAllowed>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitWriteAccessAllowedFromRequestEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<WriteAccessAllowed.FromRequest>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitWriteAccessAllowedFromAttachmentMenuEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<WriteAccessAllowed.FromAttachmentMenu>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitWriteAccessAllowedFromWebAppLinkEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<WriteAccessAllowed.FromWebAppLink>(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitWriteAccessAllowedOtherEventsMessages(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitEventsMessages<WriteAccessAllowed.Other>(initRequest, errorFactory)
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitChatSharedRequestEventsMessages(
|
suspend fun BehaviourContext.waitChatSharedRequestEventsMessages(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
|
@ -655,10 +655,90 @@ suspend fun <BC : BehaviourContext> BC.onGeneralForumTopicUnhidden(
|
|||||||
* data
|
* data
|
||||||
*/
|
*/
|
||||||
suspend fun <BC : BehaviourContext> BC.onWriteAccessAllowed(
|
suspend fun <BC : BehaviourContext> BC.onWriteAccessAllowed(
|
||||||
initialFilter: SimpleFilter<SupergroupEventMessage<WriteAccessAllowed>>? = null,
|
initialFilter: SimpleFilter<ChatEventMessage<WriteAccessAllowed>>? = null,
|
||||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<WriteAccessAllowed>, Update>? = MessageFilterByChat,
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<WriteAccessAllowed>, Update>? = MessageFilterByChat,
|
||||||
markerFactory: MarkerFactory<in ChatEventMessage<WriteAccessAllowed>, Any> = ByChatMessageMarkerFactory,
|
markerFactory: MarkerFactory<in ChatEventMessage<WriteAccessAllowed>, Any> = ByChatMessageMarkerFactory,
|
||||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<WriteAccessAllowed>>
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<WriteAccessAllowed>>
|
||||||
|
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||||
|
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||||
|
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||||
|
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||||
|
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||||
|
* to combinate several filters
|
||||||
|
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||||
|
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||||
|
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||||
|
* data
|
||||||
|
*/
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onWriteAccessAllowedFromRequest(
|
||||||
|
initialFilter: SimpleFilter<ChatEventMessage<WriteAccessAllowed.FromRequest>>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<WriteAccessAllowed.FromRequest>, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in ChatEventMessage<WriteAccessAllowed.FromRequest>, Any> = ByChatMessageMarkerFactory,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<WriteAccessAllowed.FromRequest>>
|
||||||
|
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||||
|
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||||
|
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||||
|
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||||
|
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||||
|
* to combinate several filters
|
||||||
|
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||||
|
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||||
|
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||||
|
* data
|
||||||
|
*/
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onWriteAccessAllowedFromAttachmentMenu(
|
||||||
|
initialFilter: SimpleFilter<ChatEventMessage<WriteAccessAllowed.FromAttachmentMenu>>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<WriteAccessAllowed.FromAttachmentMenu>, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in ChatEventMessage<WriteAccessAllowed.FromAttachmentMenu>, Any> = ByChatMessageMarkerFactory,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<WriteAccessAllowed.FromAttachmentMenu>>
|
||||||
|
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||||
|
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||||
|
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||||
|
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||||
|
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||||
|
* to combinate several filters
|
||||||
|
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||||
|
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||||
|
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||||
|
* data
|
||||||
|
*/
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onWriteAccessAllowedOther(
|
||||||
|
initialFilter: SimpleFilter<ChatEventMessage<WriteAccessAllowed.Other>>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<WriteAccessAllowed.Other>, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in ChatEventMessage<WriteAccessAllowed.Other>, Any> = ByChatMessageMarkerFactory,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<WriteAccessAllowed.Other>>
|
||||||
|
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||||
|
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||||
|
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||||
|
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||||
|
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||||
|
* to combinate several filters
|
||||||
|
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||||
|
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||||
|
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||||
|
* data
|
||||||
|
*/
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onWriteAccessAllowedFromWebAppLink(
|
||||||
|
initialFilter: SimpleFilter<ChatEventMessage<WriteAccessAllowed.FromWebAppLink>>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<WriteAccessAllowed.FromWebAppLink>, Update>? = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in ChatEventMessage<WriteAccessAllowed.FromWebAppLink>, Any> = ByChatMessageMarkerFactory,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<WriteAccessAllowed.FromWebAppLink>>
|
||||||
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,14 +2,14 @@ package dev.inmo.tgbotapi.requests.bot
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.builtins.serializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class SetMyDefaultAdministratorRights(
|
class SetMyDefaultAdministratorRights(
|
||||||
@SerialName(rightsField)
|
@SerialName(rightsField)
|
||||||
val rights: ChatAdministratorRightsImpl,
|
val rights: ChatCommonAdministratorRights,
|
||||||
@SerialName(forChannelsField)
|
@SerialName(forChannelsField)
|
||||||
val forChannels: Boolean? = null
|
val forChannels: Boolean? = null
|
||||||
) : SimpleRequest<Boolean> {
|
) : SimpleRequest<Boolean> {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.requests.chat.members
|
package dev.inmo.tgbotapi.requests.chat.members
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.Warning
|
||||||
import dev.inmo.tgbotapi.abstracts.types.UntilDate
|
import dev.inmo.tgbotapi.abstracts.types.UntilDate
|
||||||
import dev.inmo.tgbotapi.requests.chat.abstracts.ChatMemberRequest
|
import dev.inmo.tgbotapi.requests.chat.abstracts.ChatMemberRequest
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
@ -7,6 +8,7 @@ import kotlinx.serialization.*
|
|||||||
import kotlinx.serialization.builtins.serializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@Warning("This method is too common. Use it with caution")
|
||||||
data class PromoteChatMember(
|
data class PromoteChatMember(
|
||||||
@SerialName(chatIdField)
|
@SerialName(chatIdField)
|
||||||
override val chatId: ChatIdentifier,
|
override val chatId: ChatIdentifier,
|
||||||
@ -37,7 +39,13 @@ data class PromoteChatMember(
|
|||||||
@SerialName(canManageChatField)
|
@SerialName(canManageChatField)
|
||||||
private val canManageChat: Boolean? = null,
|
private val canManageChat: Boolean? = null,
|
||||||
@SerialName(canManageTopicsField)
|
@SerialName(canManageTopicsField)
|
||||||
private val canManageTopics: Boolean? = null
|
private val canManageTopics: Boolean? = null,
|
||||||
|
@SerialName(canPostStoriesField)
|
||||||
|
private val canPostStories: Boolean? = null,
|
||||||
|
@SerialName(canEditStoriesField)
|
||||||
|
private val canEditStories: Boolean? = null,
|
||||||
|
@SerialName(canDeleteStoriesField)
|
||||||
|
private val canDeleteStories: Boolean? = null
|
||||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||||
override fun method(): String = "promoteChatMember"
|
override fun method(): String = "promoteChatMember"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
@ -45,3 +53,109 @@ data class PromoteChatMember(
|
|||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun PromoteChatMember(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
) = PromoteChatMember(
|
||||||
|
chatId = chatId,
|
||||||
|
userId = userId,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canPostMessages = null,
|
||||||
|
canEditMessages = null,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPinMessages = null,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canManageTopics = null,
|
||||||
|
canPostStories = null,
|
||||||
|
canEditStories = null,
|
||||||
|
canDeleteStories = null
|
||||||
|
)
|
||||||
|
|
||||||
|
fun PromoteChannelAdministrator(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canPostMessages: Boolean? = null,
|
||||||
|
canEditMessages: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canPostStories: Boolean? = null,
|
||||||
|
canEditStories: Boolean? = null,
|
||||||
|
canDeleteStories: Boolean? = null
|
||||||
|
) = PromoteChatMember(
|
||||||
|
chatId = chatId,
|
||||||
|
userId = userId,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canPostMessages = canPostMessages,
|
||||||
|
canEditMessages = canEditMessages,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPinMessages = null,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canManageTopics = null,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
|
)
|
||||||
|
|
||||||
|
fun PromoteSupergroupAdministrator(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
userId: UserId,
|
||||||
|
untilDate: TelegramDate? = null,
|
||||||
|
isAnonymous: Boolean? = null,
|
||||||
|
canChangeInfo: Boolean? = null,
|
||||||
|
canDeleteMessages: Boolean? = null,
|
||||||
|
canInviteUsers: Boolean? = null,
|
||||||
|
canRestrictMembers: Boolean? = null,
|
||||||
|
canPinMessages: Boolean? = null,
|
||||||
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVideoChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null,
|
||||||
|
canManageTopics: Boolean? = null,
|
||||||
|
) = PromoteChatMember(
|
||||||
|
chatId = chatId,
|
||||||
|
userId = userId,
|
||||||
|
untilDate = untilDate,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canPostMessages = null,
|
||||||
|
canEditMessages = null,
|
||||||
|
canDeleteMessages = canDeleteMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPinMessages = canPinMessages,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
canManageTopics = canManageTopics,
|
||||||
|
canPostStories = null,
|
||||||
|
canEditStories = null,
|
||||||
|
canDeleteStories = null
|
||||||
|
)
|
||||||
|
@ -177,6 +177,11 @@ val stickerKeywordLengthLimit = 0 .. 64
|
|||||||
|
|
||||||
const val botActionActualityTime: Seconds = 5
|
const val botActionActualityTime: Seconds = 5
|
||||||
|
|
||||||
|
val cloudStorageKeyLimit = 1 .. 128
|
||||||
|
val cloudStorageValueLimit = 0 .. 4096
|
||||||
|
val cloudStorageKeyRegex = Regex("[A-Za-z0-9_-]{${cloudStorageKeyLimit.first},${cloudStorageKeyLimit.last}}")
|
||||||
|
val cloudStorageValueRegex = Regex(".{${cloudStorageValueLimit.first},${cloudStorageValueLimit.last}}")
|
||||||
|
|
||||||
// Made as lazy for correct work in K/JS
|
// Made as lazy for correct work in K/JS
|
||||||
val telegramInlineModeGifPermittedMimeTypes by lazy {
|
val telegramInlineModeGifPermittedMimeTypes by lazy {
|
||||||
listOf(
|
listOf(
|
||||||
@ -210,6 +215,7 @@ const val firstNameField = "first_name"
|
|||||||
const val lastNameField = "last_name"
|
const val lastNameField = "last_name"
|
||||||
const val languageCodeField = "language_code"
|
const val languageCodeField = "language_code"
|
||||||
const val addedToAttachmentMenuField = "added_to_attachment_menu"
|
const val addedToAttachmentMenuField = "added_to_attachment_menu"
|
||||||
|
const val allowsWriteToPMField = "allows_write_to_pm"
|
||||||
const val isPremiumField = "is_premium"
|
const val isPremiumField = "is_premium"
|
||||||
const val hasPrivateForwardsField = "has_private_forwards"
|
const val hasPrivateForwardsField = "has_private_forwards"
|
||||||
const val hasRestrictedVoiceAndVideoMessagesField = "has_restricted_voice_and_video_messages"
|
const val hasRestrictedVoiceAndVideoMessagesField = "has_restricted_voice_and_video_messages"
|
||||||
@ -274,6 +280,9 @@ const val correctOptionIdField = "correct_option_id"
|
|||||||
const val allowsMultipleAnswersField = "allows_multiple_answers"
|
const val allowsMultipleAnswersField = "allows_multiple_answers"
|
||||||
const val isAnonymousField = "is_anonymous"
|
const val isAnonymousField = "is_anonymous"
|
||||||
const val canManageTopicsField = "can_manage_topics"
|
const val canManageTopicsField = "can_manage_topics"
|
||||||
|
const val canPostStoriesField = "can_post_stories"
|
||||||
|
const val canEditStoriesField = "can_edit_stories"
|
||||||
|
const val canDeleteStoriesField = "can_delete_stories"
|
||||||
const val captionEntitiesField = "caption_entities"
|
const val captionEntitiesField = "caption_entities"
|
||||||
const val hasSpoilerField = "has_spoiler"
|
const val hasSpoilerField = "has_spoiler"
|
||||||
const val loginUrlField = "login_url"
|
const val loginUrlField = "login_url"
|
||||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.buttons
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.types.botAdministratorRightsField
|
import dev.inmo.tgbotapi.types.botAdministratorRightsField
|
||||||
import dev.inmo.tgbotapi.types.botIsMemberField
|
import dev.inmo.tgbotapi.types.botIsMemberField
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
import dev.inmo.tgbotapi.types.chatHasUsernameField
|
import dev.inmo.tgbotapi.types.chatHasUsernameField
|
||||||
import dev.inmo.tgbotapi.types.chatIsChannelField
|
import dev.inmo.tgbotapi.types.chatIsChannelField
|
||||||
import dev.inmo.tgbotapi.types.chatIsCreatedField
|
import dev.inmo.tgbotapi.types.chatIsCreatedField
|
||||||
@ -30,9 +30,9 @@ data class KeyboardButtonRequestChat(
|
|||||||
@SerialName(chatIsCreatedField)
|
@SerialName(chatIsCreatedField)
|
||||||
val isOwnedBy: Boolean? = null,
|
val isOwnedBy: Boolean? = null,
|
||||||
@SerialName(userAdministratorRightsField)
|
@SerialName(userAdministratorRightsField)
|
||||||
val userRightsInChat: ChatAdministratorRights? = null,
|
val userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
@SerialName(botAdministratorRightsField)
|
@SerialName(botAdministratorRightsField)
|
||||||
val botRightsInChat: ChatAdministratorRights? = null,
|
val botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
@SerialName(botIsMemberField)
|
@SerialName(botIsMemberField)
|
||||||
val botIsMember: Boolean? = null
|
val botIsMember: Boolean? = null
|
||||||
) {
|
) {
|
||||||
@ -41,8 +41,8 @@ data class KeyboardButtonRequestChat(
|
|||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
isPublic: Boolean? = null,
|
isPublic: Boolean? = null,
|
||||||
isOwnedBy: Boolean? = null,
|
isOwnedBy: Boolean? = null,
|
||||||
userRightsInChat: ChatAdministratorRights? = null,
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botRightsInChat: ChatAdministratorRights? = null,
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botIsMember: Boolean? = null
|
botIsMember: Boolean? = null
|
||||||
) = KeyboardButtonRequestChat(
|
) = KeyboardButtonRequestChat(
|
||||||
requestId = requestId,
|
requestId = requestId,
|
||||||
@ -60,8 +60,8 @@ data class KeyboardButtonRequestChat(
|
|||||||
isForum: Boolean? = null,
|
isForum: Boolean? = null,
|
||||||
isPublic: Boolean? = null,
|
isPublic: Boolean? = null,
|
||||||
isOwnedBy: Boolean? = null,
|
isOwnedBy: Boolean? = null,
|
||||||
userRightsInChat: ChatAdministratorRights? = null,
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botRightsInChat: ChatAdministratorRights? = null,
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botIsMember: Boolean? = null
|
botIsMember: Boolean? = null
|
||||||
) = KeyboardButtonRequestChat(
|
) = KeyboardButtonRequestChat(
|
||||||
requestId = requestId,
|
requestId = requestId,
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.types.buttons.reply
|
package dev.inmo.tgbotapi.types.buttons.reply
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.*
|
import dev.inmo.tgbotapi.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights
|
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||||
|
|
||||||
@ -120,8 +119,8 @@ inline fun requestChatReplyButton(
|
|||||||
isForum: Boolean? = null,
|
isForum: Boolean? = null,
|
||||||
isPublic: Boolean? = null,
|
isPublic: Boolean? = null,
|
||||||
isOwnedBy: Boolean? = null,
|
isOwnedBy: Boolean? = null,
|
||||||
userRightsInChat: ChatAdministratorRights? = null,
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botRightsInChat: ChatAdministratorRights? = null,
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botIsMember: Boolean = false
|
botIsMember: Boolean = false
|
||||||
) = requestChatReplyButton(
|
) = requestChatReplyButton(
|
||||||
text,
|
text,
|
||||||
@ -145,8 +144,8 @@ inline fun requestChannelReplyButton(
|
|||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
isPublic: Boolean? = null,
|
isPublic: Boolean? = null,
|
||||||
isOwnedBy: Boolean? = null,
|
isOwnedBy: Boolean? = null,
|
||||||
userRightsInChat: ChatAdministratorRights? = null,
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botRightsInChat: ChatAdministratorRights? = null,
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botIsMember: Boolean = false
|
botIsMember: Boolean = false
|
||||||
) = requestChatReplyButton(
|
) = requestChatReplyButton(
|
||||||
text,
|
text,
|
||||||
@ -170,8 +169,8 @@ inline fun requestChannelReplyButton(
|
|||||||
isForum: Boolean? = null,
|
isForum: Boolean? = null,
|
||||||
isPublic: Boolean? = null,
|
isPublic: Boolean? = null,
|
||||||
isOwnedBy: Boolean? = null,
|
isOwnedBy: Boolean? = null,
|
||||||
userRightsInChat: ChatAdministratorRights? = null,
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botRightsInChat: ChatAdministratorRights? = null,
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botIsMember: Boolean? = null
|
botIsMember: Boolean? = null
|
||||||
) = requestChatReplyButton(
|
) = requestChatReplyButton(
|
||||||
text,
|
text,
|
||||||
|
@ -35,9 +35,16 @@ data class AdministratorChatMemberImpl(
|
|||||||
@SerialName(customTitleField)
|
@SerialName(customTitleField)
|
||||||
override val customTitle: String? = null,
|
override val customTitle: String? = null,
|
||||||
@SerialName(canManageTopicsField)
|
@SerialName(canManageTopicsField)
|
||||||
override val canManageTopics: Boolean = false
|
override val canManageTopics: Boolean = false,
|
||||||
|
@SerialName(canPostStoriesField)
|
||||||
|
override val canPostStories: Boolean = false,
|
||||||
|
@SerialName(canEditStoriesField)
|
||||||
|
override val canEditStories: Boolean = false,
|
||||||
|
@SerialName(canDeleteStoriesField)
|
||||||
|
override val canDeleteStories: Boolean = false
|
||||||
) : AdministratorChatMember {
|
) : AdministratorChatMember {
|
||||||
@SerialName(statusField)
|
@SerialName(statusField)
|
||||||
@Required
|
@Required
|
||||||
private val type: String = "administrator"
|
override val status: ChatMember.Status
|
||||||
|
get() = ChatMember.Status.Administrator
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,43 @@ sealed interface ChatAdministratorRights : SpecialChatAdministratorRights {
|
|||||||
val canPromoteMembers: Boolean
|
val canPromoteMembers: Boolean
|
||||||
val canPostMessages: Boolean
|
val canPostMessages: Boolean
|
||||||
val canEditMessages: Boolean
|
val canEditMessages: Boolean
|
||||||
|
val canPostStories: Boolean
|
||||||
|
val canEditStories: Boolean
|
||||||
|
val canDeleteStories: Boolean
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
operator fun invoke(
|
||||||
|
canChangeInfo: Boolean = false,
|
||||||
|
canPostMessages: Boolean = false,
|
||||||
|
canEditMessages: Boolean = false,
|
||||||
|
canRemoveMessages: Boolean = false,
|
||||||
|
canInviteUsers: Boolean = false,
|
||||||
|
canRestrictMembers: Boolean = false,
|
||||||
|
canPinMessages: Boolean = false,
|
||||||
|
canPromoteMembers: Boolean = false,
|
||||||
|
canManageVideoChats: Boolean = false,
|
||||||
|
canManageChat: Boolean = false,
|
||||||
|
isAnonymous: Boolean = false,
|
||||||
|
canManageTopics: Boolean = false,
|
||||||
|
canPostStories: Boolean = false,
|
||||||
|
canEditStories: Boolean = false,
|
||||||
|
canDeleteStories: Boolean = false
|
||||||
|
) = ChatCommonAdministratorRights(
|
||||||
|
canChangeInfo = canChangeInfo,
|
||||||
|
canPostMessages = canPostMessages,
|
||||||
|
canEditMessages = canEditMessages,
|
||||||
|
canRemoveMessages = canRemoveMessages,
|
||||||
|
canInviteUsers = canInviteUsers,
|
||||||
|
canRestrictMembers = canRestrictMembers,
|
||||||
|
canPinMessages = canPinMessages,
|
||||||
|
canPromoteMembers = canPromoteMembers,
|
||||||
|
canManageVideoChats = canManageVideoChats,
|
||||||
|
canManageChat = canManageChat,
|
||||||
|
isAnonymous = isAnonymous,
|
||||||
|
canManageTopics = canManageTopics,
|
||||||
|
canPostStories = canPostStories,
|
||||||
|
canEditStories = canEditStories,
|
||||||
|
canDeleteStories = canDeleteStories
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import kotlinx.serialization.SerialName
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ChatAdministratorRightsImpl(
|
data class ChatCommonAdministratorRights(
|
||||||
@SerialName(canChangeInfoField)
|
@SerialName(canChangeInfoField)
|
||||||
override val canChangeInfo: Boolean = false,
|
override val canChangeInfo: Boolean = false,
|
||||||
@SerialName(canPostMessagesField)
|
@SerialName(canPostMessagesField)
|
||||||
@ -29,5 +29,20 @@ data class ChatAdministratorRightsImpl(
|
|||||||
@SerialName(isAnonymousField)
|
@SerialName(isAnonymousField)
|
||||||
override val isAnonymous: Boolean = false,
|
override val isAnonymous: Boolean = false,
|
||||||
@SerialName(canManageTopicsField)
|
@SerialName(canManageTopicsField)
|
||||||
override val canManageTopics: Boolean = false
|
override val canManageTopics: Boolean = false,
|
||||||
|
@SerialName(canPostStoriesField)
|
||||||
|
override val canPostStories: Boolean = false,
|
||||||
|
@SerialName(canEditStoriesField)
|
||||||
|
override val canEditStories: Boolean = false,
|
||||||
|
@SerialName(canDeleteStoriesField)
|
||||||
|
override val canDeleteStories: Boolean = false
|
||||||
) : ChatAdministratorRights
|
) : ChatAdministratorRights
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"Renamed to ChatCommonAdministratorRights and will be removed soon",
|
||||||
|
ReplaceWith(
|
||||||
|
"ChatCommonAdministratorRights",
|
||||||
|
"dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
typealias ChatAdministratorRightsImpl = ChatCommonAdministratorRights
|
@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.abstracts.WithUser
|
|||||||
import dev.inmo.tgbotapi.types.statusField
|
import dev.inmo.tgbotapi.types.statusField
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||||
|
import kotlinx.serialization.DeserializationStrategy
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
@ -13,7 +14,18 @@ import kotlinx.serialization.json.JsonObject
|
|||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
|
|
||||||
@Serializable(ChatMemberSerializer::class)
|
@Serializable(ChatMemberSerializer::class)
|
||||||
sealed interface ChatMember : WithUser
|
sealed interface ChatMember : WithUser {
|
||||||
|
@Serializable
|
||||||
|
enum class Status(val status: String, val deserializationStrategy: DeserializationStrategy<ChatMember>) {
|
||||||
|
Creator("creator", OwnerChatMember.serializer()),
|
||||||
|
Administrator("administrator", AdministratorChatMemberImpl.serializer()),
|
||||||
|
Member("member", MemberChatMemberImpl.serializer()),
|
||||||
|
Restricted("restricted", RestrictedChatMember.serializer()),
|
||||||
|
Left("left", LeftChatMemberImpl.serializer()),
|
||||||
|
Kicked("kicked", KickedChatMember.serializer())
|
||||||
|
}
|
||||||
|
val status: Status
|
||||||
|
}
|
||||||
|
|
||||||
@RiskFeature
|
@RiskFeature
|
||||||
object ChatMemberSerializer : KSerializer<ChatMember> {
|
object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||||
@ -21,15 +33,14 @@ object ChatMemberSerializer : KSerializer<ChatMember> {
|
|||||||
|
|
||||||
override fun deserialize(decoder: Decoder): ChatMember {
|
override fun deserialize(decoder: Decoder): ChatMember {
|
||||||
val json = JsonObject.serializer().deserialize(decoder)
|
val json = JsonObject.serializer().deserialize(decoder)
|
||||||
return when (json[statusField] ?.jsonPrimitive ?.content ?: error("Status field of chat member must be specified, but incoming json contains next: $json")) {
|
val status = json[statusField] ?.jsonPrimitive ?.content ?: error("Status field of chat member must be specified, but incoming json contains next: $json")
|
||||||
"creator" -> nonstrictJsonFormat.decodeFromJsonElement(OwnerChatMember.serializer(), json)
|
return ChatMember.Status.values().firstNotNullOfOrNull {
|
||||||
"administrator" -> nonstrictJsonFormat.decodeFromJsonElement(AdministratorChatMemberImpl.serializer(), json)
|
if (it.status == status) {
|
||||||
"member" -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMemberImpl.serializer(), json)
|
nonstrictJsonFormat.decodeFromJsonElement(it.deserializationStrategy, json)
|
||||||
"restricted" -> nonstrictJsonFormat.decodeFromJsonElement(RestrictedChatMember.serializer(), json)
|
} else {
|
||||||
"left" -> nonstrictJsonFormat.decodeFromJsonElement(LeftChatMemberImpl.serializer(), json)
|
null
|
||||||
"kicked" -> nonstrictJsonFormat.decodeFromJsonElement(KickedChatMember.serializer(), json)
|
|
||||||
else -> error("Unknown type of chat member in json: $json")
|
|
||||||
}
|
}
|
||||||
|
} ?: error("Unknown type of chat member in json: $json")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun serialize(encoder: Encoder, value: ChatMember) {
|
override fun serialize(encoder: Encoder, value: ChatMember) {
|
||||||
|
@ -13,5 +13,6 @@ data class KickedChatMember(
|
|||||||
) : BannedChatMember {
|
) : BannedChatMember {
|
||||||
@SerialName(statusField)
|
@SerialName(statusField)
|
||||||
@Required
|
@Required
|
||||||
private val type: String = "kicked"
|
override val status: ChatMember.Status
|
||||||
|
get() = ChatMember.Status.Kicked
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,12 @@ import dev.inmo.tgbotapi.types.chat.User
|
|||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class LeftChatMemberImpl(@SerialName(userField) override val user: User) : LeftChatMember {
|
data class LeftChatMemberImpl(
|
||||||
|
@SerialName(userField)
|
||||||
|
override val user: User
|
||||||
|
) : LeftChatMember {
|
||||||
@SerialName(statusField)
|
@SerialName(statusField)
|
||||||
@Required
|
@Required
|
||||||
private val type: String = "left"
|
override val status: ChatMember.Status
|
||||||
|
get() = ChatMember.Status.Left
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,12 @@ import dev.inmo.tgbotapi.types.chat.User
|
|||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class MemberChatMemberImpl(@SerialName(userField) override val user: User) : MemberChatMember {
|
data class MemberChatMemberImpl(
|
||||||
|
@SerialName(userField)
|
||||||
|
override val user: User
|
||||||
|
) : MemberChatMember {
|
||||||
@SerialName(statusField)
|
@SerialName(statusField)
|
||||||
@Required
|
@Required
|
||||||
private val type: String = "member"
|
override val status: ChatMember.Status
|
||||||
|
get() = ChatMember.Status.Member
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,15 @@ data class OwnerChatMember(
|
|||||||
override val canManageChat: Boolean = true
|
override val canManageChat: Boolean = true
|
||||||
@Transient
|
@Transient
|
||||||
override val canManageTopics: Boolean = true
|
override val canManageTopics: Boolean = true
|
||||||
|
@Transient
|
||||||
|
override val canPostStories: Boolean = true
|
||||||
|
@Transient
|
||||||
|
override val canEditStories: Boolean = true
|
||||||
|
@Transient
|
||||||
|
override val canDeleteStories: Boolean = true
|
||||||
|
|
||||||
@SerialName(statusField)
|
@SerialName(statusField)
|
||||||
@Required
|
@Required
|
||||||
private val type: String = "creator"
|
override val status: ChatMember.Status
|
||||||
|
get() = ChatMember.Status.Creator
|
||||||
}
|
}
|
||||||
|
@ -44,5 +44,6 @@ data class RestrictedChatMember(
|
|||||||
) : BannedChatMember, SpecialRightsChatMember, ChatPermissions {
|
) : BannedChatMember, SpecialRightsChatMember, ChatPermissions {
|
||||||
@SerialName(statusField)
|
@SerialName(statusField)
|
||||||
@Required
|
@Required
|
||||||
private val type: String = "restricted"
|
override val status: ChatMember.Status
|
||||||
|
get() = ChatMember.Status.Restricted
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,75 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.ChatEvents.forum
|
package dev.inmo.tgbotapi.types.message.ChatEvents.forum
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ForumEvent
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PrivateEvent
|
||||||
import dev.inmo.tgbotapi.types.webAppNameField
|
import dev.inmo.tgbotapi.types.webAppNameField
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
@Serializable
|
@Serializable(WriteAccessAllowed.Companion::class)
|
||||||
data class WriteAccessAllowed(
|
sealed interface WriteAccessAllowed : PrivateEvent, ForumEvent {
|
||||||
@SerialName(webAppNameField)
|
val webAppName: String?
|
||||||
val webAppName: String? = null
|
get() = null
|
||||||
) : ForumEvent
|
val fromRequest: Boolean
|
||||||
|
get() = false
|
||||||
|
val fromAttachmentMenu: Boolean
|
||||||
|
get() = false
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
object Other : WriteAccessAllowed
|
||||||
|
@Serializable
|
||||||
|
data class FromWebAppLink(
|
||||||
|
override val webAppName: String
|
||||||
|
) : WriteAccessAllowed
|
||||||
|
@Serializable
|
||||||
|
object FromRequest : WriteAccessAllowed {
|
||||||
|
override val fromRequest: Boolean
|
||||||
|
get() = true
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
object FromAttachmentMenu : WriteAccessAllowed {
|
||||||
|
override val fromAttachmentMenu: Boolean
|
||||||
|
get() = true
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
private class WriteAccessAllowedRaw(
|
||||||
|
val web_app_name: String? = null,
|
||||||
|
val from_request: Boolean = false,
|
||||||
|
val from_attachment_menu: Boolean = false
|
||||||
|
)
|
||||||
|
|
||||||
|
companion object : KSerializer<WriteAccessAllowed> {
|
||||||
|
override val descriptor: SerialDescriptor
|
||||||
|
get() = WriteAccessAllowedRaw.serializer().descriptor
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): WriteAccessAllowed {
|
||||||
|
val raw = WriteAccessAllowedRaw.serializer().deserialize(decoder)
|
||||||
|
|
||||||
|
return when {
|
||||||
|
raw.web_app_name != null -> FromWebAppLink(raw.web_app_name)
|
||||||
|
raw.from_request -> FromRequest
|
||||||
|
raw.from_attachment_menu -> Other
|
||||||
|
else -> Other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: WriteAccessAllowed) {
|
||||||
|
val raw = when (value) {
|
||||||
|
FromAttachmentMenu -> WriteAccessAllowedRaw(from_attachment_menu = true)
|
||||||
|
FromRequest -> WriteAccessAllowedRaw(from_request = true)
|
||||||
|
Other -> WriteAccessAllowedRaw()
|
||||||
|
is FromWebAppLink -> WriteAccessAllowedRaw(web_app_name = value.webAppName)
|
||||||
|
}
|
||||||
|
WriteAccessAllowedRaw.serializer().serialize(encoder, raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun invoke(webAppName: String?): WriteAccessAllowed = webAppName ?.let(::FromWebAppLink) ?: Other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,8 +7,9 @@ import kotlin.random.Random
|
|||||||
@Serializable
|
@Serializable
|
||||||
@JvmInline
|
@JvmInline
|
||||||
value class RequestId(
|
value class RequestId(
|
||||||
val int: Int
|
val uShort: UShort
|
||||||
) {
|
) {
|
||||||
|
constructor(int: Int) : this(int.toUShort())
|
||||||
companion object {
|
companion object {
|
||||||
fun random() = RequestId(Random.nextInt())
|
fun random() = RequestId(Random.nextInt())
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons
|
|||||||
import dev.inmo.tgbotapi.types.buttons.*
|
import dev.inmo.tgbotapi.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
||||||
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
|
import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRights
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
import dev.inmo.tgbotapi.types.request.RequestId
|
import dev.inmo.tgbotapi.types.request.RequestId
|
||||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
@ -220,8 +220,8 @@ inline fun ReplyKeyboardRowBuilder.requestChatButton(
|
|||||||
isForum: Boolean? = null,
|
isForum: Boolean? = null,
|
||||||
isPublic: Boolean? = null,
|
isPublic: Boolean? = null,
|
||||||
isOwnedBy: Boolean? = null,
|
isOwnedBy: Boolean? = null,
|
||||||
userRightsInChat: ChatAdministratorRights? = null,
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botRightsInChat: ChatAdministratorRights? = null,
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botIsMember: Boolean? = null
|
botIsMember: Boolean? = null
|
||||||
) = requestChatButton(
|
) = requestChatButton(
|
||||||
text,
|
text,
|
||||||
@ -248,8 +248,8 @@ inline fun ReplyKeyboardRowBuilder.requestChannelButton(
|
|||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
isPublic: Boolean? = null,
|
isPublic: Boolean? = null,
|
||||||
isOwnedBy: Boolean? = null,
|
isOwnedBy: Boolean? = null,
|
||||||
userRightsInChat: ChatAdministratorRights? = null,
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botRightsInChat: ChatAdministratorRights? = null,
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botIsMember: Boolean? = null
|
botIsMember: Boolean? = null
|
||||||
) = requestChatButton(
|
) = requestChatButton(
|
||||||
text,
|
text,
|
||||||
@ -275,8 +275,8 @@ inline fun ReplyKeyboardRowBuilder.requestGroupButton(
|
|||||||
isForum: Boolean? = null,
|
isForum: Boolean? = null,
|
||||||
isPublic: Boolean? = null,
|
isPublic: Boolean? = null,
|
||||||
isOwnedBy: Boolean? = null,
|
isOwnedBy: Boolean? = null,
|
||||||
userRightsInChat: ChatAdministratorRights? = null,
|
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botRightsInChat: ChatAdministratorRights? = null,
|
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||||
botIsMember: Boolean? = null
|
botIsMember: Boolean? = null
|
||||||
) = requestChatButton(
|
) = requestChatButton(
|
||||||
text,
|
text,
|
||||||
|
@ -8,7 +8,9 @@ sealed interface Color {
|
|||||||
value class BackgroundColor(override val value: String) : Color
|
value class BackgroundColor(override val value: String) : Color
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
value class Hex(override val value: String) : Color
|
value class Hex(override val value: String) : Color {
|
||||||
|
constructor(r: UByte, g: UByte, b: UByte) : this("#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}")
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val BackgroundColor = BackgroundColor("bg_color")
|
val BackgroundColor = BackgroundColor("bg_color")
|
||||||
|
@ -8,3 +8,5 @@ typealias InvoiceClosedEventHandler = WebApp.(InvoiceClosedInfo) -> Unit
|
|||||||
typealias PopupClosedEventHandler = WebApp.(String?) -> Unit
|
typealias PopupClosedEventHandler = WebApp.(String?) -> Unit
|
||||||
typealias QRTextReceivedEventHandler = WebApp.(String) -> Boolean
|
typealias QRTextReceivedEventHandler = WebApp.(String) -> Boolean
|
||||||
typealias TextReceivedEventHandler = WebApp.(String) -> Unit
|
typealias TextReceivedEventHandler = WebApp.(String) -> Unit
|
||||||
|
typealias WriteAccessRequestedHandler = WebApp.(Boolean) -> Unit
|
||||||
|
typealias ContactRequestedHandler = WebApp.(Boolean) -> Unit
|
||||||
|
@ -10,4 +10,6 @@ sealed class EventType(val typeName: String) {
|
|||||||
object PopupClosed : EventType("popupClosed")
|
object PopupClosed : EventType("popupClosed")
|
||||||
object QRTextReceived : EventType("qrTextReceived")
|
object QRTextReceived : EventType("qrTextReceived")
|
||||||
object ClipboardTextReceived : EventType("clipboardTextReceived")
|
object ClipboardTextReceived : EventType("clipboardTextReceived")
|
||||||
|
object WriteAccessRequested : EventType("writeAccessRequested")
|
||||||
|
object ContactRequested : EventType("contactRequested")
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps
|
||||||
|
|
||||||
|
external interface RequestStatus {
|
||||||
|
val status: String
|
||||||
|
}
|
||||||
|
|
||||||
|
inline val RequestStatus.isCancelled: Boolean
|
||||||
|
get() = status == "cancelled"
|
||||||
|
|
||||||
|
inline val RequestStatus.isAllowed: Boolean
|
||||||
|
get() = status == "allowed"
|
||||||
|
|
||||||
|
inline val RequestStatus.isSent: Boolean
|
||||||
|
get() = status == "sent"
|
@ -1,9 +1,11 @@
|
|||||||
package dev.inmo.tgbotapi.webapps
|
package dev.inmo.tgbotapi.webapps
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
|
import dev.inmo.tgbotapi.webapps.cloud.CloudStorage
|
||||||
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback
|
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback
|
||||||
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
|
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
|
||||||
import dev.inmo.tgbotapi.webapps.popup.*
|
import dev.inmo.tgbotapi.webapps.popup.*
|
||||||
|
import kotlin.js.Json
|
||||||
|
|
||||||
external class WebApp {
|
external class WebApp {
|
||||||
val version: String
|
val version: String
|
||||||
@ -15,6 +17,7 @@ external class WebApp {
|
|||||||
|
|
||||||
val headerColor: HEXColor?
|
val headerColor: HEXColor?
|
||||||
fun setHeaderColor(color: Color.BackgroundColor)
|
fun setHeaderColor(color: Color.BackgroundColor)
|
||||||
|
fun setHeaderColor(color: Color.Hex)
|
||||||
val backgroundColor: HEXColor?
|
val backgroundColor: HEXColor?
|
||||||
fun setBackgroundColor(color: Color.Hex)
|
fun setBackgroundColor(color: Color.Hex)
|
||||||
fun setBackgroundColor(color: Color.BackgroundColor)
|
fun setBackgroundColor(color: Color.BackgroundColor)
|
||||||
@ -48,6 +51,9 @@ external class WebApp {
|
|||||||
@JsName("HapticFeedback")
|
@JsName("HapticFeedback")
|
||||||
val hapticFeedback: HapticFeedback
|
val hapticFeedback: HapticFeedback
|
||||||
|
|
||||||
|
@JsName("CloudStorage")
|
||||||
|
val cloudStorage: CloudStorage
|
||||||
|
|
||||||
internal fun onEvent(type: String, callback: () -> Unit)
|
internal fun onEvent(type: String, callback: () -> Unit)
|
||||||
@JsName("onEvent")
|
@JsName("onEvent")
|
||||||
internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit)
|
internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit)
|
||||||
@ -59,6 +65,10 @@ external class WebApp {
|
|||||||
internal fun onEventWithQRTextInfo(type: String, callback: (String) -> Boolean)
|
internal fun onEventWithQRTextInfo(type: String, callback: (String) -> Boolean)
|
||||||
@JsName("onEvent")
|
@JsName("onEvent")
|
||||||
internal fun onEventWithTextInfo(type: String, callback: (String) -> Unit)
|
internal fun onEventWithTextInfo(type: String, callback: (String) -> Unit)
|
||||||
|
@JsName("onEvent")
|
||||||
|
internal fun onEventWithWriteAccessRequested(type: String, callback: (RequestStatus) -> Unit)
|
||||||
|
@JsName("onEvent")
|
||||||
|
internal fun onEventWithContactRequested(type: String, callback: (RequestStatus) -> Unit)
|
||||||
|
|
||||||
fun offEvent(type: String, callback: () -> Unit)
|
fun offEvent(type: String, callback: () -> Unit)
|
||||||
@JsName("offEvent")
|
@JsName("offEvent")
|
||||||
@ -76,6 +86,9 @@ external class WebApp {
|
|||||||
fun openLink(url: String)
|
fun openLink(url: String)
|
||||||
fun openTelegramLink(url: String)
|
fun openTelegramLink(url: String)
|
||||||
fun openInvoice(url: String, callback: (InvoiceClosedInfo) -> Unit = definedExternally)
|
fun openInvoice(url: String, callback: (InvoiceClosedInfo) -> Unit = definedExternally)
|
||||||
|
|
||||||
|
fun requestWriteAccess(callback: ((Boolean) -> Unit)? = definedExternally)
|
||||||
|
fun requestContact(callback: ((Boolean) -> Unit)? = definedExternally)
|
||||||
}
|
}
|
||||||
|
|
||||||
val WebApp.colorScheme: ColorScheme
|
val WebApp.colorScheme: ColorScheme
|
||||||
@ -157,6 +170,30 @@ fun WebApp.onEvent(type: EventType.ClipboardTextReceived, eventHandler: TextRece
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
|
*/
|
||||||
|
fun WebApp.onEvent(type: EventType.WriteAccessRequested, eventHandler: WriteAccessRequestedHandler) = { it: RequestStatus ->
|
||||||
|
eventHandler(js("this").unsafeCast<WebApp>(), it.isAllowed)
|
||||||
|
}.also {
|
||||||
|
onEventWithWriteAccessRequested(
|
||||||
|
type.typeName,
|
||||||
|
callback = it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
|
*/
|
||||||
|
fun WebApp.onEvent(type: EventType.ContactRequested, eventHandler: ContactRequestedHandler) = { it: RequestStatus ->
|
||||||
|
eventHandler(js("this").unsafeCast<WebApp>(), it.isSent)
|
||||||
|
}.also {
|
||||||
|
onEventWithContactRequested(
|
||||||
|
type.typeName,
|
||||||
|
callback = it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The callback which should be used in case you want to turn off events handling
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
*/
|
*/
|
||||||
@ -193,6 +230,14 @@ fun WebApp.onQRTextReceived(eventHandler: QRTextReceivedEventHandler) = onEvent(
|
|||||||
* @return The callback which should be used in case you want to turn off events handling
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
*/
|
*/
|
||||||
fun WebApp.onClipboardTextReceived(eventHandler: TextReceivedEventHandler) = onEvent(EventType.ClipboardTextReceived, eventHandler)
|
fun WebApp.onClipboardTextReceived(eventHandler: TextReceivedEventHandler) = onEvent(EventType.ClipboardTextReceived, eventHandler)
|
||||||
|
/**
|
||||||
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
|
*/
|
||||||
|
fun WebApp.onWriteAccessRequested(eventHandler: WriteAccessRequestedHandler) = onEvent(EventType.WriteAccessRequested, eventHandler)
|
||||||
|
/**
|
||||||
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
|
*/
|
||||||
|
fun WebApp.onContactRequested(eventHandler: ContactRequestedHandler) = onEvent(EventType.ContactRequested, eventHandler)
|
||||||
|
|
||||||
fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData(
|
fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData(
|
||||||
initData,
|
initData,
|
||||||
|
@ -20,6 +20,10 @@ external interface WebAppUser {
|
|||||||
val is_premium: Boolean?
|
val is_premium: Boolean?
|
||||||
@JsName(photoUrlField)
|
@JsName(photoUrlField)
|
||||||
val photoUrl: String?
|
val photoUrl: String?
|
||||||
|
@JsName(addedToAttachmentMenuField)
|
||||||
|
val addedToAttachmentMenu: Boolean?
|
||||||
|
@JsName(allowsWriteToPMField)
|
||||||
|
val allowsWriteToPM: Boolean?
|
||||||
}
|
}
|
||||||
|
|
||||||
val WebAppUser.isPremium
|
val WebAppUser.isPremium
|
||||||
|
@ -0,0 +1,139 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps.cloud
|
||||||
|
|
||||||
|
import kotlin.js.Json
|
||||||
|
|
||||||
|
external interface CloudStorage {
|
||||||
|
fun setItem(
|
||||||
|
key: CloudStorageKey,
|
||||||
|
value: CloudStorageValue,
|
||||||
|
callback: (e: Any?, success: Boolean?) -> Unit = definedExternally
|
||||||
|
): CloudStorage
|
||||||
|
fun getItem(
|
||||||
|
key: CloudStorageKey,
|
||||||
|
callback: (e: Any?, value: CloudStorageValue?) -> Unit
|
||||||
|
): CloudStorage
|
||||||
|
fun getItems(
|
||||||
|
key: Array<CloudStorageKey>,
|
||||||
|
callback: (e: Any?, values: Array<CloudStorageValue>?) -> Unit
|
||||||
|
): CloudStorage
|
||||||
|
fun removeItem(
|
||||||
|
key: CloudStorageKey,
|
||||||
|
callback: (e: Any?, success: Boolean?) -> Unit
|
||||||
|
): CloudStorage
|
||||||
|
fun removeItems(
|
||||||
|
key: Array<CloudStorageKey>,
|
||||||
|
callback: (e: Any?, success: Boolean?) -> Unit
|
||||||
|
): CloudStorage
|
||||||
|
fun getKeys(
|
||||||
|
callback: (e: Any?, success: Array<CloudStorageKey>?) -> Unit
|
||||||
|
): CloudStorage
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T> resultsToResult(e: Any?, v: T?): Result<T> = when {
|
||||||
|
e != null -> Result.failure(IllegalStateException(JSON.stringify(e)))
|
||||||
|
v != null -> Result.success(v)
|
||||||
|
else -> Result.failure(IllegalStateException("Both value and e"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CloudStorage.set(
|
||||||
|
key: String,
|
||||||
|
value: String,
|
||||||
|
callback: (result: Result<Boolean>) -> Unit = {}
|
||||||
|
) = setItem(CloudStorageKey(key), CloudStorageValue(value)) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.get(
|
||||||
|
key: CloudStorageKey,
|
||||||
|
callback: (result: Result<CloudStorageValue>) -> Unit
|
||||||
|
) = getItem(key) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.get(
|
||||||
|
key: String,
|
||||||
|
callback: (result: Result<CloudStorageValue>) -> Unit
|
||||||
|
) = get(CloudStorageKey(key), callback)
|
||||||
|
|
||||||
|
fun CloudStorage.get(
|
||||||
|
keys: Array<CloudStorageKey>,
|
||||||
|
callback: (result: Result<Array<CloudStorageValue>>) -> Unit
|
||||||
|
) = getItems(
|
||||||
|
keys
|
||||||
|
) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.get(
|
||||||
|
keys: Array<String>,
|
||||||
|
callback: (result: Result<Array<CloudStorageValue>>) -> Unit
|
||||||
|
) = get(
|
||||||
|
Array(keys.size) {
|
||||||
|
CloudStorageKey(keys[it])
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
|
||||||
|
fun CloudStorage.get(
|
||||||
|
key: String,
|
||||||
|
key2: String,
|
||||||
|
vararg otherKeys: String,
|
||||||
|
callback: (result: Result<Array<CloudStorageValue>>) -> Unit
|
||||||
|
) = get(
|
||||||
|
arrayOf(key, key2) + otherKeys,
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
|
||||||
|
fun CloudStorage.remove(
|
||||||
|
key: CloudStorageKey,
|
||||||
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
|
) = removeItem(key) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.remove(
|
||||||
|
key: String,
|
||||||
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
|
) = remove(CloudStorageKey(key), callback)
|
||||||
|
|
||||||
|
fun CloudStorage.remove(
|
||||||
|
keys: Array<CloudStorageKey>,
|
||||||
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
|
) = removeItems(
|
||||||
|
keys
|
||||||
|
) { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.remove(
|
||||||
|
keys: Array<String>,
|
||||||
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
|
) = remove(
|
||||||
|
Array(keys.size) {
|
||||||
|
CloudStorageKey(keys[it])
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
|
||||||
|
fun CloudStorage.remove(
|
||||||
|
key: String,
|
||||||
|
key2: String,
|
||||||
|
vararg otherKeys: String,
|
||||||
|
callback: (result: Result<Boolean>) -> Unit
|
||||||
|
) = remove(
|
||||||
|
arrayOf(key, key2) + otherKeys,
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
|
||||||
|
fun CloudStorage.keys(
|
||||||
|
callback: (result: Result<Array<CloudStorageKey>>) -> Unit
|
||||||
|
) = getKeys { e, v -> callback(resultsToResult(e, v)) }
|
||||||
|
|
||||||
|
fun CloudStorage.getAll(callback: (result: Result<Map<CloudStorageKey, CloudStorageValue>>) -> Unit) = keys {
|
||||||
|
it.onSuccess { keys ->
|
||||||
|
console.log(keys)
|
||||||
|
get(keys) {
|
||||||
|
it.onSuccess { values ->
|
||||||
|
console.log(values)
|
||||||
|
val resultMap = keys.withIndex().mapNotNull { (i, it) ->
|
||||||
|
it to (values.getOrNull(i) ?: return@mapNotNull null)
|
||||||
|
}.toMap()
|
||||||
|
callback(Result.success(resultMap))
|
||||||
|
}.onFailure {
|
||||||
|
callback(Result.failure(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.onFailure {
|
||||||
|
callback(Result.failure(it))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps.cloud
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.cloudStorageKeyRegex
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
value class CloudStorageKey(val key: String) {
|
||||||
|
init {
|
||||||
|
require(key.matches(cloudStorageKeyRegex)) {
|
||||||
|
"'$key' must pass $cloudStorageKeyRegex in case you wish to use it as key for cloud storage operations"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps.cloud
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.cloudStorageKeyRegex
|
||||||
|
import dev.inmo.tgbotapi.types.cloudStorageValueRegex
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
value class CloudStorageValue(val value: String) {
|
||||||
|
init {
|
||||||
|
require(value.matches(cloudStorageValueRegex)) {
|
||||||
|
"'$value' must pass $cloudStorageValueRegex in case you wish to use it as key for cloud storage operations"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user