Skip to content

Commit 650386f

Browse files
authored
Merge pull request #7 from pk9r/dev
release v1.1.1
2 parents f5b1cae + bb061b9 commit 650386f

File tree

11 files changed

+157
-74
lines changed

11 files changed

+157
-74
lines changed

GitcgNetCord.sln.DotSettings.user

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEmojiProperties_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F6ab3be37dec913ef7d649338adbdc7ba6ecf9e17ad69af5d293b71d60e4be5a_003FEmojiProperties_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
33
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AReactionEmojiProperties_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Ffa944ea7b9c605f0445098be8ca0ce31dd212e446a97d32b344db96e36aa95_003FReactionEmojiProperties_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
4-
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASlashCommandChoiceAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F70977d8e8e415d5c5286c84b973d39d27dd1744ed6edc99adee5b82899ff31_003FSlashCommandChoiceAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
4+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASlashCommandChoiceAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F70977d8e8e415d5c5286c84b973d39d27dd1744ed6edc99adee5b82899ff31_003FSlashCommandChoiceAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
5+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AValidateOptionsResultBuilder_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Ff7c3fb89ef359986fa6049c62f921cb5a184ae6b30dcddaffc3d5ab7fcd77_003FValidateOptionsResultBuilder_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
6+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AValidateOptionsResult_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003F728062cbf4f62ed8eda2cc948368227a2c54cae9679f89fb68c439f71b7576_003FValidateOptionsResult_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@
22

33
# Table of Contents
44

