Skip to content

Commit

Permalink
Remove time convertor, it's not needed anymore. Also improved logging…
Browse files Browse the repository at this point in the history
…/responses
  • Loading branch information
Rudokhvist committed Jul 13, 2019
1 parent 0c3a1a2 commit c22930e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 51 deletions.
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 114 files
4 changes: 2 additions & 2 deletions BoosterCreator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Global
{C485E0CB-4D22-4A09-8CBA-83D1300A83DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C485E0CB-4D22-4A09-8CBA-83D1300A83DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C485E0CB-4D22-4A09-8CBA-83D1300A83DC}.Release|Any CPU.Build.0 = Release|Any CPU
{CF84911C-2C4C-4195-8AF3-ABBB6D3DE9AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF84911C-2C4C-4195-8AF3-ABBB6D3DE9AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF84911C-2C4C-4195-8AF3-ABBB6D3DE9AA}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{CF84911C-2C4C-4195-8AF3-ABBB6D3DE9AA}.Debug|Any CPU.Build.0 = Release|Any CPU
{CF84911C-2C4C-4195-8AF3-ABBB6D3DE9AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF84911C-2C4C-4195-8AF3-ABBB6D3DE9AA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
4 changes: 2 additions & 2 deletions BoosterCreator/BoosterCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class BoosterCreator : IBotModules, IBotCommand {
public string Name => nameof(BoosterCreator);
public Version Version => typeof(BoosterCreator).Assembly.GetName().Version;

public void OnLoaded() => ASF.ArchiLogger.LogGenericInfo("BoosterCreator ASF Plugin by Out | Support: https://steamcommunity.com/id/outzzz");
public void OnLoaded() => ASF.ArchiLogger.LogGenericInfo("BoosterCreator ASF Plugin by Out (https://steamcommunity.com/id/outzzz) | fork by Ryzhehvost");

public async Task<string> OnBotCommand(Bot bot, ulong steamID, string message, string[] args) => await Commands.Response(bot, steamID, message, args).ConfigureAwait(false);

Expand All @@ -30,7 +30,7 @@ public async void OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JToken>
BoosterHandler.BoosterHandlers[bot.BotName] = null;
}

bot.ArchiLogger.LogGenericInfo("GamesToBooster:" + string.Join(",", configProperty.Value));
bot.ArchiLogger.LogGenericInfo("GamesToBooster : " + string.Join(",", configProperty.Value));
await Task.Run(() => BoosterHandler.BoosterHandlers[bot.BotName] = new BoosterHandler(bot, configProperty.Value.ToObject<HashSet<uint>>())).ConfigureAwait(false);
break;
}
Expand Down
13 changes: 8 additions & 5 deletions BoosterCreator/BoosterCreator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Composition.AttributedModel" Version="1.3.0-preview.19073.11" />
<Compile Remove="ValveTimeZone.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ArchiSteamFarm\ArchiSteamFarm\ArchiSteamFarm.csproj" />
<PackageReference Include="System.Composition.AttributedModel" Version="1.3.0-preview5.19224.8" />
</ItemGroup>

<ItemGroup>
<Reference Include="SteamKit2">
<HintPath>..\ArchiSteamFarm\ArchiSteamFarm\lib\SteamKit2.dll</HintPath>
</Reference>
<ProjectReference Include="..\ArchiSteamFarm\ArchiSteamFarm\ArchiSteamFarm.csproj" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="mkdir $(TargetDir)BoosterCreator&#xD;&#xA;copy $(TargetPath) $(TargetDir)BoosterCreator\&#xD;&#xA;7z a -tzip -mx7 BoosterCreator.zip $(TargetDir)BoosterCreator" />
</Target>


