mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Add a feature of accepting steam gifts, closes #18
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user