From bef96bcc0df8d9d6e2c9ba46f5ee24b56a7cf77e Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Wed, 15 Mar 2023 21:20:19 +0300 Subject: [PATCH] support info --- .../example/bot/unit/PersonalChatGPTUnit.java | 61 ++++++++++++++++++- .../example/bot/unit/StartNotify.java | 21 ++++--- .../dev/struchkov/example/bot/util/Cmd.java | 1 + .../struchkov/example/bot/util/UnitName.java | 2 + 4 files changed, 75 insertions(+), 10 deletions(-) diff --git a/src/main/java/dev/struchkov/example/bot/unit/PersonalChatGPTUnit.java b/src/main/java/dev/struchkov/example/bot/unit/PersonalChatGPTUnit.java index 2fa4a8e..09e43b5 100644 --- a/src/main/java/dev/struchkov/example/bot/unit/PersonalChatGPTUnit.java +++ b/src/main/java/dev/struchkov/example/bot/unit/PersonalChatGPTUnit.java @@ -10,6 +10,7 @@ import dev.struchkov.godfather.simple.domain.BoxAnswer; import dev.struchkov.godfather.simple.domain.unit.AnswerText; import dev.struchkov.godfather.telegram.domain.ChatAction; import dev.struchkov.godfather.telegram.domain.ClientBotCommand; +import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment; import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment; import dev.struchkov.godfather.telegram.main.context.MailPayload; import dev.struchkov.godfather.telegram.main.core.util.Attachments; @@ -73,6 +74,11 @@ public class PersonalChatGPTUnit implements PersonUnitConfiguration { ClientBotCommand.builder() .key(Cmd.HELP) .description("help in use") + .build(), + + ClientBotCommand.builder() + .key(Cmd.SUPPORT_DEV) + .description("Support project development") .build() )); } @@ -105,9 +111,19 @@ public class PersonalChatGPTUnit implements PersonUnitConfiguration { .triggerCheck(mail -> mail.getFromPersonId().equals(appProperty.getTelegramId())) .answer(message -> { telegramService.executeAction(message.getFromPersonId(), ChatAction.TYPING); + + final long countMessages = chatGptService.getCountMessages(chatInfo.getChatId()); + + final StringBuilder builder = new StringBuilder(); + builder.append("Wait... Response is being generated...\nIt might take a long time ⏳"); + + if (countMessages > 40) { + builder.append(Strings.escapeMarkdown("\n-- -- -- -- --\nWe recommend periodically clearing the conversation context (/clear_context). If this is not done, then the memory resources on your PC will run out.")); + } + final BoxAnswer answerWait = BoxAnswer.builder() .recipientPersonId(message.getFromPersonId()) - .message("Wait... Response is being generated...\nIt might take a long time ⏳") + .message(builder.toString()) .build(); telegramSending.send(answerWait); final String answerText = chatGptService.sendNewMessage(chatInfo.getChatId(), message.getText()); @@ -178,6 +194,49 @@ public class PersonalChatGPTUnit implements PersonUnitConfiguration { .build(); } + @Unit(value = UnitName.SUPPORT, main = true) + public AnswerText support() { + return AnswerText.builder() + .triggerCheck( + mail -> { + if (mail.getFromPersonId().equals(appProperty.getTelegramId())) { + final List attachments = mail.getAttachments(); + final Optional optCommand = Attachments.findFirstCommand(attachments); + if (optCommand.isPresent()) { + final CommandAttachment command = optCommand.get(); + return Cmd.SUPPORT_DEV.equals(command.getCommandType()); + } + + final Optional optClick = Attachments.findFirstButtonClick(attachments); + if (optClick.isPresent()) { + final ButtonClickAttachment click = optClick.get(); + return Cmd.SUPPORT_DEV.equals(click.getRawCallBackData()); + } + } + return false; + } + ) + .answer( + boxAnswer(""" + ❤️ *Support Develop* + + Sponsorship makes a project sustainable because it pays for the time of the maintainers of that project, a very scarce resource that is spent on developing new features, fixing bugs, improving stability, solving problems, and general support. *The biggest bottleneck in Open Source is time.* + + TON: `struchkov-mark.ton` + + BTC: + `bc1pt49vnp43c4mktk6309zlq3020dzd0p89gc8d90zzn4sgjvck56xs0t86vy` + + ETH (USDT, DAI, USDC): + `0x7668C802Bd71Be965671D4Bbb1AD90C7f7f32921` + + BNB (USDT, DAI, USDC): + `0xDa41aC95f606850f2E01ba775e521Cd385AA7D03` + """) + ) + .build(); + } + @Unit(value = UnitName.HELP, main = true) public AnswerText help() { return AnswerText.builder() diff --git a/src/main/java/dev/struchkov/example/bot/unit/StartNotify.java b/src/main/java/dev/struchkov/example/bot/unit/StartNotify.java index 2cbfd9d..e432945 100644 --- a/src/main/java/dev/struchkov/example/bot/unit/StartNotify.java +++ b/src/main/java/dev/struchkov/example/bot/unit/StartNotify.java @@ -1,7 +1,9 @@ package dev.struchkov.example.bot.unit; import dev.struchkov.example.bot.conf.AppProperty; +import dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton; import dev.struchkov.godfather.simple.domain.BoxAnswer; +import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; @@ -23,17 +25,18 @@ public class StartNotify { final BoxAnswer boxAnswer = BoxAnswer.builder() .message(MessageFormat.format( """ - Hello 👋 - Your personal ChatGPT bot has been successfully launched. - - Use the help command to find out about the possibilities 🚀 - -- -- -- -- -- - 🤘 Version: {0} - 👨‍💻 Developer: [https://mark.struchkov.dev/](Struchkov Mark) - 💊 Docs: https://docs.struchkov.dev/chatgpt-telegram-bot - """, + Hello 👋 + Your personal ChatGPT bot has been successfully launched. + + Use the help command to find out about the possibilities 🚀 + -- -- -- -- -- + 🤘 Version: {0} + 👨‍💻 Developer: [https://mark.struchkov.dev/](Struchkov Mark) + 💊 Docs: https://docs.struchkov.dev/chatgpt-telegram-bot + """, appProperty.getVersion() )) + .keyBoard(InlineKeyBoard.inlineKeyBoard(SimpleButton.simpleButton("❤️ Support Develop", "support"))) .payload(DISABLE_WEB_PAGE_PREVIEW, true) .build(); boxAnswer.setRecipientIfNull(appProperty.getTelegramId()); diff --git a/src/main/java/dev/struchkov/example/bot/util/Cmd.java b/src/main/java/dev/struchkov/example/bot/util/Cmd.java index a2a0757..df0594e 100644 --- a/src/main/java/dev/struchkov/example/bot/util/Cmd.java +++ b/src/main/java/dev/struchkov/example/bot/util/Cmd.java @@ -9,5 +9,6 @@ public class Cmd { public static final String PROMPT = "prompt"; public static final String GPT = "gpt"; public static final String HELP = "help"; + public static final String SUPPORT_DEV = "support"; } diff --git a/src/main/java/dev/struchkov/example/bot/util/UnitName.java b/src/main/java/dev/struchkov/example/bot/util/UnitName.java index c221647..4d1e0e2 100644 --- a/src/main/java/dev/struchkov/example/bot/util/UnitName.java +++ b/src/main/java/dev/struchkov/example/bot/util/UnitName.java @@ -11,4 +11,6 @@ public class UnitName { public static final String PROMPT = "PROMPT"; public static final String ACCESS_ERROR = "ACCESS_ERROR"; + public static final String SUPPORT = "SUPPORT"; + }