From 6bee6de855015884c39caa6875a8fd2445b193f1 Mon Sep 17 00:00:00 2001 From: Moons Date: Wed, 6 Sep 2023 21:17:41 +0200 Subject: [PATCH 1/6] refactor(global): cleanup code --- Felicity/Controllers/BungieAuthController.cs | 2 +- .../Interactions/EmblemCommands.cs | 89 +++++++++++-------- .../Interactions/UserCommands.cs | 6 +- .../Text/TestingTextCommands.cs | 17 ++-- Felicity/Models/Caches/GunsmithCache.cs | 2 +- Felicity/Models/Checkpoints.cs | 3 +- Felicity/Models/RecommendedRolls.cs | 35 ++++---- Felicity/Program.cs | 2 +- .../Services/Hosted/DiscordStartupService.cs | 15 ++-- Felicity/Services/Hosted/StatusService.cs | 1 - .../Services/Hosted/TwitchStartupService.cs | 2 +- Felicity/Services/TwitchService.cs | 2 +- Felicity/Util/AutoCompletes.cs | 36 ++++---- Felicity/Util/BotVariables.cs | 2 +- Felicity/Util/BungieAPIUtils.cs | 4 +- Felicity/Util/EmblemReport.cs | 3 +- Felicity/Util/EmoteHelper.cs | 4 +- Felicity/Util/HttpClientInstance.cs | 10 +-- Felicity/Util/Preconditions.cs | 4 +- Felicity/Util/ProfileHelper.cs | 4 +- 20 files changed, 127 insertions(+), 116 deletions(-) diff --git a/Felicity/Controllers/BungieAuthController.cs b/Felicity/Controllers/BungieAuthController.cs index 8634d2c..de63f34 100644 --- a/Felicity/Controllers/BungieAuthController.cs +++ b/Felicity/Controllers/BungieAuthController.cs @@ -92,4 +92,4 @@ await _bungieClient.ApiAccess.Destiny2.GetLinkedProfiles(BungieMembershipType.Bu return RedirectPermanent("https://tryfelicity.one/auth_success"); } -} +} \ No newline at end of file diff --git a/Felicity/DiscordCommands/Interactions/EmblemCommands.cs b/Felicity/DiscordCommands/Interactions/EmblemCommands.cs index b9d6731..a22b692 100644 --- a/Felicity/DiscordCommands/Interactions/EmblemCommands.cs +++ b/Felicity/DiscordCommands/Interactions/EmblemCommands.cs @@ -7,6 +7,7 @@ using DotNetBungieAPI.Models.Destiny; using DotNetBungieAPI.Models.Destiny.Definitions.Collectibles; using DotNetBungieAPI.Models.Destiny.Definitions.InventoryItems; +using DotNetBungieAPI.Models.Destiny.Responses; using DotNetBungieAPI.Service.Abstractions; using Felicity.Models; using Felicity.Util; @@ -219,51 +220,39 @@ public async Task EmblemRarest( return; } - var manifestCollectibleIDs = - (from destinyCollectibleComponent in profile.Response.ProfileCollectibles.Data.Collectibles - where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.UniquenessViolation) || - !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.Invisible) || - destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - select destinyCollectibleComponent.Key).ToList(); + var manifestCollectibleIDs = AddEmblems(profile.Response); - foreach (var destinyCollectibleComponent in profile.Response.CharacterCollectibles.Data) - manifestCollectibleIDs.AddRange(from collectibleComponent in destinyCollectibleComponent.Value.Collectibles - where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.UniquenessViolation) || - !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.Invisible) || - collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - select collectibleComponent.Key); + if (requestedProfile.MembershipId == 4611686018471516071) // Moonie + { + profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( + BungieMembershipType.TigerSteam, 4611686018500337909, + new[] + { + DestinyComponentType.Collectibles, DestinyComponentType.Profiles + }); + + manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); + } - if (requestedProfile.MembershipId == 4611686018471516071) + if (requestedProfile.MembershipId == 4611686018432393645) // Zempp { - profile = await _bungieClient.ApiAccess.Destiny2.GetProfile(BungieMembershipType.TigerSteam, - 4611686018500337909, new[] + profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( + BungieMembershipType.TigerPsn, 4611686018475371052, + new[] + { + DestinyComponentType.Collectibles, DestinyComponentType.Profiles + }); + + manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); + + profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( + BungieMembershipType.TigerSteam, 4611686018483360936, + new[] { DestinyComponentType.Collectibles, DestinyComponentType.Profiles }); - manifestCollectibleIDs.AddRange( - (from destinyCollectibleComponent in profile.Response.ProfileCollectibles.Data.Collectibles - where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState - .UniquenessViolation) || - !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.Invisible) || - destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - select destinyCollectibleComponent.Key).ToList()); - - foreach (var destinyCollectibleComponent in profile.Response.CharacterCollectibles.Data) - manifestCollectibleIDs.AddRange( - from collectibleComponent in destinyCollectibleComponent.Value.Collectibles - where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.UniquenessViolation) || - !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.Invisible) || - collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) - select collectibleComponent.Key); + manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); } var manifestCollectibles = new List(); @@ -361,4 +350,28 @@ where EmblemCats.EmblemCatList.Contains((EmblemCat)definitionParentNode.Hash!) await FollowupAsync(embed: embed.Build()); } + + private static List> AddEmblems( + DestinyProfileResponse profileResponse) + { + var manifestCollectibleIDs = + (from destinyCollectibleComponent in profileResponse.ProfileCollectibles.Data.Collectibles + where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.UniquenessViolation) || + !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) + where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.Invisible) || + destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) + where !destinyCollectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) + select destinyCollectibleComponent.Key).ToList(); + + foreach (var destinyCollectibleComponent in profileResponse.CharacterCollectibles.Data) + manifestCollectibleIDs.AddRange(from collectibleComponent in destinyCollectibleComponent.Value.Collectibles + where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.UniquenessViolation) || + !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) + where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.Invisible) || + collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) + where !collectibleComponent.Value.State.HasFlag(DestinyCollectibleState.NotAcquired) + select collectibleComponent.Key); + + return manifestCollectibleIDs; + } } \ No newline at end of file diff --git a/Felicity/DiscordCommands/Interactions/UserCommands.cs b/Felicity/DiscordCommands/Interactions/UserCommands.cs index f5d40b5..8887b42 100644 --- a/Felicity/DiscordCommands/Interactions/UserCommands.cs +++ b/Felicity/DiscordCommands/Interactions/UserCommands.cs @@ -25,9 +25,9 @@ public async Task UserRegister() var embed = Embeds.MakeBuilder(); embed.Description = "Use the link below to register your Bungie profile with Felicity.\n" - + "We securely store authentication keys to access your profile information, collections, records, and more.\n" - + "**If you don't want us to store your data, please refrain from proceeding.**\n\n" - + $"[Click here to register.](https://auth.tryfelicity.one/auth/bungie_net/{Context.User.Id})"; + + "We securely store authentication keys to access your profile information, collections, records, and more.\n" + + "**If you don't want us to store your data, please refrain from proceeding.**\n\n" + + $"[Click here to register.](https://auth.tryfelicity.one/auth/bungie_net/{Context.User.Id})"; await FollowupAsync(embed: embed.Build(), ephemeral: true); } diff --git a/Felicity/DiscordCommands/Text/TestingTextCommands.cs b/Felicity/DiscordCommands/Text/TestingTextCommands.cs index aad8041..9aba19b 100644 --- a/Felicity/DiscordCommands/Text/TestingTextCommands.cs +++ b/Felicity/DiscordCommands/Text/TestingTextCommands.cs @@ -8,7 +8,6 @@ using DotNetBungieAPI.HashReferences; using DotNetBungieAPI.Models; using DotNetBungieAPI.Models.Destiny; -using DotNetBungieAPI.Models.Destiny.Definitions; using DotNetBungieAPI.Models.Requests; using DotNetBungieAPI.Service.Abstractions; using Felicity.Models; @@ -44,13 +43,12 @@ public async Task VendorUser() var validUsers = _userDb.Users.Where(x => x.OAuthRefreshExpires > DateTime.Now).ToList(); var nowTime = DateTime.Now; var tasks = new List>(); - + foreach (var validUser in validUsers) { var user = validUser; if (validUser.OAuthTokenExpires < nowTime) - { try { user = await validUser.RefreshToken(_bungieClient, nowTime); @@ -61,7 +59,6 @@ public async Task VendorUser() Console.WriteLine($"{user.BungieName} - {ex.GetType()}: {ex.Message}"); continue; } - } tasks.Add(Task.Run(async () => { @@ -71,15 +68,19 @@ public async Task VendorUser() user.DestinyMembershipId, new[] { DestinyComponentType.Characters }); var saintVendor = await _bungieClient.ApiAccess.Destiny2.GetVendor(user.DestinyMembershipType, - user.DestinyMembershipId, characterId.Response.Characters.Data.FirstOrDefault().Value.CharacterId, + user.DestinyMembershipId, + characterId.Response.Characters.Data.FirstOrDefault().Value.CharacterId, DefinitionHashes.Vendors.Saint14, new[] { DestinyComponentType.Vendors }, user.GetTokenData()); var saladinVendor = await _bungieClient.ApiAccess.Destiny2.GetVendor(user.DestinyMembershipType, - user.DestinyMembershipId, characterId.Response.Characters.Data.FirstOrDefault().Value.CharacterId, - DefinitionHashes.Vendors.LordSaladin, new[] { DestinyComponentType.Vendors }, user.GetTokenData()); + user.DestinyMembershipId, + characterId.Response.Characters.Data.FirstOrDefault().Value.CharacterId, + DefinitionHashes.Vendors.LordSaladin, new[] { DestinyComponentType.Vendors }, + user.GetTokenData()); Console.WriteLine($"Finished task for {user.BungieName}"); - return $"{user.BungieName}: Saint-14: {saintVendor.Response.Vendor.Data.Progression.CurrentResetCount}, Saladin: {saladinVendor.Response.Vendor.Data.Progression.CurrentResetCount}"; + return + $"{user.BungieName}: Saint-14: {saintVendor.Response.Vendor.Data.Progression.CurrentResetCount}, Saladin: {saladinVendor.Response.Vendor.Data.Progression.CurrentResetCount}"; } catch { diff --git a/Felicity/Models/Caches/GunsmithCache.cs b/Felicity/Models/Caches/GunsmithCache.cs index 273b0dd..9425ed9 100644 --- a/Felicity/Models/Caches/GunsmithCache.cs +++ b/Felicity/Models/Caches/GunsmithCache.cs @@ -31,7 +31,7 @@ public static Embed BuildEmbed(GunsmithCache self, BaseSocketClient discordClien return embed.Build(); } - public static async Task FetchInventory(User oauth, IBungieClient bungieClient) + public static async Task FetchInventory(User oauth, IBungieClient bungieClient) { /*var path = $"Data/gsCache-{lg}.json"; diff --git a/Felicity/Models/Checkpoints.cs b/Felicity/Models/Checkpoints.cs index bb9bfce..c2d4f3f 100644 --- a/Felicity/Models/Checkpoints.cs +++ b/Felicity/Models/Checkpoints.cs @@ -15,7 +15,8 @@ public class CheckpointParser { try { - return await HttpClientInstance.Instance.GetFromJsonAsync("https://d2cp.io/platform/checkpoints?v=2"); + return await HttpClientInstance.Instance.GetFromJsonAsync( + "https://d2cp.io/platform/checkpoints?v=2"); } catch { diff --git a/Felicity/Models/RecommendedRolls.cs b/Felicity/Models/RecommendedRolls.cs index ebf8612..04c8246 100644 --- a/Felicity/Models/RecommendedRolls.cs +++ b/Felicity/Models/RecommendedRolls.cs @@ -13,35 +13,35 @@ namespace Felicity.Models; public partial class NewWeaponRoll { - [JsonPropertyName("weaponRolls")] - public List WeaponRolls { get; set; } + [JsonPropertyName("weaponRolls")] public List WeaponRolls { get; set; } } -public partial class WeaponRoll +public class WeaponRoll { - [JsonPropertyName("weaponHash")] - public uint WeaponHash { get; set; } + [JsonPropertyName("weaponHash")] public uint WeaponHash { get; set; } - [JsonPropertyName("authorId")] - public int AuthorId { get; set; } + [JsonPropertyName("authorId")] public int AuthorId { get; set; } - [JsonPropertyName("source")] - public int Source { get; set; } + [JsonPropertyName("source")] public int Source { get; set; } - [JsonPropertyName("notes")] - public string? Notes { get; set; } + [JsonPropertyName("notes")] public string? Notes { get; set; } - [JsonPropertyName("perks")] - public List Perks { get; set; } + [JsonPropertyName("perks")] public List Perks { get; set; } - [JsonPropertyName("canDrop")] - public bool CanDrop { get; set; } + [JsonPropertyName("canDrop")] public bool CanDrop { get; set; } } public partial class NewWeaponRoll { - public static NewWeaponRoll FromJson(string json) => JsonSerializer.Deserialize(json)!; - public static string ToJson(NewWeaponRoll self) => JsonSerializer.Serialize(self); + public static NewWeaponRoll FromJson(string json) + { + return JsonSerializer.Deserialize(json)!; + } + + public static string ToJson(NewWeaponRoll self) + { + return JsonSerializer.Serialize(self); + } } public class RecommendedRolls @@ -122,6 +122,7 @@ public static class ProcessRollData await using var stream = File.OpenRead(JsonFile); return await JsonSerializer.DeserializeAsync(stream); } + return null; } } \ No newline at end of file diff --git a/Felicity/Program.cs b/Felicity/Program.cs index 96e8ab7..de1ca72 100644 --- a/Felicity/Program.cs +++ b/Felicity/Program.cs @@ -33,7 +33,7 @@ var title = $"Starting Felicity v.{BotVariables.Version} on {Environment.OSVersion}..."; Console.Title = title; Log.Information(title); - + if (!BotVariables.IsDebug) builder.WebHost.UseSentry(options => { diff --git a/Felicity/Services/Hosted/DiscordStartupService.cs b/Felicity/Services/Hosted/DiscordStartupService.cs index 834ad1f..920fd57 100644 --- a/Felicity/Services/Hosted/DiscordStartupService.cs +++ b/Felicity/Services/Hosted/DiscordStartupService.cs @@ -166,7 +166,13 @@ private static async Task OnSlashCommandExecuted(SlashCommandInfo arg1, IInterac var errorEmbed = Embeds.MakeErrorEmbed(); errorEmbed.Title = "Failed to execute command."; - if (result is ExecuteResult { Exception: BungieNetAuthorizationErrorException { Error.ErrorDescription: "AuthorizationRecordExpired" } }) + if (result is ExecuteResult + { + Exception: BungieNetAuthorizationErrorException + { + Error.ErrorDescription: "AuthorizationRecordExpired" + } + }) { errorEmbed.Description = "Your membership info has expired, this can happen due to a Bungie change that happened 2023-08-15.\n\n" + @@ -242,10 +248,7 @@ private async Task OnMessageReceived(SocketMessage socketMessage) var context = new ShardedCommandContext(_discordShardedClient, socketUserMessage); var command = await _commandService.ExecuteAsync(context, argPos, _serviceProvider); - if (command.Error is not null) - { - _logger.LogError("{Error}: {ErrorReason}", command.Error, command.ErrorReason); - } + if (command.Error is not null) _logger.LogError("{Error}: {ErrorReason}", command.Error, command.ErrorReason); } private async Task OnInteractionCreated(SocketInteraction socketInteraction) @@ -295,9 +298,7 @@ private async Task OnInteractionCreated(SocketInteraction socketInteraction) catch (Exception e) { if (e.InnerException is not null && !e.InnerException.Message.StartsWith("Duplicate entry")) - { _logger.LogError(e, "Failed to push metrics"); - } } } diff --git a/Felicity/Services/Hosted/StatusService.cs b/Felicity/Services/Hosted/StatusService.cs index 0f7fd14..75b32b6 100644 --- a/Felicity/Services/Hosted/StatusService.cs +++ b/Felicity/Services/Hosted/StatusService.cs @@ -1,7 +1,6 @@ using Discord; using Discord.WebSocket; using Felicity.Util; -using Serilog; namespace Felicity.Services.Hosted; diff --git a/Felicity/Services/Hosted/TwitchStartupService.cs b/Felicity/Services/Hosted/TwitchStartupService.cs index 26ea67d..893f398 100644 --- a/Felicity/Services/Hosted/TwitchStartupService.cs +++ b/Felicity/Services/Hosted/TwitchStartupService.cs @@ -2,8 +2,8 @@ namespace Felicity.Services.Hosted; public class TwitchStartupService : BackgroundService { - private readonly TwitchService _twitchService; private readonly ILogger _logger; + private readonly TwitchService _twitchService; public TwitchStartupService( TwitchService twitchService, diff --git a/Felicity/Services/TwitchService.cs b/Felicity/Services/TwitchService.cs index 8862536..ad496e2 100644 --- a/Felicity/Services/TwitchService.cs +++ b/Felicity/Services/TwitchService.cs @@ -25,7 +25,7 @@ public class TwitchService public TwitchService( DiscordShardedClient discordClient, - IOptions twitchOptions, + IOptions twitchOptions, TwitchStreamDb twitchStreamDb) { _discordClient = discordClient; diff --git a/Felicity/Util/AutoCompletes.cs b/Felicity/Util/AutoCompletes.cs index 6886e68..79b31d1 100644 --- a/Felicity/Util/AutoCompletes.cs +++ b/Felicity/Util/AutoCompletes.cs @@ -25,7 +25,8 @@ public override async Task GenerateSuggestionsAsync( IParameterInfo parameter, IServiceProvider services) { - var streamList = await _streamDb.TwitchStreams.Where(stream => stream.ServerId == context.Guild.Id).ToListAsync(); + var streamList = await _streamDb.TwitchStreams.Where(stream => stream.ServerId == context.Guild.Id) + .ToListAsync(); if (streamList.Count == 0) return AutocompletionResult.FromError(InteractionCommandError.Unsuccessful, "No streams found."); @@ -63,17 +64,18 @@ public override Task GenerateSuggestionsAsync( if (currentSearch != null) resultList.AddRange(from destinyMetricDefinition in metricsList - where destinyMetricDefinition.DisplayProperties.Name.ToLower().Contains(currentSearch.ToLower()) - select new AutocompleteResult( - $"{destinyMetricDefinition.DisplayProperties.Name} ({destinyMetricDefinition.Traits.Last().Select(x => x.DisplayProperties.Name)})", - destinyMetricDefinition.Hash)); + where destinyMetricDefinition.DisplayProperties.Name.ToLower().Contains(currentSearch.ToLower()) + select new AutocompleteResult( + $"{destinyMetricDefinition.DisplayProperties.Name} ({destinyMetricDefinition.Traits.Last().Select(x => x.DisplayProperties.Name)})", + destinyMetricDefinition.Hash)); else resultList.AddRange(from destinyMetricDefinition in metricsList - select new AutocompleteResult( - $"{destinyMetricDefinition.DisplayProperties.Name} ({destinyMetricDefinition.Traits.Last().Select(x => x.DisplayProperties.Name)})", - destinyMetricDefinition.Hash)); + select new AutocompleteResult( + $"{destinyMetricDefinition.DisplayProperties.Name} ({destinyMetricDefinition.Traits.Last().Select(x => x.DisplayProperties.Name)})", + destinyMetricDefinition.Hash)); - return Task.FromResult(AutocompletionResult.FromSuccess(resultList.OrderBy(_ => Random.Shared.Next()).Take(25))); + return Task.FromResult( + AutocompletionResult.FromSuccess(resultList.OrderBy(_ => Random.Shared.Next()).Take(25))); } } @@ -86,8 +88,8 @@ public override async Task GenerateSuggestionsAsync( IServiceProvider services) { var source = (from autocompleteOption in autocompleteInteraction.Data.Options - where autocompleteOption.Name == "source" - select Enum.Parse(autocompleteOption.Value.ToString() ?? string.Empty)).FirstOrDefault(); + where autocompleteOption.Name == "source" + select Enum.Parse(autocompleteOption.Value.ToString() ?? string.Empty)).FirstOrDefault(); var memCache = await ProcessMementoData.ReadJsonAsync(); @@ -102,8 +104,8 @@ public override async Task GenerateSuggestionsAsync( var currentSearch = autocompleteInteraction.Data.Current.Value.ToString(); var results = (from weapon in goodSource.WeaponList - where currentSearch == null || weapon.WeaponName!.ToLower().Contains(currentSearch.ToLower()) - select new AutocompleteResult { Name = weapon.WeaponName, Value = weapon.WeaponName }).ToList(); + where currentSearch == null || weapon.WeaponName!.ToLower().Contains(currentSearch.ToLower()) + select new AutocompleteResult { Name = weapon.WeaponName, Value = weapon.WeaponName }).ToList(); results = results.OrderBy(x => x.Name).ToList(); @@ -167,7 +169,7 @@ public class RollFinderAutocomplete : AutocompleteHandler public override async Task GenerateSuggestionsAsync( IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, - IParameterInfo parameter, + IParameterInfo parameter, IServiceProvider services) { var weaponList = await ProcessRollData.FromJsonAsync(); @@ -233,9 +235,9 @@ public override async Task GenerateSuggestionsAsync( Enumerable.Empty()); else autocompleteList.AddRange(from officialCp in checkpointList.Official - where $"{officialCp.Activity} {officialCp.Encounter}".ToLower().Contains(currentSearch.ToLower()) - select new AutocompleteResult($"{officialCp.Activity} - {officialCp.Encounter}", - officialCp.DisplayOrder)); + where $"{officialCp.Activity} {officialCp.Encounter}".ToLower().Contains(currentSearch.ToLower()) + select new AutocompleteResult($"{officialCp.Activity} - {officialCp.Encounter}", + officialCp.DisplayOrder)); return AutocompletionResult.FromSuccess(string.IsNullOrEmpty(currentSearch) ? autocompleteList diff --git a/Felicity/Util/BotVariables.cs b/Felicity/Util/BotVariables.cs index dad1869..c3ab0ab 100644 --- a/Felicity/Util/BotVariables.cs +++ b/Felicity/Util/BotVariables.cs @@ -12,7 +12,7 @@ public static class BotVariables internal const string ErrorMessage = $"You can report this error either in our [Support Server]({DiscordInvite}) " + - "or by creating a new [Issue](https://github.com/devFelicity/Bot-Frontend/issues/new?assignees=MoonieGZ&labels=bug&template=bug-report.md&title=) on GitHub."; + "or by creating a new [Issue](https://github.com/devFelicity/Bot-Frontend/issues/new?assignees=MoonieGZ&labels=bug&template=bug-report.md&title=) on GitHub."; internal static bool IsDebug; internal static string? Version; diff --git a/Felicity/Util/BungieAPIUtils.cs b/Felicity/Util/BungieAPIUtils.cs index 133cfbd..1eccb4a 100644 --- a/Felicity/Util/BungieAPIUtils.cs +++ b/Felicity/Util/BungieAPIUtils.cs @@ -32,7 +32,7 @@ public static async Task CheckApi(IBungieClient client) } public static async Task GetLatestProfile( - IBungieClient client, + IBungieClient client, long membershipId, BungieMembershipType membershipType) { @@ -49,7 +49,7 @@ public static async Task GetLatestProfile( public static async Task GetLatestProfileAsync( IBungieClient bungieClient, - string bungieName, + string bungieName, short bungieCode) { var userInfoCard = await bungieClient.ApiAccess.Destiny2.SearchDestinyPlayerByBungieName( diff --git a/Felicity/Util/EmblemReport.cs b/Felicity/Util/EmblemReport.cs index 25cc6f7..944cd51 100644 --- a/Felicity/Util/EmblemReport.cs +++ b/Felicity/Util/EmblemReport.cs @@ -11,8 +11,7 @@ public class EmblemReport { public partial class EmblemResponse { - [JsonPropertyName("data")] - public List Data { get; set; } = null!; + [JsonPropertyName("data")] public List Data { get; set; } = null!; } public class Datum diff --git a/Felicity/Util/EmoteHelper.cs b/Felicity/Util/EmoteHelper.cs index 5848d0e..c2136da 100644 --- a/Felicity/Util/EmoteHelper.cs +++ b/Felicity/Util/EmoteHelper.cs @@ -1,9 +1,9 @@ -using Discord; +using System.Text.Json; +using Discord; using Discord.WebSocket; using DotNetBungieAPI.Models.Destiny; using DotNetBungieAPI.Models.Destiny.Definitions.InventoryItems; using Felicity.Models.Caches; -using System.Text.Json; using Emote = Felicity.Models.Caches.Emote; namespace Felicity.Util; diff --git a/Felicity/Util/HttpClientInstance.cs b/Felicity/Util/HttpClientInstance.cs index fde2b31..9db2609 100644 --- a/Felicity/Util/HttpClientInstance.cs +++ b/Felicity/Util/HttpClientInstance.cs @@ -4,11 +4,5 @@ public static class HttpClientInstance { private static readonly HttpClient? _httpClient; - public static HttpClient Instance - { - get - { - return _httpClient ?? new HttpClient(); - } - } -} + public static HttpClient Instance => _httpClient ?? new HttpClient(); +} \ No newline at end of file diff --git a/Felicity/Util/Preconditions.cs b/Felicity/Util/Preconditions.cs index 7532e0d..595f26b 100644 --- a/Felicity/Util/Preconditions.cs +++ b/Felicity/Util/Preconditions.cs @@ -13,7 +13,7 @@ public class RequireBotModerator : PreconditionAttribute { public override async Task CheckRequirementsAsync( IInteractionContext context, - ICommandInfo commandInfo, + ICommandInfo commandInfo, IServiceProvider services) { if (context.User.Id == BotVariables.BotOwnerId) @@ -37,7 +37,7 @@ public class RequireOAuth : PreconditionAttribute { public override async Task CheckRequirementsAsync( IInteractionContext context, - ICommandInfo commandInfo, + ICommandInfo commandInfo, IServiceProvider services) { await context.Interaction.DeferAsync(); diff --git a/Felicity/Util/ProfileHelper.cs b/Felicity/Util/ProfileHelper.cs index 1253b7d..7fb187d 100644 --- a/Felicity/Util/ProfileHelper.cs +++ b/Felicity/Util/ProfileHelper.cs @@ -7,8 +7,8 @@ namespace Felicity.Util; public abstract class ProfileHelper { public static async Task GetRequestedProfile( - string bungieTag, - ulong discordId, + string bungieTag, + ulong discordId, UserDb userDb, IBungieClient bungieClient) { From ff44ca55d728667c404d0cbae7619a856bed3381 Mon Sep 17 00:00:00 2001 From: Moons Date: Wed, 6 Sep 2023 22:03:41 +0200 Subject: [PATCH 2/6] fix(recipes): fix duplicate messages --- Felicity/DiscordCommands/Interactions/CraftingCommands.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Felicity/DiscordCommands/Interactions/CraftingCommands.cs b/Felicity/DiscordCommands/Interactions/CraftingCommands.cs index 7556583..8b59cfd 100644 --- a/Felicity/DiscordCommands/Interactions/CraftingCommands.cs +++ b/Felicity/DiscordCommands/Interactions/CraftingCommands.cs @@ -240,10 +240,10 @@ public async Task Recipes( i++; - if (invDescription) + if (invDescription && !page.Description.Contains('⚠')) page.Description += "\n\n⚠ = Includes incomplete deepsight weapons."; - if (buyDescription) + if (buyDescription && !page.Description.Contains("💰")) page.Description += "\n\n💰 = A pattern for this weapon can be purchased from the appropriate vendor."; @@ -265,7 +265,7 @@ public async Task Recipes( page.Description += "\n\nYou have completed all available patterns."; pageList.Add(page); } - + continue; } From aaff014f488d62004e5c305ef4c722e1cd174b3f Mon Sep 17 00:00:00 2001 From: Moons Date: Wed, 6 Sep 2023 22:04:51 +0200 Subject: [PATCH 3/6] chore(global): cleanup code --- .../Interactions/EmblemCommands.cs | 62 ++++++++++--------- Felicity/Models/RecommendedRolls.cs | 11 ++-- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/Felicity/DiscordCommands/Interactions/EmblemCommands.cs b/Felicity/DiscordCommands/Interactions/EmblemCommands.cs index a22b692..f6bf653 100644 --- a/Felicity/DiscordCommands/Interactions/EmblemCommands.cs +++ b/Felicity/DiscordCommands/Interactions/EmblemCommands.cs @@ -222,37 +222,39 @@ public async Task EmblemRarest( var manifestCollectibleIDs = AddEmblems(profile.Response); - if (requestedProfile.MembershipId == 4611686018471516071) // Moonie + switch (requestedProfile.MembershipId) { - profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( - BungieMembershipType.TigerSteam, 4611686018500337909, - new[] - { - DestinyComponentType.Collectibles, DestinyComponentType.Profiles - }); - - manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); - } - - if (requestedProfile.MembershipId == 4611686018432393645) // Zempp - { - profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( - BungieMembershipType.TigerPsn, 4611686018475371052, - new[] - { - DestinyComponentType.Collectibles, DestinyComponentType.Profiles - }); - - manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); - - profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( - BungieMembershipType.TigerSteam, 4611686018483360936, - new[] - { - DestinyComponentType.Collectibles, DestinyComponentType.Profiles - }); - - manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); + // Moonie + case 4611686018471516071: + profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( + BungieMembershipType.TigerSteam, 4611686018500337909, + new[] + { + DestinyComponentType.Collectibles, DestinyComponentType.Profiles + }); + + manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); + break; + // Zempp + case 4611686018432393645: + profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( + BungieMembershipType.TigerPsn, 4611686018475371052, + new[] + { + DestinyComponentType.Collectibles, DestinyComponentType.Profiles + }); + + manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); + + profile = await _bungieClient.ApiAccess.Destiny2.GetProfile( + BungieMembershipType.TigerSteam, 4611686018483360936, + new[] + { + DestinyComponentType.Collectibles, DestinyComponentType.Profiles + }); + + manifestCollectibleIDs.AddRange(AddEmblems(profile.Response)); + break; } var manifestCollectibles = new List(); diff --git a/Felicity/Models/RecommendedRolls.cs b/Felicity/Models/RecommendedRolls.cs index 04c8246..d8def2f 100644 --- a/Felicity/Models/RecommendedRolls.cs +++ b/Felicity/Models/RecommendedRolls.cs @@ -99,6 +99,7 @@ public enum WeaponSource Lightfall, RootOfNightmares, GhostsOfTheDeep, + CrotasEnd, SeasonalHunt = 112, SeasonalChosen = 113, SeasonalSplicer = 114, @@ -117,12 +118,10 @@ public static class ProcessRollData public static async Task FromJsonAsync() { - if (File.Exists(JsonFile)) - { - await using var stream = File.OpenRead(JsonFile); - return await JsonSerializer.DeserializeAsync(stream); - } + if (!File.Exists(JsonFile)) + return null; - return null; + await using var stream = File.OpenRead(JsonFile); + return await JsonSerializer.DeserializeAsync(stream); } } \ No newline at end of file From 716d84a3e9eb6ad34766cbc738cf481cfb33f0d6 Mon Sep 17 00:00:00 2001 From: Moons Date: Wed, 6 Sep 2023 22:05:29 +0200 Subject: [PATCH 4/6] feat(craftables): add crota's end --- Felicity/Util/Enums/Craftables.cs | 48 +++++++++++++++++++++------ Felicity/Util/Enums/LootTables.cs | 54 ++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 11 deletions(-) diff --git a/Felicity/Util/Enums/Craftables.cs b/Felicity/Util/Enums/Craftables.cs index 5586f37..b3dad96 100644 --- a/Felicity/Util/Enums/Craftables.cs +++ b/Felicity/Util/Enums/Craftables.cs @@ -7,6 +7,17 @@ internal static class Craftables { public static readonly Dictionary> CraftableList = new() { + { + CraftSource.RaidCe, new List + { + 1294327154, // abyss defiant + 583710954, // fang of ir yut + 3250738778, // oversoul edict + 3859670341, // song of ir yut + 411909019 // swordbreaker + // missing word of crota + } + }, { CraftSource.SeasonWitch, new List { @@ -94,7 +105,7 @@ internal static class Craftables } }, { - CraftSource.DeepStoneCrypt, new List + CraftSource.RaidDsc, new List { DefinitionHashes.Records.Bequest, DefinitionHashes.Records.Commemoration, @@ -105,7 +116,7 @@ internal static class Craftables } }, { - CraftSource.KingsFall, new List + CraftSource.RaidKf, new List { DefinitionHashes.Records.DefianceofYasmin, DefinitionHashes.Records.DoomofChelchis, @@ -223,6 +234,17 @@ internal static class Craftables public static readonly Dictionary> CraftedList = new() { + { + CraftSource.RaidCe, new List + { + 833898322, // abyss defiant + 1432682459, // fang of ir yut + 1098171824, // oversoul edict + 2828278545, // song of ir yut + 3163900678, // swordbreaker + 120706239 // word of crota + } + }, { CraftSource.SeasonWitch, new List { @@ -310,7 +332,7 @@ internal static class Craftables } }, { - CraftSource.DeepStoneCrypt, new List + CraftSource.RaidDsc, new List { DefinitionHashes.InventoryItems.Bequest_3366545721, DefinitionHashes.InventoryItems.Commemoration_4230965989, @@ -321,7 +343,7 @@ internal static class Craftables } }, { - CraftSource.KingsFall, new List + CraftSource.RaidKf, new List { DefinitionHashes.InventoryItems.DefianceofYasmin_3228096719, DefinitionHashes.InventoryItems.DoomofChelchis_1937552980, @@ -441,6 +463,11 @@ public static uint GetWeaponId(uint recordDefinitionHash) { return recordDefinitionHash switch { + 1294327154 => 833898322, // abyss defiant + 583710954 => 1432682459, // fang of ir yut + 3250738778 => 1098171824, // oversoul edict + 3859670341 => 2828278545, // song of ir yut + 411909019 => 3163900678, // swordbreaker DefinitionHashes.Records.BryasLove => DefinitionHashes.InventoryItems.BryasLove_2779821308, DefinitionHashes.Records.EleaticPrinciple => DefinitionHashes.InventoryItems.EleaticPrinciple_105306149, DefinitionHashes.Records.TheEremite => DefinitionHashes.InventoryItems.TheEremite_3347946548, @@ -589,19 +616,20 @@ or DefinitionHashes.InventoryItems.ShapedWeapon_659359923 private static class CraftSource { public const string Anniversary = "30th Anniversary"; - public const string DeepStoneCrypt = "Deep Stone Crypt"; - public const string KingsFall = "Kings Fall"; public const string Lightfall = "Lightfall"; public const string Opulent = "Opulent"; - public const string RaidVotD = "Vow of the Disciple"; - public const string RaidRoN = "Root of Nightmares"; + public const string RaidCe = "Crota's End"; + public const string RaidDsc = "Deep Stone Crypt"; + public const string RaidKf = "Kings Fall"; public const string RaidLw = "Last Wish"; + public const string RaidRoN = "Root of Nightmares"; + public const string RaidVotD = "Vow of the Disciple"; + public const string SeasonDeep = "Deep"; + public const string SeasonDefiance = "Defiance"; public const string SeasonHaunted = "Haunted"; public const string SeasonPlunder = "Plunder"; public const string SeasonRisen = "Risen"; public const string SeasonSeraph = "Seraph"; - public const string SeasonDefiance = "Defiance"; - public const string SeasonDeep = "Deep"; public const string SeasonWitch = "Witch"; public const string Unknown = "Quest / Unknown"; public const string Wq = "Witch Queen"; diff --git a/Felicity/Util/Enums/LootTables.cs b/Felicity/Util/Enums/LootTables.cs index 78052b8..19146e1 100644 --- a/Felicity/Util/Enums/LootTables.cs +++ b/Felicity/Util/Enums/LootTables.cs @@ -50,6 +50,58 @@ public static class LootTables { public static readonly List KnownTables = new() { + new LootTableDefinition + { + ActivityType = ActivityType.Raid, Name = "Crota's End", + Description = "The Dark Below", + Loot = new List + { + new() + { + EncounterType = Encounter.First, EncounterName = "The Abyss", + LootIds = new List + { + (uint)Armor.Chest, (uint)Armor.Boots, (uint)Armor.Class, + 833898322, // abyss defiant + 1432682459, // fang of ir yut + 2828278545 // song of ir yut + } + }, + new() + { + EncounterType = Encounter.Second, EncounterName = "The Bridge", + LootIds = new List + { + (uint)Armor.Gloves, (uint)Armor.Chest, + 1432682459, // fang of ir yut + 3163900678, // swordbreaker + 1098171824 // oversoul edict + } + }, + new() + { + EncounterType = Encounter.Third, EncounterName = "Ir Yût, the Deathsinger", + LootIds = new List + { + (uint)Armor.Gloves, (uint)Armor.Chest, + 1098171824, // oversoul edict + 2828278545, // song of ir yut + 120706239 // word of crota + } + }, + new() + { + EncounterType = Encounter.Boss, EncounterName = "Crota, Son of Oryx", + LootIds = new List + { + (uint)Armor.Helmet, (uint)Armor.Gloves, (uint)Armor.Class, + 833898322, // abyss defiant + 3163900678, // swordbreaker + 120706239 // word of crota + } + } + } + }, new LootTableDefinition { ActivityType = ActivityType.Raid, Name = "Root of Nightmares", @@ -635,4 +687,4 @@ public static class LootTables } } }; -} +} \ No newline at end of file From abe03ee522f80d3a7dfd1d963a7fbf61311f6d81 Mon Sep 17 00:00:00 2001 From: Moons Date: Wed, 6 Sep 2023 22:05:49 +0200 Subject: [PATCH 5/6] chore(deps): update nugets --- Felicity/Felicity.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Felicity/Felicity.csproj b/Felicity/Felicity.csproj index 01f0e46..2461640 100644 --- a/Felicity/Felicity.csproj +++ b/Felicity/Felicity.csproj @@ -22,8 +22,8 @@ - - + + From 0bd97e1f902680457e670c07dbc849d24b58f306 Mon Sep 17 00:00:00 2001 From: Moons Date: Wed, 6 Sep 2023 22:06:37 +0200 Subject: [PATCH 6/6] feat(vendors): use foundry instead of gunsmith --- Felicity/Util/WeaponHelper.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Felicity/Util/WeaponHelper.cs b/Felicity/Util/WeaponHelper.cs index 2ff64c6..b36489e 100644 --- a/Felicity/Util/WeaponHelper.cs +++ b/Felicity/Util/WeaponHelper.cs @@ -1,10 +1,10 @@ -using Discord.WebSocket; +using System.Web; +using Discord.WebSocket; using DotNetBungieAPI.Models.Destiny; using DotNetBungieAPI.Models.Destiny.Components; using DotNetBungieAPI.Models.Destiny.Definitions.InventoryItems; using DotNetBungieAPI.Service.Abstractions; using Felicity.Models.Caches; -using System.Web; // ReSharper disable InconsistentNaming // ReSharper disable UnusedMember.Global @@ -15,8 +15,8 @@ internal static class WeaponHelper { public static string PopulateWeaponPerks( BaseSocketClient discordClient, - List weapons, - bool gunsmithLink) + List weapons, + bool foundryLink) { var result = ""; @@ -30,8 +30,8 @@ public static string PopulateWeaponPerks( } else { - if (gunsmithLink) - result += $"[{weapon.Name}]({BuildGunsmithLink(weapon.WeaponId, weapon.Perks)})\n"; + if (foundryLink) + result += $"[{weapon.Name}]({BuildFoundryLink(weapon.WeaponId, weapon.Perks)})\n"; else result += $"[{weapon.Name}]({MiscUtils.GetLightGgLink(weapon.WeaponId)}/) | "; @@ -109,11 +109,11 @@ public static string BuildLightGGLink(string armorLegendarySet) return $"https://www.light.gg/db/all?page=1&f=12({HttpUtility.UrlEncode(search.TrimEnd(' '))}),3"; } - private static string BuildGunsmithLink( + private static string BuildFoundryLink( uint exoticWeaponWeaponId, Dictionary exoticWeaponPerks) { - var result = $"https://d2gunsmith.com/w/{exoticWeaponWeaponId}?s="; + var result = $"https://d2foundry.gg/w/{exoticWeaponWeaponId}?p="; result = exoticWeaponPerks.Values.Aggregate(result, (current, value) => current + (value.PerkId + ","));