mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
More code cleanups
This commit is contained in:
parent
1ebd9888be
commit
6a811008eb
7 changed files with 181 additions and 71 deletions
|
@ -616,6 +616,7 @@ limitations under the License.</s:String>
|
|||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GC/@EntryIndexedValue">GC</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GID/@EntryIndexedValue">GID</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HTML/@EntryIndexedValue">HTML</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IASF/@EntryIndexedValue">IASF</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPC/@EntryIndexedValue">IPC</s:String>
|
||||
|
@ -690,6 +691,7 @@ limitations under the License.</s:String>
|
|||
<s:Boolean x:Key="/Default/UserDictionary/Words/=bot_0027s/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=broadcasted/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Domeradzki/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=IASF/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=splitted/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=uptime/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0141ukasz/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using ArchiSteamFarm.Localization;
|
||||
using JetBrains.Annotations;
|
||||
|
@ -97,7 +99,7 @@ namespace ArchiSteamFarm.Json {
|
|||
#pragma warning disable IDE0051
|
||||
[JsonProperty(PropertyName = "amount", Required = Required.Always)]
|
||||
private string AmountText {
|
||||
get => Amount.ToString();
|
||||
get => Amount.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
set {
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
|
@ -120,7 +122,7 @@ namespace ArchiSteamFarm.Json {
|
|||
#pragma warning disable IDE0052
|
||||
[JsonProperty(PropertyName = "assetid", Required = Required.DisallowNull)]
|
||||
private string AssetIDText {
|
||||
get => AssetID.ToString();
|
||||
get => AssetID.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
set {
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
|
@ -162,7 +164,7 @@ namespace ArchiSteamFarm.Json {
|
|||
#pragma warning disable IDE0051
|
||||
[JsonProperty(PropertyName = "contextid", Required = Required.DisallowNull)]
|
||||
private string ContextIDText {
|
||||
get => ContextID.ToString();
|
||||
get => ContextID.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
set {
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
|
@ -210,8 +212,20 @@ namespace ArchiSteamFarm.Json {
|
|||
|
||||
// Constructed from trades being received or plugins
|
||||
public Asset(uint appID, ulong contextID, ulong classID, uint amount, ulong instanceID = 0, ulong assetID = 0, bool marketable = true, bool tradable = true, ImmutableHashSet<Tag>? tags = null, uint realAppID = 0, EType type = EType.Unknown, ERarity rarity = ERarity.Unknown) {
|
||||
if ((appID == 0) || (contextID == 0) || (classID == 0) || (amount == 0)) {
|
||||
throw new ArgumentNullException(nameof(appID) + " || " + nameof(contextID) + " || " + nameof(classID) + " || " + nameof(amount));
|
||||
if (appID == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(appID));
|
||||
}
|
||||
|
||||
if (contextID == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(contextID));
|
||||
}
|
||||
|
||||
if (classID == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(classID));
|
||||
}
|
||||
|
||||
if (amount == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(amount));
|
||||
}
|
||||
|
||||
AppID = appID;
|
||||
|
@ -226,7 +240,7 @@ namespace ArchiSteamFarm.Json {
|
|||
Type = type;
|
||||
Rarity = rarity;
|
||||
|
||||
if ((tags != null) && (tags.Count > 0)) {
|
||||
if (tags?.Count > 0) {
|
||||
Tags = tags;
|
||||
}
|
||||
}
|
||||
|
@ -239,19 +253,15 @@ namespace ArchiSteamFarm.Json {
|
|||
public sealed class Tag {
|
||||
[JsonProperty(PropertyName = "category", Required = Required.Always)]
|
||||
[PublicAPI]
|
||||
public readonly string? Identifier;
|
||||
public string? Identifier { get; private set; }
|
||||
|
||||
[JsonProperty(PropertyName = "internal_name", Required = Required.Always)]
|
||||
[PublicAPI]
|
||||
public readonly string? Value;
|
||||
public string? Value { get; private set; }
|
||||
|
||||
internal Tag(string identifier, string value) {
|
||||
if (string.IsNullOrEmpty(identifier) || string.IsNullOrEmpty(value)) {
|
||||
throw new ArgumentNullException(nameof(identifier) + " || " + nameof(value));
|
||||
}
|
||||
|
||||
Identifier = identifier;
|
||||
Value = value;
|
||||
Identifier = !string.IsNullOrEmpty(identifier) ? identifier : throw new ArgumentNullException(nameof(identifier));
|
||||
Value = !string.IsNullOrEmpty(value) ? value : throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
|
@ -288,7 +298,7 @@ namespace ArchiSteamFarm.Json {
|
|||
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
|
||||
public class BooleanResponse {
|
||||
[JsonProperty(PropertyName = "success", Required = Required.Always)]
|
||||
public readonly bool Success;
|
||||
public bool Success { get; private set; }
|
||||
|
||||
[JsonConstructor]
|
||||
protected BooleanResponse() { }
|
||||
|
@ -298,7 +308,7 @@ namespace ArchiSteamFarm.Json {
|
|||
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
|
||||
public class EResultResponse {
|
||||
[JsonProperty(PropertyName = "success", Required = Required.Always)]
|
||||
public readonly EResult Result;
|
||||
public EResult Result { get; private set; }
|
||||
|
||||
[JsonConstructor]
|
||||
protected EResultResponse() { }
|
||||
|
@ -306,15 +316,6 @@ namespace ArchiSteamFarm.Json {
|
|||
|
||||
// REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer
|
||||
public sealed class TradeOffer {
|
||||
[PublicAPI]
|
||||
public readonly ulong OtherSteamID64;
|
||||
|
||||
[PublicAPI]
|
||||
public readonly ETradeOfferState State;
|
||||
|
||||
[PublicAPI]
|
||||
public readonly ulong TradeOfferID;
|
||||
|
||||
[PublicAPI]
|
||||
public IReadOnlyCollection<Asset> ItemsToGiveReadOnly => ItemsToGive;
|
||||
|
||||
|
@ -324,10 +325,27 @@ namespace ArchiSteamFarm.Json {
|
|||
internal readonly HashSet<Asset> ItemsToGive = new HashSet<Asset>();
|
||||
internal readonly HashSet<Asset> ItemsToReceive = new HashSet<Asset>();
|
||||
|
||||
[PublicAPI]
|
||||
public ulong OtherSteamID64 { get; private set; }
|
||||
|
||||
[PublicAPI]
|
||||
public ETradeOfferState State { get; private set; }
|
||||
|
||||
[PublicAPI]
|
||||
public ulong TradeOfferID { get; private set; }
|
||||
|
||||
// Constructed from trades being received
|
||||
internal TradeOffer(ulong tradeOfferID, uint otherSteamID3, ETradeOfferState state) {
|
||||
if ((tradeOfferID == 0) || (otherSteamID3 == 0) || !Enum.IsDefined(typeof(ETradeOfferState), state)) {
|
||||
throw new ArgumentNullException(nameof(tradeOfferID) + " || " + nameof(otherSteamID3) + " || " + nameof(state));
|
||||
if (tradeOfferID == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(tradeOfferID));
|
||||
}
|
||||
|
||||
if (otherSteamID3 == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(otherSteamID3));
|
||||
}
|
||||
|
||||
if (!Enum.IsDefined(typeof(ETradeOfferState), state)) {
|
||||
throw new InvalidEnumArgumentException(nameof(state), (int) state, typeof(ETradeOfferState));
|
||||
}
|
||||
|
||||
TradeOfferID = tradeOfferID;
|
||||
|
@ -411,7 +429,7 @@ namespace ArchiSteamFarm.Json {
|
|||
case "droprate_2":
|
||||
return Asset.ERarity.Rare;
|
||||
default:
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value));
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -434,7 +452,7 @@ namespace ArchiSteamFarm.Json {
|
|||
switch (tag.Identifier) {
|
||||
case "Game":
|
||||
if (string.IsNullOrEmpty(tag.Value) || (tag.Value!.Length <= 4) || !tag.Value.StartsWith("app_", StringComparison.Ordinal)) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value));
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -472,7 +490,7 @@ namespace ArchiSteamFarm.Json {
|
|||
case "cardborder_1":
|
||||
return Asset.EType.FoilTradingCard;
|
||||
default:
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value));
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value));
|
||||
|
||||
return Asset.EType.Unknown;
|
||||
}
|
||||
|
@ -510,7 +528,7 @@ namespace ArchiSteamFarm.Json {
|
|||
case "item_class_15":
|
||||
return Asset.EType.AnimatedAvatar;
|
||||
default:
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value));
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value));
|
||||
|
||||
return Asset.EType.Unknown;
|
||||
}
|
||||
|
@ -712,8 +730,28 @@ namespace ArchiSteamFarm.Json {
|
|||
|
||||
// Constructed from privacy change request
|
||||
internal PrivacySettings(ArchiHandler.EPrivacySetting profile, ArchiHandler.EPrivacySetting ownedGames, ArchiHandler.EPrivacySetting playtime, ArchiHandler.EPrivacySetting friendsList, ArchiHandler.EPrivacySetting inventory, ArchiHandler.EPrivacySetting inventoryGifts) {
|
||||
if ((profile == ArchiHandler.EPrivacySetting.Unknown) || (ownedGames == ArchiHandler.EPrivacySetting.Unknown) || (playtime == ArchiHandler.EPrivacySetting.Unknown) || (friendsList == ArchiHandler.EPrivacySetting.Unknown) || (inventory == ArchiHandler.EPrivacySetting.Unknown) || (inventoryGifts == ArchiHandler.EPrivacySetting.Unknown)) {
|
||||
throw new ArgumentNullException(nameof(profile) + " || " + nameof(ownedGames) + " || " + nameof(playtime) + " || " + nameof(friendsList) + " || " + nameof(inventory) + " || " + nameof(inventoryGifts));
|
||||
if ((profile == ArchiHandler.EPrivacySetting.Unknown) || !Enum.IsDefined(typeof(ArchiHandler.EPrivacySetting), profile)) {
|
||||
throw new InvalidEnumArgumentException(nameof(profile), (int) profile, typeof(ArchiHandler.EPrivacySetting));
|
||||
}
|
||||
|
||||
if ((ownedGames == ArchiHandler.EPrivacySetting.Unknown) || !Enum.IsDefined(typeof(ArchiHandler.EPrivacySetting), ownedGames)) {
|
||||
throw new InvalidEnumArgumentException(nameof(ownedGames), (int) ownedGames, typeof(ArchiHandler.EPrivacySetting));
|
||||
}
|
||||
|
||||
if ((playtime == ArchiHandler.EPrivacySetting.Unknown) || !Enum.IsDefined(typeof(ArchiHandler.EPrivacySetting), playtime)) {
|
||||
throw new InvalidEnumArgumentException(nameof(playtime), (int) playtime, typeof(ArchiHandler.EPrivacySetting));
|
||||
}
|
||||
|
||||
if ((friendsList == ArchiHandler.EPrivacySetting.Unknown) || !Enum.IsDefined(typeof(ArchiHandler.EPrivacySetting), friendsList)) {
|
||||
throw new InvalidEnumArgumentException(nameof(friendsList), (int) friendsList, typeof(ArchiHandler.EPrivacySetting));
|
||||
}
|
||||
|
||||
if ((inventory == ArchiHandler.EPrivacySetting.Unknown) || !Enum.IsDefined(typeof(ArchiHandler.EPrivacySetting), inventory)) {
|
||||
throw new InvalidEnumArgumentException(nameof(inventory), (int) inventory, typeof(ArchiHandler.EPrivacySetting));
|
||||
}
|
||||
|
||||
if ((inventoryGifts == ArchiHandler.EPrivacySetting.Unknown) || !Enum.IsDefined(typeof(ArchiHandler.EPrivacySetting), inventoryGifts)) {
|
||||
throw new InvalidEnumArgumentException(nameof(inventoryGifts), (int) inventoryGifts, typeof(ArchiHandler.EPrivacySetting));
|
||||
}
|
||||
|
||||
Profile = profile;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -122,12 +123,16 @@ namespace ArchiSteamFarm.NLog {
|
|||
throw new ArgumentNullException(nameof(nullObjectName));
|
||||
}
|
||||
|
||||
LogGenericError(string.Format(Strings.ErrorObjectIsNull, nullObjectName), previousMethodName);
|
||||
LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.ErrorObjectIsNull, nullObjectName), previousMethodName);
|
||||
}
|
||||
|
||||
internal void LogChatMessage(bool echo, string message, ulong chatGroupID = 0, ulong chatID = 0, ulong steamID = 0, [CallerMemberName] string? previousMethodName = null) {
|
||||
if (string.IsNullOrEmpty(message) || (((chatGroupID == 0) || (chatID == 0)) && (steamID == 0))) {
|
||||
throw new ArgumentNullException(nameof(message) + " || " + "((" + nameof(chatGroupID) + " || " + nameof(chatID) + ") && " + nameof(steamID) + ")");
|
||||
if (string.IsNullOrEmpty(message)) {
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
|
||||
if (((chatGroupID == 0) || (chatID == 0)) && (steamID == 0)) {
|
||||
throw new InvalidOperationException("((" + nameof(chatGroupID) + " || " + nameof(chatID) + ") && " + nameof(steamID) + ")");
|
||||
}
|
||||
|
||||
StringBuilder loggedMessage = new StringBuilder(previousMethodName + "() " + message + " " + (echo ? "->" : "<-") + " ");
|
||||
|
@ -165,7 +170,7 @@ namespace ArchiSteamFarm.NLog {
|
|||
}
|
||||
|
||||
// Otherwise, we ran into fatal exception before logging module could even get initialized, so activate fallback logging that involves file and console
|
||||
string message = string.Format(DateTime.Now + " " + Strings.ErrorEarlyFatalExceptionInfo, SharedInfo.Version) + Environment.NewLine;
|
||||
string message = string.Format(CultureInfo.CurrentCulture, DateTime.Now + " " + Strings.ErrorEarlyFatalExceptionInfo, SharedInfo.Version) + Environment.NewLine;
|
||||
|
||||
try {
|
||||
await RuntimeCompatibility.File.WriteAllTextAsync(SharedInfo.LogFile, message).ConfigureAwait(false);
|
||||
|
@ -180,7 +185,7 @@ namespace ArchiSteamFarm.NLog {
|
|||
}
|
||||
|
||||
while (true) {
|
||||
message = string.Format(Strings.ErrorEarlyFatalExceptionPrint, previousMethodName, exception.Message, exception.StackTrace) + Environment.NewLine;
|
||||
message = string.Format(CultureInfo.CurrentCulture, Strings.ErrorEarlyFatalExceptionPrint, previousMethodName, exception.Message, exception.StackTrace) + Environment.NewLine;
|
||||
|
||||
try {
|
||||
await RuntimeCompatibility.File.AppendAllTextAsync(SharedInfo.LogFile, message).ConfigureAwait(false);
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -64,8 +66,12 @@ namespace ArchiSteamFarm.NLog {
|
|||
}
|
||||
|
||||
internal static async Task<string?> GetUserInput(ASF.EUserInputType userInputType, string botName = SharedInfo.ASF) {
|
||||
if ((userInputType == ASF.EUserInputType.None) || !Enum.IsDefined(typeof(ASF.EUserInputType), userInputType) || string.IsNullOrEmpty(botName)) {
|
||||
throw new ArgumentNullException(nameof(userInputType) + " || " + nameof(botName));
|
||||
if ((userInputType == ASF.EUserInputType.None) || !Enum.IsDefined(typeof(ASF.EUserInputType), userInputType)) {
|
||||
throw new InvalidEnumArgumentException(nameof(userInputType), (int) userInputType, typeof(ASF.EUserInputType));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(botName)) {
|
||||
throw new ArgumentNullException(nameof(botName));
|
||||
}
|
||||
|
||||
if (ASF.GlobalConfig?.Headless ?? GlobalConfig.DefaultHeadless) {
|
||||
|
@ -111,7 +117,7 @@ namespace ArchiSteamFarm.NLog {
|
|||
|
||||
break;
|
||||
default:
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(userInputType), userInputType));
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(userInputType), userInputType));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -212,7 +218,7 @@ namespace ArchiSteamFarm.NLog {
|
|||
|
||||
internal static void StartInteractiveConsole() {
|
||||
if ((ASF.GlobalConfig?.SteamOwnerID ?? GlobalConfig.DefaultSteamOwnerID) == 0) {
|
||||
ASF.ArchiLogger.LogGenericWarning(string.Format(Strings.InteractiveConsoleNotAvailable, nameof(ASF.GlobalConfig.SteamOwnerID)));
|
||||
ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.InteractiveConsoleNotAvailable, nameof(ASF.GlobalConfig.SteamOwnerID)));
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ArchiSteamFarm.Localization;
|
||||
|
@ -61,7 +62,7 @@ namespace ArchiSteamFarm.NLog {
|
|||
|
||||
base.Write(logEvent);
|
||||
|
||||
if ((SteamID == 0) || (Bot.Bots == null) || (Bot.Bots.Count == 0)) {
|
||||
if ((SteamID == 0) || (Bot.Bots == null) || (Bot.Bots.IsEmpty)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -85,7 +86,7 @@ namespace ArchiSteamFarm.NLog {
|
|||
|
||||
if (ChatGroupID != 0) {
|
||||
await SendGroupMessage(message, bot).ConfigureAwait(false);
|
||||
} else if ((bot == null) || (bot.SteamID != SteamID)) {
|
||||
} else if (bot?.SteamID != SteamID) {
|
||||
await SendPrivateMessage(message, bot).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +105,7 @@ namespace ArchiSteamFarm.NLog {
|
|||
}
|
||||
|
||||
if (!await bot.SendMessage(ChatGroupID, SteamID, message).ConfigureAwait(false)) {
|
||||
bot.ArchiLogger.LogGenericTrace(string.Format(Strings.WarningFailedWithError, nameof(Bot.SendMessage)));
|
||||
bot.ArchiLogger.LogGenericTrace(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(Bot.SendMessage)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +123,7 @@ namespace ArchiSteamFarm.NLog {
|
|||
}
|
||||
|
||||
if (!await bot.SendMessage(SteamID, message).ConfigureAwait(false)) {
|
||||
bot.ArchiLogger.LogGenericTrace(string.Format(Strings.WarningFailedWithError, nameof(Bot.SendMessage)));
|
||||
bot.ArchiLogger.LogGenericTrace(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(Bot.SendMessage)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ using System.Collections.Immutable;
|
|||
using System.Composition;
|
||||
using System.Composition.Convention;
|
||||
using System.Composition.Hosting;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
@ -98,7 +99,7 @@ namespace ArchiSteamFarm.Plugins {
|
|||
return true;
|
||||
}
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.Initializing, nameof(Plugins)));
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.Initializing, nameof(Plugins)));
|
||||
|
||||
ConventionBuilder conventions = new ConventionBuilder();
|
||||
conventions.ForTypesDerivedFrom<IPlugin>().Export<IPlugin>();
|
||||
|
@ -127,9 +128,9 @@ namespace ArchiSteamFarm.Plugins {
|
|||
try {
|
||||
string pluginName = plugin.Name;
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.PluginLoading, pluginName, plugin.Version));
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.PluginLoading, pluginName, plugin.Version));
|
||||
plugin.OnLoaded();
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(Strings.PluginLoaded, pluginName));
|
||||
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.PluginLoaded, pluginName));
|
||||
} catch (Exception e) {
|
||||
ASF.ArchiLogger.LogGenericException(e);
|
||||
invalidPlugins.Add(plugin);
|
||||
|
@ -164,7 +165,7 @@ namespace ArchiSteamFarm.Plugins {
|
|||
if (Directory.Exists(pluginsPath)) {
|
||||
HashSet<Assembly>? loadedAssemblies = LoadAssembliesFrom(pluginsPath);
|
||||
|
||||
if ((loadedAssemblies != null) && (loadedAssemblies.Count > 0)) {
|
||||
if (loadedAssemblies?.Count > 0) {
|
||||
assemblies = loadedAssemblies;
|
||||
}
|
||||
}
|
||||
|
@ -174,8 +175,8 @@ namespace ArchiSteamFarm.Plugins {
|
|||
if (Directory.Exists(customPluginsPath)) {
|
||||
HashSet<Assembly>? loadedAssemblies = LoadAssembliesFrom(customPluginsPath);
|
||||
|
||||
if ((loadedAssemblies != null) && (loadedAssemblies.Count > 0)) {
|
||||
if ((assemblies != null) && (assemblies.Count > 0)) {
|
||||
if (loadedAssemblies?.Count > 0) {
|
||||
if (assemblies?.Count > 0) {
|
||||
assemblies.UnionWith(loadedAssemblies);
|
||||
} else {
|
||||
assemblies = loadedAssemblies;
|
||||
|
@ -199,8 +200,20 @@ namespace ArchiSteamFarm.Plugins {
|
|||
}
|
||||
|
||||
internal static async Task<string?> OnBotCommand(Bot bot, ulong steamID, string message, string[] args) {
|
||||
if ((bot == null) || (steamID == 0) || !new SteamID(steamID).IsIndividualAccount || string.IsNullOrEmpty(message) || (args == null) || (args.Length == 0)) {
|
||||
throw new ArgumentNullException(nameof(bot) + " || " + nameof(steamID) + " || " + nameof(message) + " || " + nameof(args));
|
||||
if (bot == null) {
|
||||
throw new ArgumentNullException(nameof(bot));
|
||||
}
|
||||
|
||||
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
|
||||
throw new ArgumentOutOfRangeException(nameof(steamID));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(message)) {
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
|
||||
if ((args == null) || (args.Length == 0)) {
|
||||
throw new ArgumentNullException(nameof(args));
|
||||
}
|
||||
|
||||
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
|
||||
|
@ -301,8 +314,12 @@ namespace ArchiSteamFarm.Plugins {
|
|||
}
|
||||
|
||||
internal static async Task<bool> OnBotFriendRequest(Bot bot, ulong steamID) {
|
||||
if ((bot == null) || (steamID == 0) || !new SteamID(steamID).IsValid) {
|
||||
throw new ArgumentNullException(nameof(bot) + " || " + nameof(steamID));
|
||||
if (bot == null) {
|
||||
throw new ArgumentNullException(nameof(bot));
|
||||
}
|
||||
|
||||
if ((steamID == 0) || !new SteamID(steamID).IsValid) {
|
||||
throw new ArgumentOutOfRangeException(nameof(steamID));
|
||||
}
|
||||
|
||||
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
|
||||
|
@ -371,8 +388,16 @@ namespace ArchiSteamFarm.Plugins {
|
|||
}
|
||||
|
||||
internal static async Task<string?> OnBotMessage(Bot bot, ulong steamID, string message) {
|
||||
if ((bot == null) || (steamID == 0) || !new SteamID(steamID).IsIndividualAccount || string.IsNullOrEmpty(message)) {
|
||||
throw new ArgumentNullException(nameof(bot) + " || " + nameof(steamID) + " || " + nameof(message));
|
||||
if (bot == null) {
|
||||
throw new ArgumentNullException(nameof(bot));
|
||||
}
|
||||
|
||||
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
|
||||
throw new ArgumentOutOfRangeException(nameof(steamID));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(message)) {
|
||||
throw new ArgumentNullException(nameof(message));
|
||||
}
|
||||
|
||||
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
|
||||
|
@ -393,8 +418,12 @@ namespace ArchiSteamFarm.Plugins {
|
|||
}
|
||||
|
||||
internal static async Task OnBotSteamCallbacksInit(Bot bot, CallbackManager callbackManager) {
|
||||
if ((bot == null) || (callbackManager == null)) {
|
||||
throw new ArgumentNullException(nameof(bot) + " || " + nameof(callbackManager));
|
||||
if (bot == null) {
|
||||
throw new ArgumentNullException(nameof(bot));
|
||||
}
|
||||
|
||||
if (callbackManager == null) {
|
||||
throw new ArgumentNullException(nameof(callbackManager));
|
||||
}
|
||||
|
||||
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
|
||||
|
@ -431,8 +460,12 @@ namespace ArchiSteamFarm.Plugins {
|
|||
}
|
||||
|
||||
internal static async Task<bool> OnBotTradeOffer(Bot bot, Steam.TradeOffer tradeOffer) {
|
||||
if ((bot == null) || (tradeOffer == null)) {
|
||||
throw new ArgumentNullException(nameof(bot) + " || " + nameof(tradeOffer));
|
||||
if ((bot == null)) {
|
||||
throw new ArgumentNullException(nameof(bot));
|
||||
}
|
||||
|
||||
if (tradeOffer == null) {
|
||||
throw new ArgumentNullException(nameof(tradeOffer));
|
||||
}
|
||||
|
||||
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
|
||||
|
@ -453,8 +486,12 @@ namespace ArchiSteamFarm.Plugins {
|
|||
}
|
||||
|
||||
internal static async Task OnBotTradeOfferResults(Bot bot, IReadOnlyCollection<Trading.ParseTradeResult> tradeResults) {
|
||||
if ((bot == null) || (tradeResults == null) || (tradeResults.Count == 0)) {
|
||||
throw new ArgumentNullException(nameof(bot) + " || " + nameof(tradeResults));
|
||||
if (bot == null) {
|
||||
throw new ArgumentNullException(nameof(bot));
|
||||
}
|
||||
|
||||
if ((tradeResults == null) || (tradeResults.Count == 0)) {
|
||||
throw new ArgumentNullException(nameof(tradeResults));
|
||||
}
|
||||
|
||||
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
|
||||
|
@ -469,8 +506,12 @@ namespace ArchiSteamFarm.Plugins {
|
|||
}
|
||||
|
||||
internal static async Task OnBotUserNotifications(Bot bot, IReadOnlyCollection<ArchiHandler.UserNotificationsCallback.EUserNotification> newNotifications) {
|
||||
if ((bot == null) || (newNotifications == null) || (newNotifications.Count == 0)) {
|
||||
throw new ArgumentNullException(nameof(bot) + " || " + nameof(newNotifications));
|
||||
if ((bot == null)) {
|
||||
throw new ArgumentNullException(nameof(bot));
|
||||
}
|
||||
|
||||
if ((newNotifications == null) || (newNotifications.Count == 0)) {
|
||||
throw new ArgumentNullException(nameof(newNotifications));
|
||||
}
|
||||
|
||||
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
|
||||
|
@ -485,8 +526,16 @@ namespace ArchiSteamFarm.Plugins {
|
|||
}
|
||||
|
||||
internal static async Task OnPICSChanges(uint currentChangeNumber, IReadOnlyDictionary<uint, SteamApps.PICSChangesCallback.PICSChangeData> appChanges, IReadOnlyDictionary<uint, SteamApps.PICSChangesCallback.PICSChangeData> packageChanges) {
|
||||
if ((currentChangeNumber == 0) || (appChanges == null) || (packageChanges == null)) {
|
||||
throw new ArgumentNullException(nameof(currentChangeNumber) + " || " + nameof(appChanges) + " || " + nameof(packageChanges));
|
||||
if (currentChangeNumber == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(currentChangeNumber));
|
||||
}
|
||||
|
||||
if (appChanges == null) {
|
||||
throw new ArgumentNullException(nameof(appChanges));
|
||||
}
|
||||
|
||||
if (packageChanges == null) {
|
||||
throw new ArgumentNullException(nameof(packageChanges));
|
||||
}
|
||||
|
||||
if ((ActivePlugins == null) || (ActivePlugins.Count == 0)) {
|
||||
|
@ -534,7 +583,7 @@ namespace ArchiSteamFarm.Plugins {
|
|||
try {
|
||||
assembly = Assembly.LoadFrom(assemblyPath);
|
||||
} catch (Exception e) {
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, assemblyPath));
|
||||
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, assemblyPath));
|
||||
ASF.ArchiLogger.LogGenericWarningException(e);
|
||||
|
||||
continue;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using SteamKit2;
|
||||
|
||||
|
@ -35,8 +36,16 @@ namespace ArchiSteamFarm.SteamKit2 {
|
|||
internal readonly ProtocolTypes ProtocolTypes;
|
||||
|
||||
internal ServerRecordEndPoint(string host, ushort port, ProtocolTypes protocolTypes) {
|
||||
if (string.IsNullOrEmpty(host) || (port == 0) || (protocolTypes == 0)) {
|
||||
throw new ArgumentNullException(nameof(host) + " || " + nameof(port) + " || " + nameof(protocolTypes));
|
||||
if (string.IsNullOrEmpty(host)) {
|
||||
throw new ArgumentNullException(nameof(host));
|
||||
}
|
||||
|
||||
if (port == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(port));
|
||||
}
|
||||
|
||||
if (protocolTypes == 0) {
|
||||
throw new InvalidEnumArgumentException(nameof(protocolTypes), (int) protocolTypes, typeof(ProtocolTypes));
|
||||
}
|
||||
|
||||
Host = host;
|
||||
|
|
Loading…
Reference in a new issue