Skip to content

Commit

Permalink
Make softban log level (#3831)
Browse files Browse the repository at this point in the history
Replace last softban message line with new one to prevent spam.
  • Loading branch information
iBorna authored and dddbliss committed Aug 9, 2016
1 parent 358d8e7 commit c03c9b8
Show file tree
Hide file tree
Showing 10 changed files with 2,035 additions and 1,984 deletions.
3,950 changes: 1,975 additions & 1,975 deletions PoGo.NecroBot.CLI/Config/Translations/translation.vi.json

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions PoGo.NecroBot.CLI/ConsoleEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,21 @@ private static void HandleEvent(FortUsedEvent fortUsedEvent, ISession session)

private static void HandleEvent(FortFailedEvent fortFailedEvent, ISession session)
{
Logger.Write(
if (fortFailedEvent.Try != 1 && fortFailedEvent.Looted == false)
{
Logger.lineSelect(0, 1);
}

if (fortFailedEvent.Looted == true)
{
Logger.Write(
session.Translation.GetTranslation(TranslationString.SoftBanBypassed),
LogLevel.SoftBan);
} else {
Logger.Write(
session.Translation.GetTranslation(TranslationString.EventFortFailed, fortFailedEvent.Name, fortFailedEvent.Try, fortFailedEvent.Max),
LogLevel.Pokestop, ConsoleColor.DarkRed);
LogLevel.SoftBan);
}
}

private static void HandleEvent(FortTargetEvent fortTargetEvent, ISession session)
Expand All @@ -119,7 +131,7 @@ private static void HandleEvent(FortTargetEvent fortTargetEvent, ISession sessio
Logger.Write(
session.Translation.GetTranslation(TranslationString.EventFortTargeted, fortTargetEvent.Name ),
// Math.Round(fortTargetEvent.Distance), intTimeForArrival ),
LogLevel.Info, ConsoleColor.DarkRed);
LogLevel.Info);
}

private static void HandleEvent(PokemonCaptureEvent pokemonCaptureEvent, ISession session)
Expand Down
11 changes: 10 additions & 1 deletion PoGo.NecroBot.CLI/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,22 @@ public void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor c
break;
case LogLevel.New:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine( $"[{DateTime.Now.ToString( "HH:mm:ss" )}] ({LoggingStrings.New}) {message}" );
Console.WriteLine($"[{DateTime.Now.ToString( "HH:mm:ss" )}] ({LoggingStrings.New}) {message}" );
break;
case LogLevel.SoftBan:
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.SoftBan}) {message}");
break;
default:
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Error}) {message}");
break;
}
}

public void lineSelect(int lineChar = 0, int linesUp = 1)
{
Console.SetCursorPosition(lineChar, Console.CursorTop - linesUp);
}
}
}
6 changes: 6 additions & 0 deletions PoGo.NecroBot.CLI/Models/LoggingStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ internal class LoggingStrings

internal static string New;

internal static string SoftBan;

internal static void SetStrings(ISession session)
{
Attention =
Expand Down Expand Up @@ -96,6 +98,10 @@ internal static void SetStrings(ISession session)
New =
session?.Translation.GetTranslation(
TranslationString.LogEntryNew ) ?? "NEW";

SoftBan =
session?.Translation.GetTranslation(
TranslationString.LogEntrySoftBan) ?? "SOFTBAN";
}
}
}
2 changes: 1 addition & 1 deletion PoGo.NecroBot.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void Main(string[] args)
if (args.Length > 0)
subPath = args[0];

Logger.SetLogger(new ConsoleLogger(LogLevel.New), subPath);
Logger.SetLogger(new ConsoleLogger(LogLevel.SoftBan), subPath);

