diff --git a/GetMeBot/src/main/kotlin/GetMeBot.kt b/GetMeBot/src/main/kotlin/GetMeBot.kt index c5917cd..460b48c 100644 --- a/GetMeBot/src/main/kotlin/GetMeBot.kt +++ b/GetMeBot/src/main/kotlin/GetMeBot.kt @@ -5,6 +5,7 @@ import dev.inmo.kslog.common.filter.filtered import dev.inmo.kslog.common.setDefaultKSLog import dev.inmo.tgbotapi.bot.ktor.telegramBot import dev.inmo.tgbotapi.extensions.api.bot.getMe +import dev.inmo.tgbotapi.extensions.api.chat.get.getChat import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog /** @@ -12,13 +13,19 @@ import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog */ suspend fun main(vararg args: String) { val botToken = args.first() + val isDebug = args.getOrNull(1) == "debug" + + if (isDebug) { + setDefaultKSLog( + KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> + println(defaultMessageFormatter(level, tag, message, throwable)) + } + ) + } - setDefaultKSLog( - KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> - println(defaultMessageFormatter(level, tag, message, throwable)) - } - ) val bot = telegramBot(botToken) - println(bot.getMe()) + val me = bot.getMe() + println(me) + println(bot.getChat(me)) } diff --git a/LinkPreviewsBot/README.md b/LinkPreviewsBot/README.md new file mode 100644 index 0000000..c5ae135 --- /dev/null +++ b/LinkPreviewsBot/README.md @@ -0,0 +1,9 @@ +# ReactionsInfoBot + +This bot will resend messages with links with all variants of `LinkPreviewOptions` + +## Launch + +```bash +../gradlew run --args="BOT_TOKEN" +``` diff --git a/LinkPreviewsBot/build.gradle b/LinkPreviewsBot/build.gradle new file mode 100644 index 0000000..a699082 --- /dev/null +++ b/LinkPreviewsBot/build.gradle @@ -0,0 +1,21 @@ +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' +apply plugin: 'application' + +mainClassName="LinkPreviewsBotKt" + + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + implementation "dev.inmo:tgbotapi:$telegram_bot_api_version" +} diff --git a/LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt b/LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt new file mode 100644 index 0000000..cc85073 --- /dev/null +++ b/LinkPreviewsBot/src/main/kotlin/LinkPreviewsBot.kt @@ -0,0 +1,93 @@ +import dev.inmo.kslog.common.KSLog +import dev.inmo.kslog.common.LogLevel +import dev.inmo.kslog.common.defaultMessageFormatter +import dev.inmo.kslog.common.setDefaultKSLog +import dev.inmo.tgbotapi.bot.ktor.telegramBot +import dev.inmo.tgbotapi.extensions.api.chat.get.getChat +import dev.inmo.tgbotapi.extensions.api.send.copyMessage +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.send +import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionUpdatedByUser +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage +import dev.inmo.tgbotapi.extensions.utils.textLinkTextSourceOrNull +import dev.inmo.tgbotapi.extensions.utils.uRLTextSourceOrNull +import dev.inmo.tgbotapi.extensions.utils.withContentOrNull +import dev.inmo.tgbotapi.types.LinkPreviewOptions +import dev.inmo.tgbotapi.types.chat.ExtendedChat +import dev.inmo.tgbotapi.types.message.content.TextContent +import dev.inmo.tgbotapi.types.message.content.TextedContent +import dev.inmo.tgbotapi.types.reactions.Reaction +import dev.inmo.tgbotapi.utils.customEmoji +import dev.inmo.tgbotapi.utils.regular + +/** + * This bot will reply with the same + */ +suspend fun main(vararg args: String) { + val botToken = args.first() + val isDebug = args.getOrNull(1) == "debug" + + if (isDebug) { + setDefaultKSLog( + KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> + println(defaultMessageFormatter(level, tag, message, throwable)) + } + ) + } + + val bot = telegramBot(botToken) + + bot.buildBehaviourWithLongPolling { + onContentMessage { + val url = it.withContentOrNull() ?.let { + it.content.textSources.firstNotNullOfOrNull { + it.textLinkTextSourceOrNull() ?.url ?: it.uRLTextSourceOrNull() ?.source + } + } ?: null.apply { + reply(it) { + regular("I am support only content with text contains url only") + } + } ?: return@onContentMessage + it.withContentOrNull() ?.let { + send( + it.chat, + it.content.textSources, + linkPreviewOptions = LinkPreviewOptions.Disabled + ) + send( + it.chat, + it.content.textSources, + linkPreviewOptions = LinkPreviewOptions.Large(url, showAboveText = true) + ) + send( + it.chat, + it.content.textSources, + linkPreviewOptions = LinkPreviewOptions.Large(url, showAboveText = false) + ) + send( + it.chat, + it.content.textSources, + linkPreviewOptions = LinkPreviewOptions.Small(url, showAboveText = true) + ) + send( + it.chat, + it.content.textSources, + linkPreviewOptions = LinkPreviewOptions.Small(url, showAboveText = false) + ) + send( + it.chat, + it.content.textSources, + linkPreviewOptions = LinkPreviewOptions.Default(url, showAboveText = true) + ) + send( + it.chat, + it.content.textSources, + linkPreviewOptions = LinkPreviewOptions.Default(url, showAboveText = false) + ) + } + } + }.join() +} diff --git a/PollsBot/src/main/kotlin/PollsBot.kt b/PollsBot/src/main/kotlin/PollsBot.kt index f489fc4..1587ecc 100644 --- a/PollsBot/src/main/kotlin/PollsBot.kt +++ b/PollsBot/src/main/kotlin/PollsBot.kt @@ -14,6 +14,7 @@ import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.PollIdentifier +import dev.inmo.tgbotapi.types.ReplyParameters import dev.inmo.tgbotapi.types.chat.* import dev.inmo.tgbotapi.types.chat.GroupChat import dev.inmo.tgbotapi.types.chat.PrivateChat @@ -54,7 +55,7 @@ suspend fun main(vararg args: String) { it.toString() }, isAnonymous = true, - replyToMessageId = it.messageId + replyParameters = ReplyParameters(it) ) pollToChatMutex.withLock { pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id @@ -69,7 +70,7 @@ suspend fun main(vararg args: String) { it.toString() }, isAnonymous = false, - replyToMessageId = it.messageId + replyParameters = ReplyParameters(it) ) pollToChatMutex.withLock { pollToChat[sentPoll.content.poll.id] = sentPoll.chat.id diff --git a/ReactionsInfoBot/README.md b/ReactionsInfoBot/README.md new file mode 100644 index 0000000..72b17bf --- /dev/null +++ b/ReactionsInfoBot/README.md @@ -0,0 +1,9 @@ +# ReactionsInfoBot + +This bot will send info about user reactions in his PM with reply to message user reacted to + +## Launch + +```bash +../gradlew run --args="BOT_TOKEN" +``` diff --git a/ReactionsInfoBot/build.gradle b/ReactionsInfoBot/build.gradle new file mode 100644 index 0000000..f0554ac --- /dev/null +++ b/ReactionsInfoBot/build.gradle @@ -0,0 +1,21 @@ +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin' +apply plugin: 'application' + +mainClassName="ReactionsInfoBotKt" + + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + implementation "dev.inmo:tgbotapi:$telegram_bot_api_version" +} diff --git a/ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt b/ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt new file mode 100644 index 0000000..78d93f6 --- /dev/null +++ b/ReactionsInfoBot/src/main/kotlin/ReactionsInfoBot.kt @@ -0,0 +1,68 @@ +import dev.inmo.kslog.common.KSLog +import dev.inmo.kslog.common.LogLevel +import dev.inmo.kslog.common.defaultMessageFormatter +import dev.inmo.kslog.common.setDefaultKSLog +import dev.inmo.tgbotapi.bot.ktor.telegramBot +import dev.inmo.tgbotapi.extensions.api.chat.get.getChat +import dev.inmo.tgbotapi.extensions.api.send.reply +import dev.inmo.tgbotapi.extensions.api.send.setMessageReaction +import dev.inmo.tgbotapi.extensions.api.send.setMessageReactions +import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionUpdatedByUser +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onChatMessageReactionsCountUpdated +import dev.inmo.tgbotapi.types.chat.ExtendedChat +import dev.inmo.tgbotapi.types.reactions.Reaction +import dev.inmo.tgbotapi.utils.customEmoji +import dev.inmo.tgbotapi.utils.regular + +/** + * This bot will send info about user reactions in his PM with reply to message user reacted to + */ +suspend fun main(vararg args: String) { + val botToken = args.first() + val isDebug = args.getOrNull(1) == "debug" + + if (isDebug) { + setDefaultKSLog( + KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> + println(defaultMessageFormatter(level, tag, message, throwable)) + } + ) + } + + val bot = telegramBot(botToken) + + bot.buildBehaviourWithLongPolling { + onChatMessageReactionUpdatedByUser { + setMessageReaction( + it.chat.id, + it.messageId, + "✍" + ) + val replyResult = reply( + it.chat.id, + it.messageId, + replyInChat = it.reactedUser.id + ) { + regular("Current reactions for message in reply:\n") + it.new.forEach { + when (it) { + is Reaction.CustomEmoji -> regular("• ") + customEmoji(it.customEmojiId) + regular("(customEmojiId: ${it.customEmojiId})") + is Reaction.Emoji -> regular("• ${it.emoji}") + is Reaction.Unknown -> regular("• Unknown emoji ($it)") + } + regular("\n") + } + } + setMessageReaction( + it.chat.id, + it.messageId, + ) + } + onChatMessageReactionsCountUpdated { + val extendedChat: ExtendedChat = getChat(it.chat) + println(extendedChat) + println(it) + } + }.join() +} diff --git a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt index fe604d8..52e566c 100644 --- a/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt +++ b/ResenderBot/ResenderBotLib/src/commonMain/kotlin/ResenderBot.kt @@ -8,6 +8,10 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.CommonMessageFilte import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.* import dev.inmo.tgbotapi.extensions.utils.shortcuts.* +import dev.inmo.tgbotapi.extensions.utils.withContentOrNull +import dev.inmo.tgbotapi.types.ReplyParameters +import dev.inmo.tgbotapi.types.message.content.TextContent +import dev.inmo.tgbotapi.types.quoteEntitiesField import dev.inmo.tgbotapi.utils.extensions.threadIdOrNull import kotlinx.coroutines.* @@ -26,7 +30,14 @@ suspend fun activateResenderBot( it.content.createResend( chat.id, messageThreadId = it.threadIdOrNull, - replyToMessageId = it.messageId + replyParameters = it.replyInfo ?.messageMeta ?.let { meta -> + val quote = it.withContentOrNull() ?.content ?.quote + ReplyParameters( + meta, + entities = quote ?.textSources ?: emptyList(), + quotePosition = quote ?.position + ) + } ) ) { it.forEach(print) diff --git a/WebApp/src/jvmMain/kotlin/WebAppServer.kt b/WebApp/src/jvmMain/kotlin/WebAppServer.kt index 4d61dc9..d3cdf09 100644 --- a/WebApp/src/jvmMain/kotlin/WebAppServer.kt +++ b/WebApp/src/jvmMain/kotlin/WebAppServer.kt @@ -1,3 +1,7 @@ +import dev.inmo.kslog.common.KSLog +import dev.inmo.kslog.common.LogLevel +import dev.inmo.kslog.common.defaultMessageFormatter +import dev.inmo.kslog.common.setDefaultKSLog import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.micro_utils.ktor.server.createKtorServer import dev.inmo.tgbotapi.extensions.api.answers.answer @@ -14,6 +18,7 @@ import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton import dev.inmo.tgbotapi.types.BotCommand import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent +import dev.inmo.tgbotapi.types.LinkPreviewOptions import dev.inmo.tgbotapi.types.webAppQueryIdField import dev.inmo.tgbotapi.types.webapps.WebAppInfo import dev.inmo.tgbotapi.utils.* @@ -43,6 +48,16 @@ suspend fun main(vararg args: String) { args.first(), testServer = args.any { it == "testServer" } ) + val isDebug = args.any { it == "debug" } + + if (isDebug) { + setDefaultKSLog( + KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> + println(defaultMessageFormatter(level, tag, message, throwable)) + } + ) + } + val bot = telegramBot(telegramBotAPIUrlsKeeper) createKtorServer( "0.0.0.0", @@ -102,8 +117,11 @@ suspend fun main(vararg args: String) { row { webAppButton("Open WebApp", WebAppInfo(args[1])) } - } - + }, + linkPreviewOptions = LinkPreviewOptions.Small( + args[1], + showAboveText = false + ) ) } onCommand("attachment_menu") { @@ -114,8 +132,11 @@ suspend fun main(vararg args: String) { row { webAppButton("Open WebApp", WebAppInfo(args[1])) } - } - + }, + linkPreviewOptions = LinkPreviewOptions.Large( + args[1], + showAboveText = true + ) ) } onBaseInlineQuery { diff --git a/build.gradle b/build.gradle index f0319eb..40b825e 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,6 @@ allprojects { } } - maven { url "https://git.inmo.dev/api/packages/InsanusMokrassar/maven" } + maven { url "https://nexus.inmo.dev/repository/maven-releases/" } } } diff --git a/gradle.properties b/gradle.properties index 9a01b19..fbcd980 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,11 @@ kotlin.code.style=official org.gradle.parallel=true # Due to parallel compilation project require next amount of memory on full build -org.gradle.jvmargs=-Xmx2g +org.gradle.jvmargs=-Xmx2344m kotlin_version=1.9.22 -telegram_bot_api_version=9.4.1 -micro_utils_version=0.20.15 +telegram_bot_api_version=10.0.0-branch_10.0.0-build2048 +micro_utils_version=0.20.25 serialization_version=1.6.2 -ktor_version=2.3.6 +ktor_version=2.3.7 diff --git a/settings.gradle b/settings.gradle index ea37daa..a12a93e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -41,3 +41,7 @@ include ":LiveLocationsBot" include ":StickerSetHandler" include ":InlineQueriesBot" + +include ":ReactionsInfoBot" + +include ":LinkPreviewsBot"