2022-09-17 03:42:55 +00:00
|
|
|
using Discord.Net;
|
|
|
|
using RegexBot.Common;
|
|
|
|
|
|
|
|
namespace RegexBot;
|
|
|
|
/// <summary>
|
|
|
|
/// Contains information on various success/failure outcomes for setting a timeout.
|
|
|
|
/// </summary>
|
|
|
|
public class TimeoutSetResult : IOperationResult {
|
|
|
|
private readonly SocketGuildUser? _target;
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool Success => Error == null;
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public Exception? Error { get; }
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2023-11-15 05:09:21 +00:00
|
|
|
public bool ErrorNotFound => (_target == null) || Error is HttpException { HttpCode: System.Net.HttpStatusCode.NotFound };
|
2022-09-17 03:42:55 +00:00
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2023-11-15 05:09:21 +00:00
|
|
|
public bool ErrorForbidden => Error is HttpException { HttpCode: System.Net.HttpStatusCode.Forbidden };
|
2022-09-17 03:42:55 +00:00
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public bool NotificationSuccess { get; }
|
|
|
|
|
|
|
|
internal TimeoutSetResult(Exception? error, bool notificationSuccess, SocketGuildUser? target) {
|
|
|
|
Error = error;
|
|
|
|
NotificationSuccess = notificationSuccess;
|
|
|
|
_target = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public string ToResultString() {
|
|
|
|
if (Success) {
|
2023-11-15 05:09:21 +00:00
|
|
|
var msg = $":white_check_mark: Timeout set for **{_target!.GetDisplayableUsername()}**.";
|
2022-09-17 03:42:55 +00:00
|
|
|
if (!NotificationSuccess) msg += "\n(User was unable to receive notification message.)";
|
|
|
|
return msg;
|
|
|
|
} else {
|
|
|
|
var msg = ":x: Failed to set timeout: ";
|
2022-09-21 04:50:33 +00:00
|
|
|
if (ErrorNotFound) msg += "The specified user could not be found.";
|
|
|
|
else if (ErrorForbidden) msg += Messages.ForbiddenGenericError;
|
|
|
|
else if (Error != null) msg += Error.Message;
|
|
|
|
else msg += "Unknown error.";
|
2022-09-17 03:42:55 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|