Skip to content

Commit

Permalink
Allow using gemini in private chat and other groups
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Feb 1, 2024
1 parent f39c1fe commit a40bab1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
30 changes: 14 additions & 16 deletions BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public sealed class GeminiTextPromptHandler(
ICommandQueue commandQueue,
ILogger<GeminiTextPromptHandler> logger
) : ICommandHandler<GeminiTextPrompt> {
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;
Expand All @@ -38,22 +39,19 @@ ILogger<GeminiTextPromptHandler> logger
private readonly ILogger<GeminiTextPromptHandler> _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,
Expand Down
14 changes: 10 additions & 4 deletions BotNet.CommandHandlers/Privilege/PrivilegeCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
""",
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
""",
Expand All @@ -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
""",
Expand All @@ -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
Expand Down

0 comments on commit a40bab1

Please sign in to comment.