Browse Source

Added ModuleManager EnableChannels and EnableServers

tags/docs-0.9
RogueException 9 years ago
parent
commit
3027abc044
1 changed files with 48 additions and 20 deletions
  1. +48
    -20
      src/Discord.Net.Modules/ModuleManager.cs

+ 48
- 20
src/Discord.Net.Modules/ModuleManager.cs View File

@@ -126,17 +126,31 @@ namespace Discord.Modules
if (server == null) throw new ArgumentNullException(nameof(server)); if (server == null) throw new ArgumentNullException(nameof(server));
if (!_useServerWhitelist) throw new InvalidOperationException("This module is not configured to use a server whitelist."); if (!_useServerWhitelist) throw new InvalidOperationException("This module is not configured to use a server whitelist.");


lock (this)
return EnableServerInternal(server);
}
public void EnableServers(IEnumerable<Server> servers)
{
if (servers == null) throw new ArgumentNullException(nameof(servers));
if (!_useServerWhitelist) throw new InvalidOperationException("This module is not configured to use a server whitelist.");

lock (this) lock (this)
{ {
if (_enabledServers.TryAdd(server.Id, server))
{
if (ServerEnabled != null)
ServerEnabled(this, new ServerEventArgs(server));
return true;
}
return false;
foreach (var server in servers)
EnableServerInternal(server);
}
}
private bool EnableServerInternal(Server server)
{
if (_enabledServers.TryAdd(server.Id, server))
{
if (ServerEnabled != null)
ServerEnabled(this, new ServerEventArgs(server));
return true;
} }
return false;
} }

public bool DisableServer(Server server) public bool DisableServer(Server server)
{ {
if (server == null) throw new ArgumentNullException(nameof(server)); if (server == null) throw new ArgumentNullException(nameof(server));
@@ -175,24 +189,38 @@ namespace Discord.Modules
if (!_useChannelWhitelist) throw new InvalidOperationException("This module is not configured to use a channel whitelist."); if (!_useChannelWhitelist) throw new InvalidOperationException("This module is not configured to use a channel whitelist.");


lock (this) lock (this)
return EnableChannelInternal(channel);
}
public void EnableChannels(IEnumerable<Channel> channels)
{
if (channels == null) throw new ArgumentNullException(nameof(channels));
if (!_useChannelWhitelist) throw new InvalidOperationException("This module is not configured to use a channel whitelist.");

lock (this)
{
foreach (var channel in channels)
EnableChannelInternal(channel);
}
}
private bool EnableChannelInternal(Channel channel)
{
if (_enabledChannels.TryAdd(channel.Id, channel))
{ {
if (_enabledChannels.TryAdd(channel.Id, channel))
var server = channel.Server;
if (server != null)
{ {
var server = channel.Server;
if (server != null)
{
int value = 0;
_indirectServers.TryGetValue(server.Id, out value);
value++;
_indirectServers[server.Id] = value;
}
if (ChannelEnabled != null)
ChannelEnabled(this, new ChannelEventArgs(channel));
return true;
int value = 0;
_indirectServers.TryGetValue(server.Id, out value);
value++;
_indirectServers[server.Id] = value;
} }
return false;
if (ChannelEnabled != null)
ChannelEnabled(this, new ChannelEventArgs(channel));
return true;
} }
return false;
} }

public bool DisableChannel(Channel channel) public bool DisableChannel(Channel channel)
{ {
if (channel == null) throw new ArgumentNullException(nameof(channel)); if (channel == null) throw new ArgumentNullException(nameof(channel));


Loading…
Cancel
Save