Add comprehensive Discord provider design documentation#524
Add comprehensive Discord provider design documentation#524csharpfritz wants to merge 3 commits intoFritzAndFriends:mainfrom
Conversation
Complete design specifications for Discord channel monitoring: - Discord-Provider-Design.md: WebSocket Gateway API integration architecture - Discord-Technical-Implementation.md: WebSocket services and bot authentication - Discord-UI-Specification.md: Bot setup wizard and Discord ID helpers - Discord-Configuration-Guide.md: End-user bot creation and setup guide - Discord-Implementation-Roadmap.md: 5-week development timeline Discord provider enables real-time channel monitoring for gaming streams, developer conferences, community events, and live audience engagement. Features: WebSocket connections, bot authentication, Discord API v10 integration, comprehensive bot setup guidance, and real-time message processing.
…oring - Added DiscordConfiguration class for provider configuration settings. - Developed DiscordGatewayService for managing WebSocket connections to Discord Gateway. - Created DiscordModels to represent Discord messages, users, embeds, and attachments. - Implemented DiscordProvider to handle message retrieval and processing. - Added README documentation for setup and configuration instructions. - Established service registration for Discord provider in StartDiscord class. - Configured project file with necessary dependencies and settings.
| private static readonly ConcurrentQueue<Content> _Contents = new(); | ||
| private static readonly ConcurrentQueue<DiscordMessage> _MessageQueue = new(); | ||
| private static readonly CancellationTokenSource _CancellationTokenSource = new(); |
There was a problem hiding this comment.
Static shared state across provider instances creates potential concurrency issues. Each DiscordProvider instance should have its own queues and cancellation tokens to avoid cross-instance interference and ensure proper isolation.
| private static readonly ConcurrentQueue<Content> _Contents = new(); | |
| private static readonly ConcurrentQueue<DiscordMessage> _MessageQueue = new(); | |
| private static readonly CancellationTokenSource _CancellationTokenSource = new(); | |
| private readonly ConcurrentQueue<Content> _Contents = new(); | |
| private readonly ConcurrentQueue<DiscordMessage> _MessageQueue = new(); | |
| private readonly CancellationTokenSource _CancellationTokenSource = new(); |
| { | ||
| if (data == null) return; | ||
|
|
||
| var helloData = JsonSerializer.Deserialize<DiscordHelloPayload>(data.ToString()!); |
There was a problem hiding this comment.
Using data.ToString()! assumes the object can be safely converted to JSON string, but data is of type object? and may not serialize correctly. Should use JsonSerializer.Serialize(data) first or cast to JsonElement for proper JSON handling.
| var helloData = JsonSerializer.Deserialize<DiscordHelloPayload>(data.ToString()!); | |
| string json; | |
| if (data is JsonElement element) | |
| { | |
| json = element.GetRawText(); | |
| } | |
| else | |
| { | |
| json = JsonSerializer.Serialize(data); | |
| } | |
| var helloData = JsonSerializer.Deserialize<DiscordHelloPayload>(json); |
| break; | ||
|
|
||
| case "MESSAGE_CREATE": | ||
| var message = JsonSerializer.Deserialize<DiscordMessage>(data.ToString()!); |
There was a problem hiding this comment.
Using data.ToString()! assumes the object can be safely converted to JSON string, but data is of type object? and may not serialize correctly. Should use JsonSerializer.Serialize(data) first or cast to JsonElement for proper JSON handling.
| var message = JsonSerializer.Deserialize<DiscordMessage>(data.ToString()!); | |
| var json = data is JsonElement je ? je.GetRawText() : JsonSerializer.Serialize(data); | |
| var message = JsonSerializer.Deserialize<DiscordMessage>(json); |
| !string.IsNullOrEmpty(BotToken) && | ||
| !string.IsNullOrEmpty(GuildId) && | ||
| !string.IsNullOrEmpty(ChannelId) && | ||
| BotToken.Length > 50; // Discord tokens are ~70 characters |
There was a problem hiding this comment.
Magic number 50 should be defined as a named constant like MinimumTokenLength to improve code maintainability and make the validation threshold more explicit.
Complete design specifications for Discord channel monitoring:
Discord provider enables real-time channel monitoring for gaming streams, developer conferences, community events, and live audience engagement.
Features: WebSocket connections, bot authentication, Discord API v10 integration, comprehensive bot setup guidance, and real-time message processing.