Skip to content

Commit

Permalink
one more approach to parse time
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudokhvist committed Dec 31, 2022
1 parent 750c4fd commit 9830199
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 102 files
4 changes: 2 additions & 2 deletions BoosterCreator/BoosterCreator.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<TargetFrameworks>net7.0;net481</TargetFrameworks>
<Authors>Out</Authors>
<AssemblyVersion>1.2.3.2</AssemblyVersion>
<AssemblyVersion>1.2.4.0</AssemblyVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
28 changes: 17 additions & 11 deletions BoosterCreator/BoosterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,27 @@ private async Task AutoBooster() {
if (bi.Unavailable) {

//God, I hate this shit. But for now I have no idea how to predict/enforce correct format.
string timeFormat;
if (!string.IsNullOrWhiteSpace(bi.AvailableAtTime) && char.IsDigit(bi.AvailableAtTime.Trim()[0])) {
timeFormat = "d MMM @ h:mmtt";
} else {
timeFormat = "MMM d @ h:mmtt";
}

response.AppendLine(Commands.FormatBotResponse(bot, "Crafting booster from " + gameID.Key.ToString() + " will be available at time: " + bi.AvailableAtTime));
bot.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Crafting booster from " + gameID.Key.ToString() + " is not available now"));
//Wait until specified time
if (DateTime.TryParseExact(bi.AvailableAtTime, timeFormat, new CultureInfo("en-US"), DateTimeStyles.None, out DateTime availableAtTime)) {
} else {
List<string> timeFormats = new(){
"d MMM @ h:mmtt",
"MMM d @ h:mmtt",
"d MMM, @ h:mmtt"
};

DateTime availableAtTime = DateTime.MinValue;
foreach (string timeFormat in timeFormats) {
if (DateTime.TryParseExact(bi.AvailableAtTime, timeFormat, new CultureInfo("en-US"), DateTimeStyles.None, out availableAtTime)) {
break;
}
}
if (availableAtTime == DateTime.MinValue) {
bot.ArchiLogger.LogGenericInfo("Unable to parse time \"" + bi.AvailableAtTime + "\", please report this.");
availableAtTime = DateTime.Now.AddHours(8); //fallback to 8 hours in case of error
}

response.AppendLine(Commands.FormatBotResponse(bot, "Crafting booster from " + gameID.Key.ToString() + " will be available at time: " + bi.AvailableAtTime));
bot.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Crafting booster from " + gameID.Key.ToString() + " is not available now"));

if (gameID.Value.HasValue) { //if source is timer, not command
gameIDs[gameID.Key] = availableAtTime;//convertedTime;
bot.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Next attempt to make booster from " + gameID.Key.ToString() + " is planned at " + gameIDs[gameID.Key]!.Value.ToShortDateString() + " " + gameIDs[gameID.Key]!.Value.ToShortTimeString()));
Expand Down
4 changes: 2 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if exist out rmdir /Q /S out

rem release generic version

dotnet publish -c "Release" -f "net6.0" -o "out/generic" "/p:LinkDuringPublish=false"
dotnet publish -c "Release" -f "net7.0" -o "out/generic" "/p:LinkDuringPublish=false"
mkdir .\out\%CurrDirName%
copy .\out\generic\%CurrDirName%.dll .\out\%CurrDirName%
rem comment section below (downto :zip label) if you don't want to include documentation
Expand All @@ -40,7 +40,7 @@ rmdir /Q /S out\%CurrDirName%
rem release generic-netf version
rem comment section below if you don't target netf ASF version

dotnet publish -c "Release" -f "net48" -o "out/generic-netf"
dotnet publish -c "Release" -f "net481" -o "out/generic-netf"
mkdir .\out\%CurrDirName%
copy .\out\generic-netf\%CurrDirName%.dll .\out\%CurrDirName%
rem comment section below (downto :zipnetf label) if you don't want to include documentation
Expand Down

0 comments on commit 9830199

Please sign in to comment.