diff --git a/src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs b/src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs index f6753f09..9000d21b 100644 --- a/src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs +++ b/src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs @@ -30,6 +30,8 @@ public DiscordChatClient(DiscordClientSettings settings) _discordClient.MessageReceived += DiscordClientMessageReceived; _discordClient.GuildAvailable += DiscordClientGuildAvailable; _discordClient.GuildUnavailable += DiscordClientGuildUnavailable; + _discordClient.UserJoined += DiscordClientUserJoined; + _discordClient.UserLeft += DiscordClientUserLeft; } private async Task DiscordClientGuildAvailable(SocketGuild arg) @@ -73,18 +75,6 @@ private async Task DiscordClientMessageReceived(SocketMessage arg) } } - private void RaiseOnCommandReceived(SocketGuildUser user, string commandWord, List arguments) - { - var eventArgs = new CommandReceivedEventArgs - { - CommandWord = commandWord, - Arguments = arguments ?? new List(), - ChatUser = user.ToChatUser(_settings) - }; - - OnCommandReceived?.Invoke(this, eventArgs); - } - public async Task Connect() { _discordClient.Connected += DiscordClientConnected; @@ -119,6 +109,16 @@ private async Task DiscordClientDisconnected(Exception arg) _connectionCompletionTask = new TaskCompletionSource(); } + private async Task DiscordClientUserJoined(SocketGuildUser arg) + { + RaiseOnUserNoticed(arg); + } + + private async Task DiscordClientUserLeft(SocketGuildUser arg) + { + RaiseOnUserLeft(arg); + } + public List GetAllChatters() { if(!_isReady) @@ -138,6 +138,40 @@ public void SendMessage(string message) _TextChannel.SendMessageAsync($"`{message}`").Wait(); } + private void RaiseOnCommandReceived(SocketGuildUser user, string commandWord, List arguments) + { + var eventArgs = new CommandReceivedEventArgs + { + CommandWord = commandWord, + Arguments = arguments ?? new List(), + ChatUser = user.ToChatUser(_settings) + }; + + OnCommandReceived?.Invoke(this, eventArgs); + } + + private void RaiseOnUserNoticed(SocketGuildUser user) + { + var eventArgs = new UserStatusEventArgs + { + DisplayName = user.Username, + Role = user.ToUserRole(_settings) + }; + + OnUserNoticed?.Invoke(this, eventArgs); + } + + private void RaiseOnUserLeft(SocketGuildUser user) + { + var eventArgs = new UserStatusEventArgs + { + DisplayName = user.Username, + Role = user.ToUserRole(_settings) + }; + + OnUserLeft?.Invoke(this, eventArgs); + } + public event EventHandler OnCommandReceived; public event EventHandler OnNewSubscriber; public event EventHandler OnUserNoticed;