Add a feature of accepting steam gifts, closes #18

This commit is contained in:
JustArchi
2016-03-27 23:07:00 +02:00
parent 2554794daa
commit 8048d4a7aa
5 changed files with 82 additions and 3 deletions

View File

@@ -172,6 +172,7 @@ namespace ArchiSteamFarm {
SteamApps = SteamClient.GetHandler<SteamApps>();
CallbackManager.Subscribe<SteamApps.FreeLicenseCallback>(OnFreeLicense);
CallbackManager.Subscribe<SteamApps.GuestPassListCallback>(OnGuestPassList);
SteamFriends = SteamClient.GetHandler<SteamFriends>();
CallbackManager.Subscribe<SteamFriends.ChatInviteCallback>(OnChatInvite);
@@ -1299,6 +1300,7 @@ namespace ArchiSteamFarm {
}
Logging.LogGenericInfo("Disconnected from Steam!", BotName);
ArchiWebHandler.OnDisconnected();
CardsFarmer.StopFarming().Forget();
// If we initiated disconnect, do not attempt to reconnect
@@ -1347,6 +1349,41 @@ namespace ArchiSteamFarm {
}
}
private async void OnGuestPassList(SteamApps.GuestPassListCallback callback) {
if (callback == null || callback.Result != EResult.OK || callback.CountGuestPassesToRedeem <= 0 || !BotConfig.AcceptGifts) {
return;
}
for (byte i = 0; i < WebBrowser.MaxRetries && !ArchiWebHandler.IsInitialized; i++) {
await Utilities.SleepAsync(1000).ConfigureAwait(false);
}
if (!ArchiWebHandler.IsInitialized) {
Logging.LogGenericWarning("Reached timeout while waiting for ArchiWebHandler to initialize!");
return;
}
bool acceptedSomething = false;
foreach (KeyValue guestPass in callback.GuestPasses) {
ulong gid = guestPass["gid"].AsUnsignedLong();
if (gid == 0) {
continue;
}
Logging.LogGenericInfo("Accepting gift: " + gid + "...", BotName);
if (await ArchiWebHandler.AcceptGift(gid).ConfigureAwait(false)) {
acceptedSomething = true;
Logging.LogGenericInfo("Success!", BotName);
} else {
Logging.LogGenericInfo("Failed!", BotName);
}
}
if (acceptedSomething) {
CardsFarmer.RestartFarming().Forget();
}
}
private void OnChatInvite(SteamFriends.ChatInviteCallback callback) {
if (callback == null || !IsMaster(callback.PatronID)) {
return;