Skip to content

Commit

Permalink
Handle channels being created or destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
AridTag committed Apr 7, 2018
1 parent c700d6d commit 8207c92
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,37 @@ public DiscordChatClient(DiscordClientSettings settings)
_discordClient.MessageReceived += DiscordClientMessageReceived;
_discordClient.GuildAvailable += DiscordClientGuildAvailable;
_discordClient.GuildUnavailable += DiscordClientGuildUnavailable;
_discordClient.ChannelCreated += DiscordClientChannelCreated;
_discordClient.ChannelDestroyed += DiscordClientChannelDestroyed;
_discordClient.UserJoined += DiscordClientUserJoined;
_discordClient.UserLeft += DiscordClientUserLeft;
}

private async Task DiscordClientGuildAvailable(SocketGuild arg)
private async Task DiscordClientGuildAvailable(SocketGuild guild)
{
_Guild = arg;
_Guild = guild;
_GuildChannelIds.AddRange(_Guild.Channels.Select(channel => channel.Id));
_TextChannel = _Guild.Channels.FirstOrDefault(channel => channel.Id == _settings.DiscordTextChannelId) as ISocketMessageChannel;
_isReady = true;
}

private async Task DiscordClientGuildUnavailable(SocketGuild arg)
private async Task DiscordClientGuildUnavailable(SocketGuild guild)
{
_Guild = null;
_GuildChannelIds.Clear();
_isReady = false;
}

private async Task DiscordClientChannelCreated(SocketChannel newChannel)
{
_GuildChannelIds.Add(newChannel.Id);
}

private async Task DiscordClientChannelDestroyed(SocketChannel oldChannel)
{
_GuildChannelIds.Remove(oldChannel.Id);
}

private async Task DiscordClientMessageReceived(SocketMessage arg)
{
var message = arg as SocketUserMessage;
Expand Down

0 comments on commit 8207c92

Please sign in to comment.