2019-03-16 23:41:55 +00:00
|
|
|
|
using Discord.Net;
|
2018-12-05 03:41:42 +00:00
|
|
|
|
|
|
|
|
|
namespace Kerobot
|
|
|
|
|
{
|
2019-03-16 23:41:55 +00:00
|
|
|
|
// Instances of this are created by CommonFunctionService and by ModuleBase on behalf of CommonFunctionService,
|
|
|
|
|
// and are meant to be sent to modules. This class has therefore been put within the Kerobot namespace.
|
2018-12-05 03:41:42 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains information on various success/failure outcomes for a ban or kick operation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class BanKickResult
|
|
|
|
|
{
|
|
|
|
|
private readonly bool _userNotFound;
|
|
|
|
|
|
2019-03-16 23:41:55 +00:00
|
|
|
|
internal BanKickResult(HttpException error, bool notificationSuccess, bool errorNotFound)
|
2018-12-05 03:41:42 +00:00
|
|
|
|
{
|
|
|
|
|
OperationError = error;
|
2019-03-16 23:41:55 +00:00
|
|
|
|
MessageSendSuccess = notificationSuccess;
|
2018-12-05 03:41:42 +00:00
|
|
|
|
_userNotFound = errorNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the kick or ban succeeded.
|
|
|
|
|
/// </summary>
|
2019-03-16 23:41:55 +00:00
|
|
|
|
public bool OperationSuccess {
|
|
|
|
|
get {
|
|
|
|
|
if (ErrorNotFound) return false;
|
|
|
|
|
if (OperationError == null) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-05 03:41:42 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The exception thrown, if any, when attempting to kick or ban the target.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public HttpException OperationError { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the operation failed due to being unable to find the user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ErrorNotFound
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_userNotFound) return true; // TODO I don't like this.
|
|
|
|
|
if (OperationSuccess) return false;
|
|
|
|
|
return OperationError.HttpCode == System.Net.HttpStatusCode.NotFound;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the operation failed due to a permissions issue.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ErrorForbidden
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (OperationSuccess) return false;
|
|
|
|
|
return OperationError.HttpCode == System.Net.HttpStatusCode.Forbidden;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the user was able to receive the ban or kick message.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>
|
|
|
|
|
/// <see langword="false"/> if an error was encountered when attempting to send the target a DM. Will always
|
|
|
|
|
/// return <see langword="true"/> otherwise, including cases in which no message was sent.
|
|
|
|
|
/// </value>
|
|
|
|
|
public bool MessageSendSuccess { get; }
|
|
|
|
|
}
|
|
|
|
|
}
|