Removed duplicate ban/unban methods
This commit is contained in:
@@ -166,9 +166,6 @@
|
||||
<Compile Include="..\Discord.Net\DiscordAPIClientConfig.cs">
|
||||
<Link>DiscordAPIClientConfig.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Discord.Net\DiscordClient.Bans.cs">
|
||||
<Link>DiscordClient.Bans.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Discord.Net\DiscordClient.Channels.cs">
|
||||
<Link>DiscordClient.Channels.cs</Link>
|
||||
</Compile>
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public class BanEventArgs : EventArgs
|
||||
{
|
||||
public long UserId { get; }
|
||||
public Server Server { get; }
|
||||
|
||||
public BanEventArgs(long userId, Server server)
|
||||
{
|
||||
UserId = userId;
|
||||
Server = server;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class DiscordClient
|
||||
{
|
||||
public event EventHandler<BanEventArgs> UserBanned;
|
||||
private void RaiseUserBanned(long userId, Server server)
|
||||
{
|
||||
if (UserBanned != null)
|
||||
RaiseEvent(nameof(UserBanned), () => UserBanned(this, new BanEventArgs(userId, server)));
|
||||
}
|
||||
public event EventHandler<BanEventArgs> UserUnbanned;
|
||||
private void RaiseUserUnbanned(long userId, Server server)
|
||||
{
|
||||
if (UserUnbanned != null)
|
||||
RaiseEvent(nameof(UserUnbanned), () => UserUnbanned(this, new BanEventArgs(userId, server)));
|
||||
}
|
||||
|
||||
/// <summary> Bans a user from the provided server. </summary>
|
||||
public Task Ban(User user)
|
||||
{
|
||||
if (user == null) throw new ArgumentNullException(nameof(user));
|
||||
if (user.Server == null) throw new ArgumentException("Unable to ban a user in a private chat.");
|
||||
CheckReady();
|
||||
|
||||
return _api.BanUser(user.Server.Id, user.Id);
|
||||
}
|
||||
|
||||
/// <summary> Unbans a user from the provided server. </summary>
|
||||
public async Task Unban(Server server, long userId)
|
||||
{
|
||||
if (server == null) throw new ArgumentNullException(nameof(server));
|
||||
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
|
||||
CheckReady();
|
||||
|
||||
try { await _api.UnbanUser(server.Id, userId).ConfigureAwait(false); }
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
@@ -53,6 +54,17 @@ namespace Discord
|
||||
IsSpeaking = isSpeaking;
|
||||
}
|
||||
}
|
||||
public class BanEventArgs : EventArgs
|
||||
{
|
||||
public long UserId { get; }
|
||||
public Server Server { get; }
|
||||
|
||||
public BanEventArgs(long userId, Server server)
|
||||
{
|
||||
UserId = userId;
|
||||
Server = server;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class DiscordClient
|
||||
{
|
||||
@@ -104,6 +116,18 @@ namespace Discord
|
||||
if (ProfileUpdated != null)
|
||||
RaiseEvent(nameof(ProfileUpdated), () => ProfileUpdated(this, EventArgs.Empty));
|
||||
}
|
||||
public event EventHandler<BanEventArgs> UserBanned;
|
||||
private void RaiseUserBanned(long userId, Server server)
|
||||
{
|
||||
if (UserBanned != null)
|
||||
RaiseEvent(nameof(UserBanned), () => UserBanned(this, new BanEventArgs(userId, server)));
|
||||
}
|
||||
public event EventHandler<BanEventArgs> UserUnbanned;
|
||||
private void RaiseUserUnbanned(long userId, Server server)
|
||||
{
|
||||
if (UserUnbanned != null)
|
||||
RaiseEvent(nameof(UserUnbanned), () => UserUnbanned(this, new BanEventArgs(userId, server)));
|
||||
}
|
||||
|
||||
/// <summary> Returns the current logged-in user in a private channel. </summary>
|
||||
internal User PrivateUser => _privateUser;
|
||||
@@ -202,6 +226,7 @@ namespace Discord
|
||||
{
|
||||
if (user == null) throw new ArgumentNullException(nameof(user));
|
||||
if (user.IsPrivate) throw new InvalidOperationException("Unable to kick users from a private channel");
|
||||
CheckReady();
|
||||
|
||||
return _api.KickUser(user.Server.Id, user.Id);
|
||||
}
|
||||
@@ -209,15 +234,18 @@ namespace Discord
|
||||
{
|
||||
if (user == null) throw new ArgumentNullException(nameof(user));
|
||||
if (user.IsPrivate) throw new InvalidOperationException("Unable to ban users from a private channel");
|
||||
CheckReady();
|
||||
|
||||
return _api.BanUser(user.Server.Id, user.Id);
|
||||
}
|
||||
public Task UnbanUser(Server server, long userId)
|
||||
public async Task UnbanUser(Server server, long userId)
|
||||
{
|
||||
if (server == null) throw new ArgumentNullException(nameof(server));
|
||||
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
|
||||
CheckReady();
|
||||
|
||||
return _api.UnbanUser(server.Id, userId);
|
||||
try { await _api.UnbanUser(server.Id, userId).ConfigureAwait(false); }
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
|
||||
public async Task<int> PruneUsers(Server server, int days, bool simulate = false)
|
||||
|
||||
Reference in New Issue
Block a user