5-
## ⚙️ Core Libraries & APIs
5+
1. [⚙️ Core Libraries & APIs](#1-️-core-libraries--apis)
6+
2. [📄 Documentation](#2--documentation)
7+
3. [🩹 Support](#3--support)
8+
4. [📜 License](#4--license)
9+
5. [🛠️ Development](#5-%EF%B8%8F-development)
10+
11+
## 1. ⚙️ Core Libraries & APIs
612

713
- [NetCord](https://github.com/NetCordDev/NetCord): For Discord interaction.
814
- [ImageSharp](https://github.com/SixLabors/ImageSharp): For image processing.
915
- [SkiaSharp](https://github.com/mono/SkiaSharp): Migration from ImageSharp to SkiaSharp in future versions.
1016

11-
## 📄 Documentation
17+
## 2. 📄 Documentation
18+
19+
- [Github Wiki](https://github.com/pk9r/gitcg-netcord/wiki): Comprehensive documentation for the project.
1220

13-
## 🩹 Support
21+
## 3. 🩹 Support
1422

1523
- [Discord Server](https://discord.gg/7ME6bwkQSs): Join for support and discussions.
1624

17-
## 📜 License
25+
## 4. 📜 License
1826

1927
This repository is released under the [MIT License](LICENSE.md).
2028

21-
## 🛠️ Development
29+
## 5. 🛠️ Development
2230

2331
### Versioning
2432

src/GitcgNetCord.MainApp/Commands/Autocompletes/SharingCodeAutocompleteProvider.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,37 +74,37 @@ async ValueTask AddDecodeMessage()
7474
if (keyword.Length != SharedConstants.SharingCodeLength)
7575
return;
7676

77-
try
78-
{
79-
var decoded = await hoyolab.DecodeCardCodeAsync(keyword);
80-
81-
var rolesDisplay = string.Join(
82-
separator: ", ",
83-
decoded.RoleCards.Select(x => x.Basic.Name)
84-
);
85-
86-
var displayBuilder = new StringBuilder();
87-
displayBuilder.Append(rolesDisplay);
88-
displayBuilder.Append(" - ");
89-
displayBuilder.Append($"{decoded.ActionCards.Count} Cards");
77+
var decoded = await hoyolab.DecodeCardCodeAsync(keyword);
9078

91-
suggestions.Insert(
92-
index: 0,
93-
item: new ApplicationCommandOptionChoiceProperties(
94-
name: displayBuilder.ToString(),
95-
stringValue: keyword
96-
)
97-
);
98-
}
99-
catch (Exception e)
79+
if (decoded.Validate.Failed)
10080
{
10181
suggestions.Add(
10282
new ApplicationCommandOptionChoiceProperties(
103-
name: e.Message,
83+
name: decoded.Validate.FailureMessage,
10484
stringValue: keyword
10585
)
10686
);
87+
88+
return;
10789
}
90+
91+
var rolesDisplay = string.Join(
92+
separator: ", ",
93+
decoded.Data.RoleCards.Select(x => x.Basic.Name)
94+
);
95+
96+
var displayBuilder = new StringBuilder();
97+
displayBuilder.Append(rolesDisplay);
98+
displayBuilder.Append(" - ");
99+
displayBuilder.Append($"{decoded.Data.ActionCards.Count} Cards");
100+
101+
suggestions.Insert(
102+
index: 0,
103+
item: new ApplicationCommandOptionChoiceProperties(
104+
name: displayBuilder.ToString(),
105+
stringValue: keyword
106+
)
107+
);
108108
}
109109

110110
async ValueTask AddAccountDecks()
@@ -135,7 +135,7 @@ async ValueTask AddAccountDecks()
135135
stringValue: keyword
136136
)
137137
);
138-
138+
139139
return;
140140
}
141141

@@ -197,4 +197,4 @@ static void LimitNameLength(StringBuilder nameBuilder)
197197
nameBuilder.Length = 97;
198198
nameBuilder.Append("...");
199199
}
200-
}
200+
}

src/GitcgNetCord.MainApp/Commands/Slash/DeckSlashCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ await context.Interaction.SendResponseAsync(
6565
lang: lang
6666
);
6767

68-
if (!decodeResult.IsValid)
68+
if (decodeResult.Validate.Failed)
6969
{
7070
await context.Interaction.ModifyResponseAsync(message => message
7171
.AddEmbeds(new EmbedProperties()
7272
.WithTitle("Invalid sharing code")
73-
// .WithDescription(decodeResult.ErrorMessage)
73+
.WithDescription(string.Join('\n', decodeResult.Validate.Failures))
7474
.WithColor(new NetCord.Color(Color.Red.ToArgb()))
7575
)
7676
);

src/GitcgNetCord.MainApp/Commands/Slash/TcgSlashCommand.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ await context.Interaction.SendResponseAsync(
6464
var redColor = new NetCord.Color(Color.Red.ToArgb());
6565

6666
HoyolabHttpClient.Responses.GcgBasicInfo.Data info;
67-
67+
6868
try
6969
{
7070
info = await gcgBasicInfoService
@@ -121,10 +121,13 @@ await context.Interaction.ModifyResponseAsync(message =>
121121
string GetRoleEmojis(IEnumerable<string> s)
122122
{
123123
var roles = s.Select(url => cardRoles.Roles
124-
.First(x => x.Basic.IconSmall == url)
124+
.FirstOrDefault(x => x.Basic.IconSmall == url)
125+
);
126+
var ids = roles.Select(x => x?.Basic.ItemId.ToString());
127+
return string.Join(
128+
separator: " ",
129+
values: ids.Select(id => id == null ? ":question:" : emojis[id].ToString())
125130
);
126-
var ids = roles.Select(x => x.Basic.ItemId.ToString());
127-
return string.Join(" ", ids.Select(id => emojis[id]));
128131
}
129132

130133
string DisplayName(string name, bool isWin)
@@ -159,4 +162,4 @@ private static string GetServerValue(
159162
_ => server
160163
};
161164
}
162-
}
165+
}

src/GitcgNetCord.MainApp/GatewayHandlers/CardCodeGatewayHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private async Task<MatchesResult>
217217
var result = await decoder.DecodeAsync(sharingCode);
218218

219219
var added = false;
220-
if (result.IsValid)
220+
if (result.Validate.Succeeded)
221221
{
222222
var deck = result.Deck;
223223
items.Add(new ItemResult(deck, sharingCode));

src/GitcgNetCord.MainApp/Infrastructure/HoyolabServices/HoyolabDecoder.cs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,69 @@
22
using GitcgNetCord.MainApp.Models;
33
using HoyolabHttpClient;
44
using HoyolabHttpClient.Models.Interfaces;
5+
using Microsoft.Extensions.Options;
6+
using SharedUtils;
57

68
namespace GitcgNetCord.MainApp.Infrastructure.HoyolabServices;
79

810
public class HoyolabDecoder(
911
HoyolabHttpClientService hoyolab
1012
)
1113
{
12-
public async Task<DecodeResult> DecodeAsync(
14+
public async ValueTask<DecodeResult> DecodeAsync(
1315
string sharingCode,
1416
SharingCodeValidationRuleType validationRule =
1517
SharingCodeValidationRuleType.Playable,
1618
string lang = "en-us"
1719
)
1820
{
19-
IDeckData deck;
20-
try
21+
var resultBuilder = new ValidateOptionsResultBuilder();
22+
23+
if (sharingCode.Length != SharedConstants.SharingCodeLength)
2124
{
22-
deck = await hoyolab.DecodeCardCodeAsync(
23-
code: sharingCode, lang: lang
25+
resultBuilder.AddError(
26+
error: $"Sharing code must be {SharedConstants.SharingCodeLength} characters long.",
27+
propertyName: nameof(sharingCode)
2428
);
29+
30+
return new DecodeResult(Validate: resultBuilder.Build());
2531
}
26-
catch
32+
33+
var decodeResult = await hoyolab.DecodeCardCodeAsync(
34+
code: sharingCode, lang: lang
35+
);
36+
37+
if (decodeResult.Validate.Failed)
2738
{
28-
return new DecodeResult(IsValid: false);
39+
resultBuilder.AddResult(decodeResult.Validate);
40+
return new DecodeResult(resultBuilder.Build());
2941
}
3042

43+
ExecutePlayableValidateRule();
44+
3145
return new DecodeResult(
32-
IsValid: true, Deck: deck
46+
resultBuilder.Build(),
47+
Deck: decodeResult.Data
3348
);
49+
50+
void ExecutePlayableValidateRule()
51+
{
52+
if (validationRule != SharingCodeValidationRuleType.Playable)
53+
return;
54+
55+
if (decodeResult.Data.RoleCards.Count != 3)
56+
{
57+
resultBuilder.AddError(
58+
error: "Deck must have exactly 3 role cards."
59+
);
60+
}
61+
62+
if (decodeResult.Data.ActionCards.Count != 30)
63+
{
64+
resultBuilder.AddError(
65+
"Deck must have exactly 30 action cards."
66+
);
67+
}
68+
}
3469
}
35-
}
70+
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
using HoyolabHttpClient.Models.Interfaces;
1+
using System.ComponentModel.DataAnnotations;
2+
using System.Diagnostics.CodeAnalysis;
3+
using HoyolabHttpClient.Models.Interfaces;
4+
using Microsoft.Extensions.Options;
25

36
namespace GitcgNetCord.MainApp.Models;
47

58
public record DecodeResult(
6-
bool IsValid,
9+
ValidateOptionsResult Validate,
710
IDeckData Deck = null!
8-
);
11+
);

0 commit comments

Comments
 (0)