Skip to content

Commit b20b6b8

Browse files
committed
Raise UserNoticed/Left
1 parent eb6f04d commit b20b6b8

1 file changed

Lines changed: 46 additions & 12 deletions

File tree

src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public DiscordChatClient(DiscordClientSettings settings)
3030
_discordClient.MessageReceived += DiscordClientMessageReceived;
3131
_discordClient.GuildAvailable += DiscordClientGuildAvailable;
3232
_discordClient.GuildUnavailable += DiscordClientGuildUnavailable;
33+
_discordClient.UserJoined += DiscordClientUserJoined;
34+
_discordClient.UserLeft += DiscordClientUserLeft;
3335
}
3436

3537
private async Task DiscordClientGuildAvailable(SocketGuild arg)
@@ -73,18 +75,6 @@ private async Task DiscordClientMessageReceived(SocketMessage arg)
7375
}
7476
}
7577

76-
private void RaiseOnCommandReceived(SocketGuildUser user, string commandWord, List<string> arguments)
77-
{
78-
var eventArgs = new CommandReceivedEventArgs
79-
{
80-
CommandWord = commandWord,
81-
Arguments = arguments ?? new List<string>(),
82-
ChatUser = user.ToChatUser(_settings)
83-
};
84-
85-
OnCommandReceived?.Invoke(this, eventArgs);
86-
}
87-
8878
public async Task Connect()
8979
{
9080
_discordClient.Connected += DiscordClientConnected;
@@ -119,6 +109,16 @@ private async Task DiscordClientDisconnected(Exception arg)
119109
_connectionCompletionTask = new TaskCompletionSource<bool>();
120110
}
121111

112+
private async Task DiscordClientUserJoined(SocketGuildUser arg)
113+
{
114+
RaiseOnUserNoticed(arg);
115+
}
116+
117+
private async Task DiscordClientUserLeft(SocketGuildUser arg)
118+
{
119+
RaiseOnUserLeft(arg);
120+
}
121+
122122
public List<ChatUser> GetAllChatters()
123123
{
124124
if(!_isReady)
@@ -138,6 +138,40 @@ public void SendMessage(string message)
138138
_TextChannel.SendMessageAsync($"`{message}`").Wait();
139139
}
140140

141+
private void RaiseOnCommandReceived(SocketGuildUser user, string commandWord, List<string> arguments)
142+
{
143+
var eventArgs = new CommandReceivedEventArgs
144+
{
145+
CommandWord = commandWord,
146+
Arguments = arguments ?? new List<string>(),
147+
ChatUser = user.ToChatUser(_settings)
148+
};
149+
150+
OnCommandReceived?.Invoke(this, eventArgs);
151+
}
152+
153+
private void RaiseOnUserNoticed(SocketGuildUser user)
154+
{
155+
var eventArgs = new UserStatusEventArgs
156+
{
157+
DisplayName = user.Username,
158+
Role = user.ToUserRole(_settings)
159+
};
160+
161+
OnUserNoticed?.Invoke(this, eventArgs);
162+
}
163+
164+
private void RaiseOnUserLeft(SocketGuildUser user)
165+
{
166+
var eventArgs = new UserStatusEventArgs
167+
{
168+
DisplayName = user.Username,
169+
Role = user.ToUserRole(_settings)
170+
};
171+
172+
OnUserLeft?.Invoke(this, eventArgs);
173+
}
174+
141175
public event EventHandler<CommandReceivedEventArgs> OnCommandReceived;
142176
public event EventHandler<NewSubscriberEventArgs> OnNewSubscriber;
143177
public event EventHandler<UserStatusEventArgs> OnUserNoticed;

0 commit comments

Comments
 (0)