if( CheckKillSwitch() )
return;
Expand Down
5 changes: 5 additions & 0 deletions PoGo.NecroBot.Logic/Common/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public enum TranslationString
LogEntryDebug,
LogEntryUpdate,
LogEntryNew,
LogEntrySoftBan,
LoggingIn,
PtcOffline,
AccessTokenExpired,
Expand Down Expand Up @@ -166,6 +167,7 @@ public enum TranslationString
EventUsedIncense,
SnipeServerOffline,
PromptError,
SoftBanBypassed,
FirstStartLanguagePrompt,
FirstStartLanguageCodePrompt,
FirstStartLanguageConfirm,
Expand Down Expand Up @@ -286,6 +288,7 @@ public class Translation : ITranslation
new KeyValuePair<TranslationString, string>(TranslationString.LogEntryDebug, "DEBUG"),
new KeyValuePair<TranslationString, string>(TranslationString.LogEntryUpdate, "UPDATE"),
new KeyValuePair<TranslationString, string>(TranslationString.LogEntryNew, "NEW"),
new KeyValuePair<TranslationString, string>(TranslationString.LogEntrySoftBan, "SOFTBAN"),
new KeyValuePair<TranslationString, string>(TranslationString.LoggingIn, "Logging in using {0}"),
new KeyValuePair<TranslationString, string>(TranslationString.PtcOffline,
"PTC Servers are probably down OR your credentials are wrong. Try google"),
Expand Down Expand Up @@ -445,6 +448,8 @@ public class Translation : ITranslation
new KeyValuePair<TranslationString, string>(TranslationString.FirstStartSetupDefaultLatConfirm, "Lattitude accepted: {0}"),
new KeyValuePair<TranslationString, string>(TranslationString.FirstStartSetupDefaultLongPrompt, "Please enter a Longitude (Right click to paste)"),
new KeyValuePair<TranslationString, string>(TranslationString.FirstStartSetupDefaultLongConfirm, "Longitude accepted: {0}"),
new KeyValuePair<TranslationString, string>(TranslationString.SoftBanBypassed,
"Successfully bypassed!"),
new KeyValuePair<TranslationString, string>(TranslationString.FirstStartSetupCompleted, "### COMPLETED CONFIG SETUP ###")
};

Expand Down
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/Event/FortFailedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public class FortFailedEvent : IEvent
public int Max;
public string Name;
public int Try;
public bool Looted;
}
}
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/Logging/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public interface ILogger
/// <param name="level">Optional. Default <see cref="LogLevel.Info" />.</param>
/// <param name="color">Optional. Default automatic color.</param>
void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor color = ConsoleColor.Black);
void lineSelect(int lineChar = 0, int linesUp = 1);
}
}
8 changes: 7 additions & 1 deletion PoGo.NecroBot.Logic/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public static void Write(string message, LogLevel level = LogLevel.Info, Console
if (!_isGui)
Log(string.Concat($"[{DateTime.Now.ToString("HH:mm:ss")}] ", message), force);
}

public static void lineSelect(int lineChar = 0, int linesUp = 1)
{
_logger.lineSelect(lineChar, linesUp);
}
}

public enum LogLevel
Expand All @@ -107,6 +112,7 @@ public enum LogLevel
Update = 13,
Info = 14,
New = 15,
Debug = 16,
SoftBan = 16,
Debug = 17,
}
}
17 changes: 14 additions & 3 deletions PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
{
if ((int) fortSearch.CooldownCompleteTimestampMs != 0)
{
break;
// Check if successfully looted, if so program can continue as this was "false alarm".
break; // Check if successfully looted, if so program can continue as this was "false alarm".
}

fortTry += 1;
Expand All @@ -126,14 +125,26 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
{
Name = fortInfo.Name,
Try = fortTry,
Max = retryNumber - zeroCheck
Max = retryNumber - zeroCheck,
Looted = false
});

DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
}
}
else
{
if (fortTry != 0)
{
session.EventDispatcher.Send(new FortFailedEvent
{
Name = fortInfo.Name,
Try = fortTry + 1,
Max = retryNumber - zeroCheck,
Looted = true
});
}

session.EventDispatcher.Send(new FortUsedEvent
{
Id = pokeStop.Id,
Expand Down

0 comments on commit c03c9b8

Please sign in to comment.