Skip to content

Commit

Permalink
Fix HomeGroupChat handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Jan 31, 2024
1 parent eaf500d commit e493b6f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
28 changes: 14 additions & 14 deletions BotNet.CommandHandlers/Privilege/PrivilegeCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ await _telegramBotClient.SendTextMessageAsync(
cancellationToken: cancellationToken
);
break;
case { Chat: HomeGroupChat }:
await _telegramBotClient.SendTextMessageAsync(
chatId: command.Chat.Id,
text: $$"""
👑 Group {{command.Chat.Title}} (ID: {{command.Chat.Id}}) adalah home group
👑 GPT-4 tersedia
👑 GPT-4 Vision tersedia
✅ SDXL tersedia
""",
replyToMessageId: command.CommandMessageId,
parseMode: ParseMode.Markdown,
cancellationToken: cancellationToken
);
break;
case { Chat: GroupChat, Sender: VIPSender }:
await _telegramBotClient.SendTextMessageAsync(
chatId: command.Chat.Id,
Expand All @@ -92,20 +106,6 @@ await _telegramBotClient.SendTextMessageAsync(
cancellationToken: cancellationToken
);
break;
case { Chat: HomeGroupChat }:
await _telegramBotClient.SendTextMessageAsync(
chatId: command.Chat.Id,
text: $$"""
👑 Group {{command.Chat.Title}} (ID: {{command.Chat.Id}}) adalah home group
👑 GPT-4 tersedia
👑 GPT-4 Vision tersedia
✅ SDXL tersedia
""",
replyToMessageId: command.CommandMessageId,
parseMode: ParseMode.Markdown,
cancellationToken: cancellationToken
);
break;
case { Chat: GroupChat }:
await _telegramBotClient.SendTextMessageAsync(
chatId: command.Chat.Id,
Expand Down
27 changes: 23 additions & 4 deletions BotNet.Commands/ChatAggregate/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,27 @@ Telegram.Bot.Types.Chat telegramChat
}
}

public sealed record HomeGroupChat(
ChatId Id,
string Title
) : GroupChat(Id, Title);
public sealed record HomeGroupChat : GroupChat {
private HomeGroupChat(
ChatId id,
string title
) : base(id, title) { }

public static new HomeGroupChat FromTelegramChat(
Telegram.Bot.Types.Chat telegramChat
) {
if (telegramChat is not {
Id: long chatId,
Title: string chatTitle,
Type: ChatType.Group or ChatType.Supergroup
}) {
throw new ArgumentException("Telegram chat must be either a group or a supergroup.");
}

return new(
id: new ChatId(chatId),
title: chatTitle
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ IOptions<CommandPrioritizationOptions> optionsAccessor
.ToImmutableHashSet();
}

public bool IsHomeGroup(long ChatId) {
return _homeGroupChatIds.Contains(ChatId);
public bool IsHomeGroup(long chatId) {
return _homeGroupChatIds.Contains(chatId);
}

public bool IsVIPUser(long UserId) {
return _vipUserIds.Contains(UserId);
public bool IsVIPUser(long userId) {
return _vipUserIds.Contains(userId);
}
}
}
1 change: 1 addition & 0 deletions BotNet.Commands/SenderAggregate/SenderId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
public readonly record struct SenderId(long Value) {
public static implicit operator long(SenderId senderId) => senderId.Value;
public static implicit operator SenderId(long senderId) => new(senderId);
public override string ToString() => Value.ToString();
}
}

0 comments on commit e493b6f

Please sign in to comment.