using Discord.Net; using RegexBot.Common; namespace RegexBot; /// /// Contains information on various success/failure outcomes for setting a timeout. /// public class TimeoutSetResult : IOperationResult { private readonly SocketGuildUser? _target; /// public bool Success => Error == null; /// public Exception? Error { get; } /// public bool ErrorNotFound => (_target == null) || Error is HttpException { HttpCode: System.Net.HttpStatusCode.NotFound }; /// public bool ErrorForbidden => Error is HttpException { HttpCode: System.Net.HttpStatusCode.Forbidden }; /// public bool NotificationSuccess { get; } internal TimeoutSetResult(Exception? error, bool notificationSuccess, SocketGuildUser? target) { Error = error; NotificationSuccess = notificationSuccess; _target = target; } /// public string ToResultString() { if (Success) { var msg = $":white_check_mark: Timeout set for **{_target!.GetDisplayableUsername()}**."; if (!NotificationSuccess) msg += "\n(User was unable to receive notification message.)"; return msg; } else { var msg = ":x: Failed to set timeout: "; 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."; return msg; } } }