</Project>
43 changes: 28 additions & 15 deletions BoosterCreator/BoosterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ internal sealed class BoosterHandler : IDisposable {

internal BoosterHandler([NotNull] Bot bot, IReadOnlyCollection<uint> gameIDs) {
Bot = bot ?? throw new ArgumentNullException(nameof(bot));
foreach (var gameID in gameIDs) {
foreach (uint gameID in gameIDs) {
GameIDs.TryAdd(gameID, DateTime.Now.AddHours(1));
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Auto-attepmt to make booster from " + gameID.ToString() + " is planned at " + GameIDs[gameID].Value.ToShortDateString() + " " + GameIDs[gameID].Value.ToShortTimeString()));
}

BoosterTimer = new Timer(
Expand All @@ -43,8 +44,9 @@ private async Task AutoBooster() {
return;
}

string response = await CreateBooster(Bot, GameIDs).ConfigureAwait(false);
ASF.ArchiLogger.LogGenericInfo(response);
//string response =
await CreateBooster(Bot, GameIDs).ConfigureAwait(false);
//ASF.ArchiLogger.LogGenericInfo(response);
}

internal static async Task<string> CreateBooster(Bot bot, ConcurrentDictionary<uint, DateTime?> gameIDs) {
Expand All @@ -59,14 +61,16 @@ internal static async Task<string> CreateBooster(Bot bot, ConcurrentDictionary<u
if (boosterPage == null) {
bot.ArchiLogger.LogNullError(nameof(boosterPage));

return Strings.WarningFailed;
return Commands.FormatBotResponse(bot, string.Format(Strings.ErrorFailingRequest, boosterPage)); ;
}

MatchCollection gooAmounts = Regex.Matches(boosterPage.Text, "(?<=parseFloat\\( \")[0-9]+");
Match info = Regex.Match(boosterPage.Text, "\\[\\{\"[\\s\\S]*\"}]");

if (!info.Success || (gooAmounts.Count != 3)) {
return Strings.WarningFailed;
bot.ArchiLogger.LogGenericError(string.Format(Strings.ErrorParsingObject, boosterPage));
return Commands.FormatBotResponse(bot, string.Format(Strings.ErrorParsingObject, boosterPage));
//return Strings.WarningFailed;
}

uint gooAmount = uint.Parse(gooAmounts[0].Value);
Expand All @@ -77,39 +81,44 @@ internal static async Task<string> CreateBooster(Bot bot, ConcurrentDictionary<u

StringBuilder response = new StringBuilder();

foreach (var gameID in gameIDs) {
foreach (KeyValuePair<uint, DateTime?> gameID in gameIDs) {
if (!gameID.Value.HasValue || DateTime.Compare(gameID.Value.Value, DateTime.Now) <= 0) {
await Task.Delay(500).ConfigureAwait(false);

if (!boosterInfos.ContainsKey(gameID.Key)) {
response.AppendLine(Commands.FormatBotResponse(bot, string.Format(Strings.BotAddLicense, gameID, "NotEligible")));
response.AppendLine(Commands.FormatBotResponse(bot, "Not eligible to create boosters from " + gameID.Key.ToString()));
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Not eligible to create boosters from " + gameID.Key.ToString()));
//If we are not eligible - wait 8 hours, just in case game will be added to account later
if (gameID.Value.HasValue) { //if source is timer, not command
gameIDs[gameID.Key] = DateTime.Now.AddHours(8);
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Next attepmt to make booster from " + gameID.Key.ToString() + " is planned at " + gameIDs[gameID.Key].Value.ToShortDateString() + " " + gameIDs[gameID.Key].Value.ToShortTimeString()));
}
continue;
}

Steam.BoosterInfo bi = boosterInfos[gameID.Key];

if (gooAmount < bi.Price) {
response.AppendLine(Commands.FormatBotResponse(bot, string.Format(Strings.BotAddLicense, gameID, "NotEnoughGems")));
response.AppendLine(Commands.FormatBotResponse(bot, "Not enough gems to create booster from " + gameID.Key.ToString()));
//If we have not enough gems - wait 8 hours, just in case gems will be added to account later
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Not enough gems to create booster from " + gameID.Key.ToString()));
if (gameID.Value.HasValue) { //if source is timer, not command
gameIDs[gameID.Key] = DateTime.Now.AddHours(8);
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Next attepmt to make booster from " + gameID.Key.ToString() + " is planned at " + gameIDs[gameID.Key].Value.ToShortDateString() + " " + gameIDs[gameID.Key].Value.ToShortTimeString()));
}
continue;
}

if (bi.Unavailable) {
response.AppendLine(Commands.FormatBotResponse(bot, string.Format(Strings.BotAddLicense, gameID, $"Available at time: {bi.AvailableAtTime}")));
response.AppendLine(Commands.FormatBotResponse(bot, "Crafting booster from " + gameID.Key.ToString() + "will be available at time: " + bi.AvailableAtTime));
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Crafting booster from " + gameID.Key.ToString() + " is not availiable now"));
//Wait until specified time
DateTime availableAtTime;

if (DateTime.TryParseExact(bi.AvailableAtTime, "d MMM @ h:mmtt", CultureInfo.CurrentCulture, DateTimeStyles.None, out availableAtTime)) {
DateTime convertedTime = TimeZoneInfo.ConvertTime(availableAtTime, ValveTimeZone.GetTimeZoneInfo(), TimeZoneInfo.Local);
if (DateTime.TryParseExact(bi.AvailableAtTime, "d MMM @ h:mmtt", CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime availableAtTime)) {
/*DateTime convertedTime = TimeZoneInfo.ConvertTime(availableAtTime, ValveTimeZone.GetTimeZoneInfo(), TimeZoneInfo.Local);*/
if (gameID.Value.HasValue) { //if source is timer, not command
gameIDs[gameID.Key] = convertedTime;
gameIDs[gameID.Key] = availableAtTime;//convertedTime;
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Next attepmt to make booster from " + gameID.Key.ToString() + " is planned at " + gameIDs[gameID.Key].Value.ToShortDateString() + " " + gameIDs[gameID.Key].Value.ToShortTimeString()));
}
} else {
ASF.ArchiLogger.LogGenericInfo("Unable to parse time \"" + bi.AvailableAtTime + "\", please report this.");
Expand All @@ -128,21 +137,25 @@ internal static async Task<string> CreateBooster(Bot bot, ConcurrentDictionary<u
Steam.BoostersResponse result = await WebRequest.CreateBooster(bot, bi.AppID, bi.Series, nTp).ConfigureAwait(false);

if (result?.Result?.Result != EResult.OK) {
response.AppendLine(Commands.FormatBotResponse(bot, string.Format(Strings.BotAddLicense, bi.AppID, EResult.Fail)));
response.AppendLine(Commands.FormatBotResponse(bot, "Failed to create booster from " + gameID.Key.ToString()));
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Failed to create booster from " + gameID.Key.ToString()));
//Some unhandled error - wait 8 hours before retry
if (gameID.Value.HasValue) { //if source is timer, not command
gameIDs[gameID.Key] = DateTime.Now.AddHours(8);
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Next attepmt to make booster from " + gameID.Key.ToString() + " is planned at " + gameIDs[gameID.Key].Value.ToShortDateString() + " " + gameIDs[gameID.Key].Value.ToShortTimeString()));
}
continue;
}

gooAmount = result.GooAmount;
tradableGooAmount = result.TradableGooAmount;
unTradableGooAmount = result.UntradableGooAmount;
response.AppendLine(Commands.FormatBotResponse(bot, string.Format(Strings.BotAddLicenseWithItems, bi.AppID, EResult.OK, bi.Name)));
response.AppendLine(Commands.FormatBotResponse(bot, "Successfuly created booster from " + gameID.Key.ToString()));
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Successfuly created booster from " + gameID.Key.ToString()));
//Buster was made - next is only available in 24 hours
if (gameID.Value.HasValue) { //if source is timer, not command
gameIDs[gameID.Key] = DateTime.Now.AddHours(24);
ASF.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Next attepmt to make booster from " + gameID.Key.ToString() + " is planned at " + gameIDs[gameID.Key].Value.ToShortDateString() + " " + gameIDs[gameID.Key].Value.ToShortTimeString()));
}
}

Expand Down
26 changes: 0 additions & 26 deletions BoosterCreator/ValveTimeZone.cs

This file was deleted.

4 changes: 4 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
del .\BoosterCreator\*.zip
dotnet publish -c "Release" -f "net472" -o "out/generic-netf"
rename .\BoosterCreator\BoosterCreator.zip BoosterCreator-netf.zip
dotnet publish -c "Release" -f "netcoreapp2.2" -o "out/generic" "/p:LinkDuringPublish=false"

0 comments on commit c22930e

Please sign in to comment.