Implement manual farming, closes #78

This commit is contained in:
JustArchi
2016-01-22 10:45:01 +01:00
parent 73b5246a88
commit 948787f8ba
2 changed files with 50 additions and 1 deletions

View File

@@ -670,6 +670,27 @@ namespace ArchiSteamFarm {
return await bot.ResponseRedeem(message, validate).ConfigureAwait(false);
}
internal static async Task<string> ResponsePlay(string botName, string game) {
if (string.IsNullOrEmpty(botName) || string.IsNullOrEmpty(game)) {
return null;
}
Bot bot;
if (!Bots.TryGetValue(botName, out bot)) {
return "Couldn't find any bot named " + botName + "!";
}
uint gameID;
if (!uint.TryParse(game, out gameID)) {
return "Couldn't parse game as a number!";
}
await bot.CardsFarmer.SwitchToManualMode(gameID != 0).ConfigureAwait(false);
bot.ArchiHandler.PlayGames(gameID);
return "Done!";
}
internal static string ResponseStart(string botName) {
if (string.IsNullOrEmpty(botName)) {
return null;
@@ -743,6 +764,12 @@ namespace ArchiSteamFarm {
return Response2FA(args[1]);
case "!2faoff":
return Response2FAOff(args[1]);
case "!play":
if (args.Length > 2) {
return await ResponsePlay(args[1], args[2]).ConfigureAwait(false);
} else {
return await ResponsePlay(BotName, args[1]).ConfigureAwait(false);
}
case "!redeem":
string botName;
string key;
@@ -1052,7 +1079,7 @@ namespace ArchiSteamFarm {
Trading.CheckTrades();
await CardsFarmer.StartFarming().ConfigureAwait(false);
var start = Task.Run(async () => await CardsFarmer.StartFarming().ConfigureAwait(false));
break;
case EResult.NoConnection:
case EResult.ServiceUnavailable:

View File

@@ -45,6 +45,7 @@ namespace ArchiSteamFarm {
internal readonly ConcurrentDictionary<uint, float> GamesToFarm = new ConcurrentDictionary<uint, float>();
internal readonly List<uint> CurrentGamesFarming = new List<uint>();
private bool ManualMode = false;
private bool NowFarming = false;
internal CardsFarmer(Bot bot) {
@@ -85,6 +86,22 @@ namespace ArchiSteamFarm {
return 0;
}
internal async Task SwitchToManualMode(bool manualMode) {
if (ManualMode == manualMode) {
return;
}
ManualMode = manualMode;
if (ManualMode) {
Logging.LogGenericInfo(Bot.BotName, "Now running in Manual Farming mode");
await StopFarming().ConfigureAwait(false);
} else {
Logging.LogGenericInfo(Bot.BotName, "Now running in Automatic Farming mode");
var start = Task.Run(async () => await StartFarming().ConfigureAwait(false));
}
}
internal bool FarmMultiple(ConcurrentDictionary<uint, float> appIDs) {
if (appIDs.Count == 0) {
return true;
@@ -140,6 +157,11 @@ namespace ArchiSteamFarm {
internal async Task StartFarming() {
await Semaphore.WaitAsync().ConfigureAwait(false);
if (ManualMode) {
Semaphore.Release(); // We have nothing to do, don't forget to release semaphore
return;
}
if (!await IsAnythingToFarm().ConfigureAwait(false)) {
Semaphore.Release(); // We have nothing to do, don't forget to release semaphore
return;