private static string TranslateFailedCheck(CheckBaseAttribute check, CommandContext ctx) { return(check switch { RequireOwnerAttribute => "You must be the bot's owner to use this command", RequireGuildAttribute => "The command can only be used in a Guild channel (not in a DM)", RequireDirectMessageAttribute => "The command can only be used in a Direct Message", RequireBotPermissionsAttribute botperm => $"The Bot doesn't have the required permissions. It needs: {botperm.Permissions}", RequireUserPermissionsAttribute userPerm => $"You don't have the required permissions. You need: {userPerm.Permissions}", RequirePermissionsAttribute perms => $"You or the bot don't the required permissions: {perms.Permissions}", RequireRolesAttribute roles => $"You need the following role(s) to use this command: {string.Join(", ", roles.RoleNames)}", RequireNsfwAttribute => $"This command can only be used in a nsfw channel!", CooldownAttribute cooldown => $"This command has a cooldown. Please wait {cooldown.GetRemainingCooldown(ctx).Humanize(culture: new("en-GB"))} before you can use it again.", _ => $"{check.TypeId} failed" });
/// <summary> /// Render the error message for an Attribute /// </summary> /// <param name="checkBase">The attribute</param> /// <param name="lang">The language</param> /// <param name="isinguild">Was the command executed in a guild or in direct messages</param> /// <param name="e">Gives the raw command error arguments</param> /// <returns>A <see cref="string" /> containing the error message</returns> private static string RenderErrorMessageForAttribute(CheckBaseAttribute checkBase, Language lang, bool isinguild, CommandErrorEventArgs e) { var type = checkBase.GetType(); if (type == typeof(RequireDjAttribute)) { return(lang.RequireDJCheckFailed); } if (type == typeof(RequireGuildAttribute)) { return(lang.RequireGuildCheckFailed); } if (type == typeof(RequireNsfwAttribute)) { return(lang.RequireNsfwCheckFailed); } if (type == typeof(RequireOwnerAttribute)) { return(lang.RequireOwnerCheckFailed); } return(checkBase switch { RequireRolesAttribute requireRolesAttribute when requireRolesAttribute.RoleNames.Count == 1 => string.Format(lang.RequireRolesCheckFailedSG, requireRolesAttribute.RoleNames[0]), RequireRolesAttribute requireRolesAttribute => string.Format(lang.RequireRolesCheckFailedPL, requireRolesAttribute.RoleNames.Humanize()), RequireBotPermissionsAttribute requireBotPermissions when !(requireBotPermissions.IgnoreDms && isinguild) => lang.RequireGuildCheckFailed, RequireBotPermissionsAttribute requireBotPermissions when Enum.IsDefined(requireBotPermissions.Permissions) && requireBotPermissions.Permissions != Permissions.All => string.Format(lang.RequireBotPermisionsCheckFailedSG, requireBotPermissions.Permissions.Humanize(LetterCasing.LowerCase)), RequireBotPermissionsAttribute requireBotPermissions => string.Format(lang.RequireBotPermisionsCheckFailedPL, requireBotPermissions.Permissions.Humanize(LetterCasing.LowerCase)), RequireUserPermissionsAttribute userPermissions when !(userPermissions.IgnoreDms && isinguild) => lang.RequireGuildCheckFailed, RequireUserPermissionsAttribute userPermissions when Enum.IsDefined(userPermissions.Permissions) && userPermissions.Permissions != Permissions.All => string.Format(lang.RequireUserPermisionsCheckFailedSG, userPermissions.Permissions.Humanize(LetterCasing.LowerCase)), RequireUserPermissionsAttribute userPermissions => string.Format(lang.RequireUserPermisionsCheckFailedPL, userPermissions.Permissions.Humanize(LetterCasing.LowerCase)), RequirePermissionsAttribute userAndBotPermissions when !(userAndBotPermissions.IgnoreDms && isinguild) => lang.RequireGuildCheckFailed, RequirePermissionsAttribute userAndBotPermissions when Enum.IsDefined(userAndBotPermissions.Permissions) && userAndBotPermissions.Permissions != Permissions.All => string.Format(lang.RequireBotAndUserPermisionsCheckFailedSG, userAndBotPermissions.Permissions.Humanize(LetterCasing.LowerCase)), RequirePermissionsAttribute userAndBotPermissions => string.Format(lang.RequireBotAndUserPermisionsCheckFailedPL, userAndBotPermissions.Permissions.Humanize(LetterCasing.LowerCase)), RequireAttachmentAttribute attachmentAttribute when e.Context.Message.Attachments.Count > attachmentAttribute.AttachmentCount => (string)typeof(Language).GetProperty(attachmentAttribute.MoreThenLang)?.GetValue(lang), RequireAttachmentAttribute attachmentAttribute => (string)typeof(Language).GetProperty(attachmentAttribute.LessThenLang)?.GetValue(lang), _ => string.Format(lang.CheckFailed, type.Name.RemoveStringFromEnd("Attribute").Humanize()), });