Skip to content

Commit

Permalink
Raise UserNoticed/Left
Browse files Browse the repository at this point in the history
  • Loading branch information
AridTag committed Apr 7, 2018
1 parent 57799a4 commit edd1506
Showing 1 changed file with 46 additions and 12 deletions.
58 changes: 46 additions & 12 deletions src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -73,18 +75,6 @@ private async Task DiscordClientMessageReceived(SocketMessage arg)
}
}

private void RaiseOnCommandReceived(SocketGuildUser user, string commandWord, List<string> arguments)
{
var eventArgs = new CommandReceivedEventArgs
{
CommandWord = commandWord,
Arguments = arguments ?? new List<string>(),
ChatUser = user.ToChatUser(_settings)
};

OnCommandReceived?.Invoke(this, eventArgs);
}

public async Task Connect()
{
_discordClient.Connected += DiscordClientConnected;
Expand Down Expand Up @@ -119,6 +109,16 @@ private async Task DiscordClientDisconnected(Exception arg)
_connectionCompletionTask = new TaskCompletionSource<bool>();
}

private async Task DiscordClientUserJoined(SocketGuildUser arg)
{
RaiseOnUserNoticed(arg);
}

private async Task DiscordClientUserLeft(SocketGuildUser arg)
{
RaiseOnUserLeft(arg);
}

public List<ChatUser> GetAllChatters()
{
if(!_isReady)
Expand All @@ -138,6 +138,40 @@ public void SendMessage(string message)
_TextChannel.SendMessageAsync($"`{message}`").Wait();
}

private void RaiseOnCommandReceived(SocketGuildUser user, string commandWord, List<string> arguments)
{
var eventArgs = new CommandReceivedEventArgs
{
CommandWord = commandWord,
Arguments = arguments ?? new List<string>(),
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<CommandReceivedEventArgs> OnCommandReceived;
public event EventHandler<NewSubscriberEventArgs> OnNewSubscriber;
public event EventHandler<UserStatusEventArgs> OnUserNoticed;
Expand Down

0 comments on commit edd1506

Please sign in to comment.