mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
commit
7f5cd0567b
@ -1,5 +1,12 @@
|
||||
# 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
|
||||
|
||||
* `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) |
|
||||
|:----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
|
||||
|
@ -6,4 +6,4 @@ kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
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.requests.bot.SetMyDefaultAdministratorRights
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatAdministratorRightsImpl
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||
|
||||
suspend fun TelegramBot.setMyDefaultAdministratorRights(
|
||||
rights: ChatAdministratorRightsImpl,
|
||||
rights: ChatCommonAdministratorRights,
|
||||
forChannels: Boolean? = null
|
||||
) = execute(SetMyDefaultAdministratorRights(rights, forChannels))
|
||||
|
||||
suspend fun TelegramBot.setMyDefaultAdministratorRightsForChannels(
|
||||
rights: ChatAdministratorRightsImpl
|
||||
rights: ChatCommonAdministratorRights
|
||||
) = setMyDefaultAdministratorRights(rights, forChannels = true)
|
||||
|
||||
suspend fun TelegramBot.setMyDefaultAdministratorRightsForGroupsAndSupergroups(
|
||||
rights: ChatAdministratorRightsImpl
|
||||
rights: ChatCommonAdministratorRights
|
||||
) = 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
|
||||
|
||||
import dev.inmo.micro_utils.common.Warning
|
||||
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.*
|
||||
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
|
||||
@Warning("This method is too common. Use it with caution")
|
||||
suspend fun TelegramBot.promoteChatMember(
|
||||
chatId: ChatIdentifier,
|
||||
userId: UserId,
|
||||
@ -24,27 +23,34 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canPromoteMembers: Boolean? = null,
|
||||
canManageVideoChats: Boolean? = null,
|
||||
canManageChat: Boolean? = null,
|
||||
canManageTopics: Boolean? = null
|
||||
canManageTopics: Boolean? = null,
|
||||
canPostStories: Boolean? = null,
|
||||
canEditStories: Boolean? = null,
|
||||
canDeleteStories: Boolean? = null
|
||||
) = execute(
|
||||
PromoteChatMember(
|
||||
chatId,
|
||||
userId,
|
||||
untilDate,
|
||||
isAnonymous,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
canManageVideoChats,
|
||||
canManageChat,
|
||||
canManageTopics
|
||||
chatId = chatId,
|
||||
userId = userId,
|
||||
untilDate = untilDate,
|
||||
isAnonymous = isAnonymous,
|
||||
canChangeInfo = canChangeInfo,
|
||||
canPostMessages = canPostMessages,
|
||||
canEditMessages = canEditMessages,
|
||||
canDeleteMessages = canDeleteMessages,
|
||||
canInviteUsers = canInviteUsers,
|
||||
canRestrictMembers = canRestrictMembers,
|
||||
canPinMessages = canPinMessages,
|
||||
canPromoteMembers = canPromoteMembers,
|
||||
canManageVideoChats = canManageVideoChats,
|
||||
canManageChat = canManageChat,
|
||||
canManageTopics = canManageTopics,
|
||||
canPostStories = canPostStories,
|
||||
canEditStories = canEditStories,
|
||||
canDeleteStories = canDeleteStories
|
||||
)
|
||||
)
|
||||
|
||||
@Warning("This method is too common. Use it with caution")
|
||||
suspend fun TelegramBot.promoteChatMember(
|
||||
chat: PublicChat,
|
||||
userId: UserId,
|
||||
@ -60,25 +66,32 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canPromoteMembers: Boolean? = null,
|
||||
canManageVideoChats: Boolean? = null,
|
||||
canManageChat: Boolean? = null,
|
||||
canManageTopics: Boolean? = null
|
||||
canManageTopics: Boolean? = null,
|
||||
canPostStories: Boolean? = null,
|
||||
canEditStories: Boolean? = null,
|
||||
canDeleteStories: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chat.id,
|
||||
userId,
|
||||
untilDate,
|
||||
isAnonymous,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
canManageVideoChats,
|
||||
canManageChat,
|
||||
canManageTopics
|
||||
untilDate = untilDate,
|
||||
isAnonymous = isAnonymous,
|
||||
canChangeInfo = canChangeInfo,
|
||||
canPostMessages = canPostMessages,
|
||||
canEditMessages = canEditMessages,
|
||||
canDeleteMessages = canDeleteMessages,
|
||||
canInviteUsers = canInviteUsers,
|
||||
canRestrictMembers = canRestrictMembers,
|
||||
canPinMessages = canPinMessages,
|
||||
canPromoteMembers = canPromoteMembers,
|
||||
canManageVideoChats = canManageVideoChats,
|
||||
canManageChat = canManageChat,
|
||||
canManageTopics = canManageTopics,
|
||||
canPostStories = canPostStories,
|
||||
canEditStories = canEditStories,
|
||||
canDeleteStories = canDeleteStories
|
||||
)
|
||||
|
||||
@Warning("This method is too common. Use it with caution")
|
||||
suspend fun TelegramBot.promoteChatMember(
|
||||
chatId: IdChatIdentifier,
|
||||
user: User,
|
||||
@ -94,25 +107,32 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canPromoteMembers: Boolean? = null,
|
||||
canManageVideoChats: Boolean? = null,
|
||||
canManageChat: Boolean? = null,
|
||||
canManageTopics: Boolean? = null
|
||||
canManageTopics: Boolean? = null,
|
||||
canPostStories: Boolean? = null,
|
||||
canEditStories: Boolean? = null,
|
||||
canDeleteStories: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chatId,
|
||||
user.id,
|
||||
untilDate,
|
||||
isAnonymous,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
canManageVideoChats,
|
||||
canManageChat,
|
||||
canManageTopics
|
||||
untilDate = untilDate,
|
||||
isAnonymous = isAnonymous,
|
||||
canChangeInfo = canChangeInfo,
|
||||
canPostMessages = canPostMessages,
|
||||
canEditMessages = canEditMessages,
|
||||
canDeleteMessages = canDeleteMessages,
|
||||
canInviteUsers = canInviteUsers,
|
||||
canRestrictMembers = canRestrictMembers,
|
||||
canPinMessages = canPinMessages,
|
||||
canPromoteMembers = canPromoteMembers,
|
||||
canManageVideoChats = canManageVideoChats,
|
||||
canManageChat = canManageChat,
|
||||
canManageTopics = canManageTopics,
|
||||
canPostStories = canPostStories,
|
||||
canEditStories = canEditStories,
|
||||
canDeleteStories = canDeleteStories
|
||||
)
|
||||
|
||||
@Warning("This method is too common. Use it with caution")
|
||||
suspend fun TelegramBot.promoteChatMember(
|
||||
chat: PublicChat,
|
||||
user: User,
|
||||
@ -128,21 +148,27 @@ suspend fun TelegramBot.promoteChatMember(
|
||||
canPromoteMembers: Boolean? = null,
|
||||
canManageVideoChats: Boolean? = null,
|
||||
canManageChat: Boolean? = null,
|
||||
canManageTopics: Boolean? = null
|
||||
canManageTopics: Boolean? = null,
|
||||
canPostStories: Boolean? = null,
|
||||
canEditStories: Boolean? = null,
|
||||
canDeleteStories: Boolean? = null
|
||||
) = promoteChatMember(
|
||||
chat.id,
|
||||
user.id,
|
||||
untilDate,
|
||||
isAnonymous,
|
||||
canChangeInfo,
|
||||
canPostMessages,
|
||||
canEditMessages,
|
||||
canDeleteMessages,
|
||||
canInviteUsers,
|
||||
canRestrictMembers,
|
||||
canPinMessages,
|
||||
canPromoteMembers,
|
||||
canManageVideoChats,
|
||||
canManageChat,
|
||||
canManageTopics
|
||||
untilDate = untilDate,
|
||||
isAnonymous = isAnonymous,
|
||||
canChangeInfo = canChangeInfo,
|
||||
canPostMessages = canPostMessages,
|
||||
canEditMessages = canEditMessages,
|
||||
canDeleteMessages = canDeleteMessages,
|
||||
canInviteUsers = canInviteUsers,
|
||||
canRestrictMembers = canRestrictMembers,
|
||||
canPinMessages = canPinMessages,
|
||||
canPromoteMembers = canPromoteMembers,
|
||||
canManageVideoChats = canManageVideoChats,
|
||||
canManageChat = canManageChat,
|
||||
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,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = 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(
|
||||
initRequest: Request<*>? = null,
|
||||
|
@ -171,6 +171,22 @@ suspend fun BehaviourContext.waitWriteAccessAllowedEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = 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(
|
||||
initRequest: Request<*>? = null,
|
||||
|
@ -655,10 +655,90 @@ suspend fun <BC : BehaviourContext> BC.onGeneralForumTopicUnhidden(
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onWriteAccessAllowed(
|
||||
initialFilter: SimpleFilter<SupergroupEventMessage<WriteAccessAllowed>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<WriteAccessAllowed>, Update>? = MessageFilterByChat,
|
||||
initialFilter: SimpleFilter<ChatEventMessage<WriteAccessAllowed>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<WriteAccessAllowed>, Update>? = MessageFilterByChat,
|
||||
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)
|
||||
|
||||
|
||||
|
@ -2,14 +2,14 @@ package dev.inmo.tgbotapi.requests.bot
|
||||
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
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.builtins.serializer
|
||||
|
||||
@Serializable
|
||||
class SetMyDefaultAdministratorRights(
|
||||
@SerialName(rightsField)
|
||||
val rights: ChatAdministratorRightsImpl,
|
||||
val rights: ChatCommonAdministratorRights,
|
||||
@SerialName(forChannelsField)
|
||||
val forChannels: Boolean? = null
|
||||
) : SimpleRequest<Boolean> {
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.requests.chat.abstracts.ChatMemberRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
@ -7,6 +8,7 @@ import kotlinx.serialization.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
@Serializable
|
||||
@Warning("This method is too common. Use it with caution")
|
||||
data class PromoteChatMember(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@ -37,7 +39,13 @@ data class PromoteChatMember(
|
||||
@SerialName(canManageChatField)
|
||||
private val canManageChat: Boolean? = null,
|
||||
@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 {
|
||||
override fun method(): String = "promoteChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
@ -45,3 +53,109 @@ data class PromoteChatMember(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
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
|
||||
|
||||
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
|
||||
val telegramInlineModeGifPermittedMimeTypes by lazy {
|
||||
listOf(
|
||||
@ -210,6 +215,7 @@ const val firstNameField = "first_name"
|
||||
const val lastNameField = "last_name"
|
||||
const val languageCodeField = "language_code"
|
||||
const val addedToAttachmentMenuField = "added_to_attachment_menu"
|
||||
const val allowsWriteToPMField = "allows_write_to_pm"
|
||||
const val isPremiumField = "is_premium"
|
||||
const val hasPrivateForwardsField = "has_private_forwards"
|
||||
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 isAnonymousField = "is_anonymous"
|
||||
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 hasSpoilerField = "has_spoiler"
|
||||
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.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.chatIsChannelField
|
||||
import dev.inmo.tgbotapi.types.chatIsCreatedField
|
||||
@ -30,9 +30,9 @@ data class KeyboardButtonRequestChat(
|
||||
@SerialName(chatIsCreatedField)
|
||||
val isOwnedBy: Boolean? = null,
|
||||
@SerialName(userAdministratorRightsField)
|
||||
val userRightsInChat: ChatAdministratorRights? = null,
|
||||
val userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
@SerialName(botAdministratorRightsField)
|
||||
val botRightsInChat: ChatAdministratorRights? = null,
|
||||
val botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
@SerialName(botIsMemberField)
|
||||
val botIsMember: Boolean? = null
|
||||
) {
|
||||
@ -41,8 +41,8 @@ data class KeyboardButtonRequestChat(
|
||||
requestId: RequestId,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = KeyboardButtonRequestChat(
|
||||
requestId = requestId,
|
||||
@ -60,8 +60,8 @@ data class KeyboardButtonRequestChat(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = KeyboardButtonRequestChat(
|
||||
requestId = requestId,
|
||||
|
@ -1,8 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.buttons.reply
|
||||
|
||||
import dev.inmo.tgbotapi.types.buttons.*
|
||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.*
|
||||
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.webapps.WebAppInfo
|
||||
|
||||
@ -120,8 +119,8 @@ inline fun requestChatReplyButton(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botIsMember: Boolean = false
|
||||
) = requestChatReplyButton(
|
||||
text,
|
||||
@ -145,8 +144,8 @@ inline fun requestChannelReplyButton(
|
||||
requestId: RequestId,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botIsMember: Boolean = false
|
||||
) = requestChatReplyButton(
|
||||
text,
|
||||
@ -170,8 +169,8 @@ inline fun requestChannelReplyButton(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = requestChatReplyButton(
|
||||
text,
|
||||
|
@ -35,9 +35,16 @@ data class AdministratorChatMemberImpl(
|
||||
@SerialName(customTitleField)
|
||||
override val customTitle: String? = null,
|
||||
@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 {
|
||||
@SerialName(statusField)
|
||||
@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 canPostMessages: 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
|
||||
|
||||
@Serializable
|
||||
data class ChatAdministratorRightsImpl(
|
||||
data class ChatCommonAdministratorRights(
|
||||
@SerialName(canChangeInfoField)
|
||||
override val canChangeInfo: Boolean = false,
|
||||
@SerialName(canPostMessagesField)
|
||||
@ -29,5 +29,20 @@ data class ChatAdministratorRightsImpl(
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@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
|
||||
|
||||
@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.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
@ -13,7 +14,18 @@ import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
@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
|
||||
object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
@ -21,15 +33,14 @@ object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
|
||||
override fun deserialize(decoder: Decoder): ChatMember {
|
||||
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")) {
|
||||
"creator" -> nonstrictJsonFormat.decodeFromJsonElement(OwnerChatMember.serializer(), json)
|
||||
"administrator" -> nonstrictJsonFormat.decodeFromJsonElement(AdministratorChatMemberImpl.serializer(), json)
|
||||
"member" -> nonstrictJsonFormat.decodeFromJsonElement(MemberChatMemberImpl.serializer(), json)
|
||||
"restricted" -> nonstrictJsonFormat.decodeFromJsonElement(RestrictedChatMember.serializer(), json)
|
||||
"left" -> nonstrictJsonFormat.decodeFromJsonElement(LeftChatMemberImpl.serializer(), json)
|
||||
"kicked" -> nonstrictJsonFormat.decodeFromJsonElement(KickedChatMember.serializer(), json)
|
||||
else -> error("Unknown type of chat member in json: $json")
|
||||
}
|
||||
val status = json[statusField] ?.jsonPrimitive ?.content ?: error("Status field of chat member must be specified, but incoming json contains next: $json")
|
||||
return ChatMember.Status.values().firstNotNullOfOrNull {
|
||||
if (it.status == status) {
|
||||
nonstrictJsonFormat.decodeFromJsonElement(it.deserializationStrategy, json)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: error("Unknown type of chat member in json: $json")
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatMember) {
|
||||
|
@ -13,5 +13,6 @@ data class KickedChatMember(
|
||||
) : BannedChatMember {
|
||||
@SerialName(statusField)
|
||||
@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.*
|
||||
|
||||
@Serializable
|
||||
data class LeftChatMemberImpl(@SerialName(userField) override val user: User) : LeftChatMember {
|
||||
data class LeftChatMemberImpl(
|
||||
@SerialName(userField)
|
||||
override val user: User
|
||||
) : LeftChatMember {
|
||||
@SerialName(statusField)
|
||||
@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.*
|
||||
|
||||
@Serializable
|
||||
data class MemberChatMemberImpl(@SerialName(userField) override val user: User) : MemberChatMember {
|
||||
data class MemberChatMemberImpl(
|
||||
@SerialName(userField)
|
||||
override val user: User
|
||||
) : MemberChatMember {
|
||||
@SerialName(statusField)
|
||||
@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
|
||||
@Transient
|
||||
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)
|
||||
@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 {
|
||||
@SerialName(statusField)
|
||||
@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
|
||||
|
||||
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.PrivateEvent
|
||||
import dev.inmo.tgbotapi.types.webAppNameField
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable
|
||||
data class WriteAccessAllowed(
|
||||
@SerialName(webAppNameField)
|
||||
val webAppName: String? = null
|
||||
) : ForumEvent
|
||||
@Serializable(WriteAccessAllowed.Companion::class)
|
||||
sealed interface WriteAccessAllowed : PrivateEvent, ForumEvent {
|
||||
val webAppName: String?
|
||||
get() = null
|
||||
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
|
||||
@JvmInline
|
||||
value class RequestId(
|
||||
val int: Int
|
||||
val uShort: UShort
|
||||
) {
|
||||
constructor(int: Int) : this(int.toUShort())
|
||||
companion object {
|
||||
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.reply.requestChatReplyButton
|
||||
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.webapps.WebAppInfo
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
@ -220,8 +220,8 @@ inline fun ReplyKeyboardRowBuilder.requestChatButton(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = requestChatButton(
|
||||
text,
|
||||
@ -248,8 +248,8 @@ inline fun ReplyKeyboardRowBuilder.requestChannelButton(
|
||||
requestId: RequestId,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = requestChatButton(
|
||||
text,
|
||||
@ -275,8 +275,8 @@ inline fun ReplyKeyboardRowBuilder.requestGroupButton(
|
||||
isForum: Boolean? = null,
|
||||
isPublic: Boolean? = null,
|
||||
isOwnedBy: Boolean? = null,
|
||||
userRightsInChat: ChatAdministratorRights? = null,
|
||||
botRightsInChat: ChatAdministratorRights? = null,
|
||||
userRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botRightsInChat: ChatCommonAdministratorRights? = null,
|
||||
botIsMember: Boolean? = null
|
||||
) = requestChatButton(
|
||||
text,
|
||||
|
@ -8,7 +8,9 @@ sealed interface Color {
|
||||
value class BackgroundColor(override val value: String) : Color
|
||||
|
||||
@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 {
|
||||
val BackgroundColor = BackgroundColor("bg_color")
|
||||
|
@ -8,3 +8,5 @@ typealias InvoiceClosedEventHandler = WebApp.(InvoiceClosedInfo) -> Unit
|
||||
typealias PopupClosedEventHandler = WebApp.(String?) -> Unit
|
||||
typealias QRTextReceivedEventHandler = WebApp.(String) -> Boolean
|
||||
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 QRTextReceived : EventType("qrTextReceived")
|
||||
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
|
||||
|
||||
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.invoice.InvoiceClosedInfo
|
||||
import dev.inmo.tgbotapi.webapps.popup.*
|
||||
import kotlin.js.Json
|
||||
|
||||
external class WebApp {
|
||||
val version: String
|
||||
@ -15,6 +17,7 @@ external class WebApp {
|
||||
|
||||
val headerColor: HEXColor?
|
||||
fun setHeaderColor(color: Color.BackgroundColor)
|
||||
fun setHeaderColor(color: Color.Hex)
|
||||
val backgroundColor: HEXColor?
|
||||
fun setBackgroundColor(color: Color.Hex)
|
||||
fun setBackgroundColor(color: Color.BackgroundColor)
|
||||
@ -48,6 +51,9 @@ external class WebApp {
|
||||
@JsName("HapticFeedback")
|
||||
val hapticFeedback: HapticFeedback
|
||||
|
||||
@JsName("CloudStorage")
|
||||
val cloudStorage: CloudStorage
|
||||
|
||||
internal fun onEvent(type: String, callback: () -> Unit)
|
||||
@JsName("onEvent")
|
||||
internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit)
|
||||
@ -59,6 +65,10 @@ external class WebApp {
|
||||
internal fun onEventWithQRTextInfo(type: String, callback: (String) -> Boolean)
|
||||
@JsName("onEvent")
|
||||
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)
|
||||
@JsName("offEvent")
|
||||
@ -76,6 +86,9 @@ external class WebApp {
|
||||
fun openLink(url: String)
|
||||
fun openTelegramLink(url: String)
|
||||
fun openInvoice(url: String, callback: (InvoiceClosedInfo) -> Unit = definedExternally)
|
||||
|
||||
fun requestWriteAccess(callback: ((Boolean) -> Unit)? = definedExternally)
|
||||
fun requestContact(callback: ((Boolean) -> Unit)? = definedExternally)
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
@ -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
|
||||
*/
|
||||
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(
|
||||
initData,
|
||||
|
@ -20,6 +20,10 @@ external interface WebAppUser {
|
||||
val is_premium: Boolean?
|
||||
@JsName(photoUrlField)
|
||||
val photoUrl: String?
|
||||
@JsName(addedToAttachmentMenuField)
|
||||
val addedToAttachmentMenu: Boolean?
|
||||
@JsName(allowsWriteToPMField)
|
||||
val allowsWriteToPM: Boolean?
|
||||
}
|
||||
|
||||
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