From 4f0de376abb214ec21053e6c1f6aad781fecced6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 19 Feb 2022 23:02:58 +0600 Subject: [PATCH] MentionTextSource#username --- CHANGELOG.md | 3 +++ .../types/MessageEntity/textsources/MentionTextSource.kt | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e97c743f..49be0747ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.38.6 +* `Core`: + * New member of `MentionTextSource` - `username` + ## 0.38.5 * `Common`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index 471c316a28..b0a5d8db3f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources +import dev.inmo.tgbotapi.types.Username import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.internal.* @@ -23,6 +24,7 @@ data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo override val markdown: String by lazy { source.mentionMarkdown() } override val markdownV2: String by lazy { mentionMarkdownV2() } override val html: String by lazy { mentionHTML() } + val username: Username = Username(source) init { if (!source.startsWith("@")) { @@ -42,3 +44,6 @@ inline fun mention(vararg parts: TextSource) = mention(parts.toList()) @Suppress("NOTHING_TO_INLINE") inline fun mention(whoToMention: String) = mention(regular(whoToMention)) +@Suppress("NOTHING_TO_INLINE") +inline fun mention(whoToMention: Username) = mention(whoToMention.username.dropWhile { it == '@' }) +