diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index 6b92fc4ee..fda361848 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -59,7 +59,7 @@ namespace ArchiSteamFarm { Unknown = 0, Trading = 1, // Only custom below, different than ones available as user_notification_type - Items = 255 + Items = 254 } internal readonly HashSet Notifications; @@ -71,8 +71,13 @@ namespace ArchiSteamFarm { JobID = jobID; + if (msg.notifications.Count == 0) { + return; + } + Notifications = new HashSet(); foreach (CMsgClientUserNotifications.Notification notification in msg.notifications) { + Logging.LogGenericDebug("Pushed new notification: " + notification.user_notification_type); Notifications.Add((ENotification) notification.user_notification_type); } } @@ -85,7 +90,8 @@ namespace ArchiSteamFarm { JobID = jobID; if (msg.count_new_items > 0) { - Notifications = new HashSet { ENotification.Items }; + Logging.LogGenericDebug("Pushed new items notification"); + Notifications = new HashSet { ENotification.Items }; } } } diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index d3e18eb35..7df5f79eb 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1963,6 +1963,8 @@ namespace ArchiSteamFarm { return; } + Logging.LogGenericDebug("Received notifications: " + string.Join(", ", callback.Notifications), BotName); + foreach (ArchiHandler.NotificationsCallback.ENotification notification in callback.Notifications) { switch (notification) { case ArchiHandler.NotificationsCallback.ENotification.Items: diff --git a/ArchiSteamFarm/JSON/GitHub.cs b/ArchiSteamFarm/JSON/GitHub.cs index c7024d006..5eaef704c 100644 --- a/ArchiSteamFarm/JSON/GitHub.cs +++ b/ArchiSteamFarm/JSON/GitHub.cs @@ -27,22 +27,23 @@ using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; namespace ArchiSteamFarm.JSON { - internal static class GitHub { - [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global"), SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] - internal sealed class ReleaseResponse { - internal sealed class Asset { - [JsonProperty(PropertyName = "name", Required = Required.Always)] - internal string Name { get; private set; } + internal static class GitHub { + [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] + internal sealed class ReleaseResponse { + internal sealed class Asset { + [JsonProperty(PropertyName = "name", Required = Required.Always)] + internal string Name { get; private set; } - [JsonProperty(PropertyName = "browser_download_url", Required = Required.Always)] - internal string DownloadURL { get; private set; } - } + [JsonProperty(PropertyName = "browser_download_url", Required = Required.Always)] + internal string DownloadURL { get; private set; } + } - [JsonProperty(PropertyName = "tag_name", Required = Required.Always)] - internal string Tag { get; private set; } + [JsonProperty(PropertyName = "tag_name", Required = Required.Always)] + internal string Tag { get; private set; } - [JsonProperty(PropertyName = "assets", Required = Required.Always)] - internal List Assets { get; private set; } - } - } + [JsonProperty(PropertyName = "assets", Required = Required.Always)] + internal List Assets { get; private set; } + } + } } diff --git a/ArchiSteamFarm/JSON/Steam.cs b/ArchiSteamFarm/JSON/Steam.cs index 513bffee3..2d4a17b2a 100644 --- a/ArchiSteamFarm/JSON/Steam.cs +++ b/ArchiSteamFarm/JSON/Steam.cs @@ -29,297 +29,304 @@ using Newtonsoft.Json; using SteamKit2; namespace ArchiSteamFarm.JSON { - internal static class Steam { - internal sealed class Item { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_Asset - internal const ushort SteamAppID = 753; - internal const byte SteamContextID = 6; + internal static class Steam { + internal sealed class Item { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_Asset + internal const ushort SteamAppID = 753; + internal const byte SteamContextID = 6; - internal enum EType : byte { - Unknown, + internal enum EType : byte { + Unknown, - BoosterPack, - Coupon, - Gift, - SteamGems, + BoosterPack, + Coupon, + Gift, + SteamGems, - Emoticon, - FoilTradingCard, - ProfileBackground, - TradingCard - } + Emoticon, + FoilTradingCard, + ProfileBackground, + TradingCard + } - internal uint AppID { get; set; } + internal uint AppID { get; set; } - [JsonProperty(PropertyName = "appid", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")] - private string AppIDString { - get { - return AppID.ToString(); - } + [JsonProperty(PropertyName = "appid", Required = Required.DisallowNull)] + [SuppressMessage("ReSharper", "UnusedMember.Local")] + private string AppIDString { + get { + return AppID.ToString(); + } - set { - if (string.IsNullOrEmpty(value)) { - return; - } + set { + if (string.IsNullOrEmpty(value)) { + return; + } - uint result; - if (!uint.TryParse(value, out result)) { - return; - } + uint result; + if (!uint.TryParse(value, out result)) { + return; + } - AppID = result; - } - } + AppID = result; + } + } - internal ulong ContextID { get; set; } + internal ulong ContextID { get; set; } - [JsonProperty(PropertyName = "contextid", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")] - private string ContextIDString { - get { - return ContextID.ToString(); - } + [JsonProperty(PropertyName = "contextid", Required = Required.DisallowNull)] + [SuppressMessage("ReSharper", "UnusedMember.Local")] + private string ContextIDString { + get { + return ContextID.ToString(); + } - set { - if (string.IsNullOrEmpty(value)) { - return; - } + set { + if (string.IsNullOrEmpty(value)) { + return; + } - ulong result; - if (!ulong.TryParse(value, out result)) { - return; - } + ulong result; + if (!ulong.TryParse(value, out result)) { + return; + } - ContextID = result; - } - } + ContextID = result; + } + } - internal ulong AssetID { get; set; } + internal ulong AssetID { get; set; } - [JsonProperty(PropertyName = "assetid", Required = Required.DisallowNull)] - private string AssetIDString { - get { - return AssetID.ToString(); - } + [JsonProperty(PropertyName = "assetid", Required = Required.DisallowNull)] + private string AssetIDString { + get { + return AssetID.ToString(); + } - set { - if (string.IsNullOrEmpty(value)) { - return; - } + set { + if (string.IsNullOrEmpty(value)) { + return; + } - ulong result; - if (!ulong.TryParse(value, out result)) { - return; - } + ulong result; + if (!ulong.TryParse(value, out result)) { + return; + } - AssetID = result; - } - } + AssetID = result; + } + } - [JsonProperty(PropertyName = "id", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")] - private string ID { - get { return AssetIDString; } - set { AssetIDString = value; } - } + [JsonProperty(PropertyName = "id", Required = Required.DisallowNull)] + [SuppressMessage("ReSharper", "UnusedMember.Local")] + private string ID { + get { return AssetIDString; } + set { AssetIDString = value; } + } - internal ulong ClassID { get; set; } + internal ulong ClassID { get; set; } - [JsonProperty(PropertyName = "classid", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")] - private string ClassIDString { - get { - return ClassID.ToString(); - } + [JsonProperty(PropertyName = "classid", Required = Required.DisallowNull)] + [SuppressMessage("ReSharper", "UnusedMember.Local")] + private string ClassIDString { + get { + return ClassID.ToString(); + } - set { - if (string.IsNullOrEmpty(value)) { - return; - } + set { + if (string.IsNullOrEmpty(value)) { + return; + } - ulong result; - if (!ulong.TryParse(value, out result)) { - return; - } + ulong result; + if (!ulong.TryParse(value, out result)) { + return; + } - ClassID = result; - } - } + ClassID = result; + } + } - internal ulong InstanceID { get; set; } + internal ulong InstanceID { private get; set; } - [JsonProperty(PropertyName = "instanceid", Required = Required.DisallowNull), SuppressMessage("ReSharper", "UnusedMember.Local")] - private string InstanceIDString { - get { - return InstanceID.ToString(); - } + [JsonProperty(PropertyName = "instanceid", Required = Required.DisallowNull)] + [SuppressMessage("ReSharper", "UnusedMember.Local")] + private string InstanceIDString { + get { + return InstanceID.ToString(); + } - set { - if (string.IsNullOrEmpty(value)) { - return; - } + set { + if (string.IsNullOrEmpty(value)) { + return; + } - ulong result; - if (!ulong.TryParse(value, out result)) { - return; - } + ulong result; + if (!ulong.TryParse(value, out result)) { + return; + } - InstanceID = result; - } - } + InstanceID = result; + } + } - internal uint Amount { get; set; } + internal uint Amount { get; set; } - [JsonProperty(PropertyName = "amount", Required = Required.Always), SuppressMessage("ReSharper", "UnusedMember.Local")] - private string AmountString { - get { - return Amount.ToString(); - } + [JsonProperty(PropertyName = "amount", Required = Required.Always)] + [SuppressMessage("ReSharper", "UnusedMember.Local")] + private string AmountString { + get { + return Amount.ToString(); + } - set { - if (string.IsNullOrEmpty(value)) { - return; - } + set { + if (string.IsNullOrEmpty(value)) { + return; + } - uint result; - if (!uint.TryParse(value, out result)) { - return; - } + uint result; + if (!uint.TryParse(value, out result)) { + return; + } - Amount = result; - } - } + Amount = result; + } + } - internal uint RealAppID { get; set; } - internal EType Type { get; set; } - } + internal uint RealAppID { get; set; } + internal EType Type { get; set; } + } - internal sealed class TradeOffer { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer - [SuppressMessage("ReSharper", "UnusedMember.Global")] - internal enum ETradeOfferState : byte { - Unknown, - Invalid, - Active, - Accepted, - Countered, - Expired, - Canceled, - Declined, - InvalidItems, - EmailPending, - EmailCanceled, - OnHold - } + internal sealed class TradeOffer { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer + [SuppressMessage("ReSharper", "UnusedMember.Global")] + internal enum ETradeOfferState : byte { + Unknown, + Invalid, + Active, + Accepted, + Countered, + Expired, + Canceled, + Declined, + InvalidItems, + EmailPending, + EmailCanceled, + OnHold + } - internal ulong TradeOfferID { get; set; } + internal ulong TradeOfferID { get; set; } - [JsonProperty(PropertyName = "tradeofferid", Required = Required.Always), SuppressMessage("ReSharper", "UnusedMember.Local")] - private string TradeOfferIDString { - get { - return TradeOfferID.ToString(); - } + [JsonProperty(PropertyName = "tradeofferid", Required = Required.Always)] + [SuppressMessage("ReSharper", "UnusedMember.Local")] + private string TradeOfferIDString { + get { + return TradeOfferID.ToString(); + } - set { - if (string.IsNullOrEmpty(value)) { - return; - } + set { + if (string.IsNullOrEmpty(value)) { + return; + } - ulong result; - if (!ulong.TryParse(value, out result)) { - return; - } + ulong result; + if (!ulong.TryParse(value, out result)) { + return; + } - TradeOfferID = result; - } - } + TradeOfferID = result; + } + } - [JsonProperty(PropertyName = "accountid_other", Required = Required.Always)] - internal uint OtherSteamID3 { private get; set; } + [JsonProperty(PropertyName = "accountid_other", Required = Required.Always)] + internal uint OtherSteamID3 { private get; set; } - [JsonProperty(PropertyName = "trade_offer_state", Required = Required.Always)] - internal ETradeOfferState State { get; set; } + [JsonProperty(PropertyName = "trade_offer_state", Required = Required.Always)] + internal ETradeOfferState State { get; set; } - [JsonProperty(PropertyName = "items_to_give", Required = Required.Always)] - internal HashSet ItemsToGive { get; } = new HashSet(); + [JsonProperty(PropertyName = "items_to_give", Required = Required.Always)] + internal HashSet ItemsToGive { get; } = new HashSet(); - [JsonProperty(PropertyName = "items_to_receive", Required = Required.Always)] - internal HashSet ItemsToReceive { get; } = new HashSet(); + [JsonProperty(PropertyName = "items_to_receive", Required = Required.Always)] + internal HashSet ItemsToReceive { get; } = new HashSet(); - // Extra - internal ulong OtherSteamID64 => OtherSteamID3 == 0 ? 0 : new SteamID(OtherSteamID3, EUniverse.Public, EAccountType.Individual); + // Extra + internal ulong OtherSteamID64 => OtherSteamID3 == 0 ? 0 : new SteamID(OtherSteamID3, EUniverse.Public, EAccountType.Individual); - internal bool IsSteamCardsOnlyTradeForUs() => ItemsToGive.All(item => (item.AppID == Item.SteamAppID) && (item.ContextID == Item.SteamContextID) && ((item.Type == Item.EType.FoilTradingCard) || (item.Type == Item.EType.TradingCard))); + internal bool IsSteamCardsOnlyTradeForUs() => ItemsToGive.All(item => (item.AppID == Item.SteamAppID) && (item.ContextID == Item.SteamContextID) && ((item.Type == Item.EType.FoilTradingCard) || (item.Type == Item.EType.TradingCard))); - internal bool IsPotentiallyDupesTradeForUs() { - Dictionary> itemsToGivePerGame = new Dictionary>(); - foreach (Item item in ItemsToGive) { - Dictionary itemsPerType; - if (!itemsToGivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) { - itemsPerType = new Dictionary { [item.Type] = item.Amount }; - itemsToGivePerGame[item.RealAppID] = itemsPerType; - } else { - uint amount; - if (itemsPerType.TryGetValue(item.Type, out amount)) { - itemsPerType[item.Type] = amount + item.Amount; - } else { - itemsPerType[item.Type] = item.Amount; - } - } - } + internal bool IsPotentiallyDupesTradeForUs() { + Dictionary> itemsToGivePerGame = new Dictionary>(); + foreach (Item item in ItemsToGive) { + Dictionary itemsPerType; + if (!itemsToGivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) { + itemsPerType = new Dictionary { [item.Type] = item.Amount }; + itemsToGivePerGame[item.RealAppID] = itemsPerType; + } else { + uint amount; + if (itemsPerType.TryGetValue(item.Type, out amount)) { + itemsPerType[item.Type] = amount + item.Amount; + } else { + itemsPerType[item.Type] = item.Amount; + } + } + } - Dictionary> itemsToReceivePerGame = new Dictionary>(); - foreach (Item item in ItemsToReceive) { - Dictionary itemsPerType; - if (!itemsToReceivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) { - itemsPerType = new Dictionary { [item.Type] = item.Amount }; - itemsToReceivePerGame[item.RealAppID] = itemsPerType; - } else { - uint amount; - if (itemsPerType.TryGetValue(item.Type, out amount)) { - itemsPerType[item.Type] = amount + item.Amount; - } else { - itemsPerType[item.Type] = item.Amount; - } - } - } + Dictionary> itemsToReceivePerGame = new Dictionary>(); + foreach (Item item in ItemsToReceive) { + Dictionary itemsPerType; + if (!itemsToReceivePerGame.TryGetValue(item.RealAppID, out itemsPerType)) { + itemsPerType = new Dictionary { [item.Type] = item.Amount }; + itemsToReceivePerGame[item.RealAppID] = itemsPerType; + } else { + uint amount; + if (itemsPerType.TryGetValue(item.Type, out amount)) { + itemsPerType[item.Type] = amount + item.Amount; + } else { + itemsPerType[item.Type] = item.Amount; + } + } + } - // Ensure that amount of items to give is at least amount of items to receive (per game and per type) - foreach (KeyValuePair> itemsPerGame in itemsToGivePerGame) { - Dictionary otherItemsPerType; - if (!itemsToReceivePerGame.TryGetValue(itemsPerGame.Key, out otherItemsPerType)) { - return false; - } + // Ensure that amount of items to give is at least amount of items to receive (per game and per type) + foreach (KeyValuePair> itemsPerGame in itemsToGivePerGame) { + Dictionary otherItemsPerType; + if (!itemsToReceivePerGame.TryGetValue(itemsPerGame.Key, out otherItemsPerType)) { + return false; + } - foreach (KeyValuePair itemsPerType in itemsPerGame.Value) { - uint otherAmount; - if (!otherItemsPerType.TryGetValue(itemsPerType.Key, out otherAmount)) { - return false; - } + foreach (KeyValuePair itemsPerType in itemsPerGame.Value) { + uint otherAmount; + if (!otherItemsPerType.TryGetValue(itemsPerType.Key, out otherAmount)) { + return false; + } - if (itemsPerType.Value > otherAmount) { - return false; - } - } - } + if (itemsPerType.Value > otherAmount) { + return false; + } + } + } - return true; - } - } + return true; + } + } - [SuppressMessage("ReSharper", "UnusedMember.Global")] - internal sealed class TradeOfferRequest { - internal sealed class ItemList { - [JsonProperty(PropertyName = "assets", Required = Required.Always)] - internal HashSet Assets { get; } = new HashSet(); - } + [SuppressMessage("ReSharper", "UnusedMember.Global")] + internal sealed class TradeOfferRequest { + internal sealed class ItemList { + [JsonProperty(PropertyName = "assets", Required = Required.Always)] + internal HashSet Assets { get; } = new HashSet(); + } - [JsonProperty(PropertyName = "newversion", Required = Required.Always)] - internal bool NewVersion { get; } = true; + [JsonProperty(PropertyName = "newversion", Required = Required.Always)] + internal bool NewVersion { get; } = true; - [JsonProperty(PropertyName = "version", Required = Required.Always)] - internal byte Version { get; } = 2; + [JsonProperty(PropertyName = "version", Required = Required.Always)] + internal byte Version { get; } = 2; - [JsonProperty(PropertyName = "me", Required = Required.Always)] - internal ItemList ItemsToGive { get; } = new ItemList(); + [JsonProperty(PropertyName = "me", Required = Required.Always)] + internal ItemList ItemsToGive { get; } = new ItemList(); - [JsonProperty(PropertyName = "them", Required = Required.Always)] - internal ItemList ItemsToReceive { get; } = new ItemList(); - } - } + [JsonProperty(PropertyName = "them", Required = Required.Always)] + internal ItemList ItemsToReceive { get; } = new ItemList(); + } + } } diff --git a/ArchiSteamFarm/Logging.cs b/ArchiSteamFarm/Logging.cs index dc39d3c20..750ebc14e 100644 --- a/ArchiSteamFarm/Logging.cs +++ b/ArchiSteamFarm/Logging.cs @@ -29,143 +29,143 @@ using System.IO; using System.Runtime.CompilerServices; namespace ArchiSteamFarm { - internal static class Logging { - private static readonly object FileLock = new object(); + internal static class Logging { + private static readonly object FileLock = new object(); - private static bool LogToFile; + private static bool LogToFile; - internal static void Init() { - LogToFile = Program.GlobalConfig.LogToFile; + internal static void Init() { + LogToFile = Program.GlobalConfig.LogToFile; - if (!LogToFile) { - return; - } + if (!LogToFile) { + return; + } - lock (FileLock) { - if (!LogToFile) { - return; - } + lock (FileLock) { + if (!LogToFile) { + return; + } - try { - File.Delete(Program.LogFile); - } catch (Exception e) { - LogToFile = false; - LogGenericException(e); - } - } - } + try { + File.Delete(Program.LogFile); + } catch (Exception e) { + LogToFile = false; + LogGenericException(e); + } + } + } - internal static void LogGenericWTF(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } + internal static void LogGenericWTF(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message), botName); + return; + } - Log("[!!] WTF: " + previousMethodName + "() <" + botName + "> " + message + ", WTF?"); - } + Log("[!!] WTF: " + previousMethodName + "() <" + botName + "> " + message + ", WTF?"); + } - internal static void LogGenericError(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } + internal static void LogGenericError(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message), botName); + return; + } - Log("[!!] ERROR: " + previousMethodName + "() <" + botName + "> " + message); - } + Log("[!!] ERROR: " + previousMethodName + "() <" + botName + "> " + message); + } - internal static void LogGenericException(Exception exception, string botName = "Main", [CallerMemberName] string previousMethodName = null) { - while (true) { - if (exception == null) { - LogNullError(nameof(exception), botName); - return; - } + internal static void LogGenericException(Exception exception, string botName = "Main", [CallerMemberName] string previousMethodName = null) { + while (true) { + if (exception == null) { + LogNullError(nameof(exception), botName); + return; + } - Log("[!] EXCEPTION: " + previousMethodName + "() <" + botName + "> " + exception.Message); - Log("[!] StackTrace:" + Environment.NewLine + exception.StackTrace); + Log("[!] EXCEPTION: " + previousMethodName + "() <" + botName + "> " + exception.Message); + Log("[!] StackTrace:" + Environment.NewLine + exception.StackTrace); - if (exception.InnerException != null) { - exception = exception.InnerException; - continue; - } + if (exception.InnerException != null) { + exception = exception.InnerException; + continue; + } - break; - } - } + break; + } + } - internal static void LogGenericWarning(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } + internal static void LogGenericWarning(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message), botName); + return; + } - Log("[!] WARNING: " + previousMethodName + "() <" + botName + "> " + message); - } + Log("[!] WARNING: " + previousMethodName + "() <" + botName + "> " + message); + } - internal static void LogGenericInfo(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } + internal static void LogGenericInfo(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message), botName); + return; + } - Log("[*] INFO: " + previousMethodName + "() <" + botName + "> " + message); - } + Log("[*] INFO: " + previousMethodName + "() <" + botName + "> " + message); + } - [SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")] - internal static void LogNullError(string nullObjectName, string botName = "Main", [CallerMemberName] string previousMethodName = null) { - while (true) { - if (string.IsNullOrEmpty(nullObjectName)) { - nullObjectName = nameof(nullObjectName); - continue; - } + [SuppressMessage("ReSharper", "ExplicitCallerInfoArgument")] + internal static void LogNullError(string nullObjectName, string botName = "Main", [CallerMemberName] string previousMethodName = null) { + while (true) { + if (string.IsNullOrEmpty(nullObjectName)) { + nullObjectName = nameof(nullObjectName); + continue; + } - LogGenericError(nullObjectName + " is null!", botName, previousMethodName); - break; - } - } + LogGenericError(nullObjectName + " is null!", botName, previousMethodName); + break; + } + } - [Conditional("DEBUG"), SuppressMessage("ReSharper", "UnusedMember.Global")] - internal static void LogGenericDebug(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message), botName); - return; - } + [SuppressMessage("ReSharper", "UnusedMember.Global")] + internal static void LogGenericDebug(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message), botName); + return; + } - Log("[#] DEBUG: " + previousMethodName + "() <" + botName + "> " + message); - } + Log("[#] DEBUG: " + previousMethodName + "() <" + botName + "> " + message); + } - private static void Log(string message) { - if (string.IsNullOrEmpty(message)) { - LogNullError(nameof(message)); - return; - } + private static void Log(string message) { + if (string.IsNullOrEmpty(message)) { + LogNullError(nameof(message)); + return; + } - string loggedMessage = DateTime.Now + " " + message + Environment.NewLine; + string loggedMessage = DateTime.Now + " " + message + Environment.NewLine; - // Write on console only when not awaiting response from user - if (!Program.ConsoleIsBusy) { - try { - Console.Write(loggedMessage); - } catch { - // Ignored - } - } + // Write on console only when not awaiting response from user + if (!Program.ConsoleIsBusy) { + try { + Console.Write(loggedMessage); + } catch { + // Ignored + } + } - if (!LogToFile) { - return; - } + if (!LogToFile) { + return; + } - lock (FileLock) { - if (!LogToFile) { - return; - } + lock (FileLock) { + if (!LogToFile) { + return; + } - try { - File.AppendAllText(Program.LogFile, loggedMessage); - } catch (Exception e) { - LogToFile = false; - LogGenericException(e); - } - } - } - } + try { + File.AppendAllText(Program.LogFile, loggedMessage); + } catch (Exception e) { + LogToFile = false; + LogGenericException(e); + } + } + } + } }