From a40bab12babe9b376cb2637ec39faa281e123eaf Mon Sep 17 00:00:00 2001 From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com> Date: Fri, 2 Feb 2024 01:46:02 +0700 Subject: [PATCH] Allow using gemini in private chat and other groups --- .../AI/Gemini/GeminiTextPromptHandler.cs | 30 +++++++++---------- .../Privilege/PrivilegeCommandHandler.cs | 14 ++++++--- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs b/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs index 8cbe057..4b6de59 100644 --- a/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs +++ b/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs @@ -28,7 +28,8 @@ public sealed class GeminiTextPromptHandler( ICommandQueue commandQueue, ILogger logger ) : ICommandHandler { - internal static readonly RateLimiter CHAT_RATE_LIMITER = RateLimiter.PerChat(60, TimeSpan.FromMinutes(1)); + internal static readonly RateLimiter CHAT_RATE_LIMITER = RateLimiter.PerChat(5, TimeSpan.FromMinutes(5)); + internal static readonly RateLimiter VIP_CHAT_RATE_LIMITER = RateLimiter.PerChat(60, TimeSpan.FromMinutes(1)); private readonly ITelegramBotClient _telegramBotClient = telegramBotClient; private readonly GeminiClient _geminiClient = geminiClient; @@ -38,22 +39,19 @@ ILogger logger private readonly ILogger _logger = logger; public Task Handle(GeminiTextPrompt textPrompt, CancellationToken cancellationToken) { - if (textPrompt.Command.Chat is not HomeGroupChat - && textPrompt.Command.Sender is not VIPSender) { - return _telegramBotClient.SendTextMessageAsync( - chatId: textPrompt.Command.Chat.Id, - text: MarkdownV2Sanitizer.Sanitize("Gemini tidak bisa dipakai di sini."), - parseMode: ParseMode.MarkdownV2, - replyToMessageId: textPrompt.Command.MessageId, - cancellationToken: cancellationToken - ); - } - try { - CHAT_RATE_LIMITER.ValidateActionRate( - chatId: textPrompt.Command.Chat.Id, - userId: textPrompt.Command.Sender.Id - ); + if (textPrompt.Command.Chat is HomeGroupChat + || textPrompt.Command.Sender is VIPSender) { + VIP_CHAT_RATE_LIMITER.ValidateActionRate( + chatId: textPrompt.Command.Chat.Id, + userId: textPrompt.Command.Sender.Id + ); + } else { + CHAT_RATE_LIMITER.ValidateActionRate( + chatId: textPrompt.Command.Chat.Id, + userId: textPrompt.Command.Sender.Id + ); + } } catch (RateLimitExceededException exc) { return _telegramBotClient.SendTextMessageAsync( chatId: textPrompt.Command.Chat.Id, diff --git a/BotNet.CommandHandlers/Privilege/PrivilegeCommandHandler.cs b/BotNet.CommandHandlers/Privilege/PrivilegeCommandHandler.cs index 5826bd8..262d4c6 100644 --- a/BotNet.CommandHandlers/Privilege/PrivilegeCommandHandler.cs +++ b/BotNet.CommandHandlers/Privilege/PrivilegeCommandHandler.cs @@ -33,7 +33,8 @@ await _telegramBotClient.SendTextMessageAsync( chatId: command.Chat.Id, text: $$""" 👑 Anda adalah user VIP (ID: {{command.Sender.Id}}) - 👑 GPT-4, Gemini tersedia + 👑 Gemini Pro tersedia + 👑 GPT-4 tersedia 👑 GPT-4 Vision tersedia 👑 DALL-E 3 tersedia """, @@ -47,6 +48,7 @@ await _telegramBotClient.SendTextMessageAsync( chatId: command.Chat.Id, text: $$""" ❌ Feature bot dibatasi di dalam private chat (ID: {{command.Sender.Id}}) + ✅ Gemini Pro tersedia ✅ GPT-3.5 tersedia ❌ Vision tidak tersedia ❌ Image generation tidak tersedia @@ -61,7 +63,8 @@ await _telegramBotClient.SendTextMessageAsync( chatId: command.Chat.Id, text: $$""" 👑 Group {{command.Chat.Title}} (ID: {{command.Chat.Id}}) adalah home group - 👑 GPT-4, Gemini tersedia + 👑 Gemini Pro tersedia + 👑 GPT-4 tersedia 👑 GPT-4 Vision tersedia ✅ SDXL tersedia @@ -78,7 +81,8 @@ await _telegramBotClient.SendTextMessageAsync( chatId: command.Chat.Id, text: $$""" 👑 Group {{command.Chat.Title}} (ID: {{command.Chat.Id}}) adalah home group - 👑 GPT-4, Gemini tersedia + 👑 Gemini Pro tersedia + 👑 GPT-4 tersedia 👑 GPT-4 Vision tersedia ✅ SDXL tersedia """, @@ -92,12 +96,13 @@ await _telegramBotClient.SendTextMessageAsync( chatId: command.Chat.Id, text: $$""" ⚠️ Bot dipakai di group selain home group (ID: {{command.Chat.Id}}) + ✅ Gemini Pro tersedia ✅ GPT-3.5 tersedia ❌ Vision tidak tersedia ❌ Image generation tidak tersedia 👑 Anda adalah user VIP - 👑 GPT-4, Gemini tersedia untuk Anda + 👑 GPT-4 tersedia untuk Anda 👑 GPT-4 Vision tersedia untuk Anda 👑 DALL-E 3 tersedia untuk Anda """, @@ -111,6 +116,7 @@ await _telegramBotClient.SendTextMessageAsync( chatId: command.Chat.Id, text: $$""" ⚠️ Bot dipakai di group selain home group (ID: {{command.Chat.Id}}) + ✅ Gemini Pro tersedia ✅ GPT-3.5 tersedia ❌ Vision tidak tersedia ❌ Image generation tidak tersedia