Code cleanup

This commit is contained in:
JustArchi 2020-11-29 16:15:20 +01:00
parent e522602535
commit 14f58d5aec
4 changed files with 75 additions and 75 deletions

View file

@ -39,10 +39,6 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin {
// This will keep your code compact, efficient and less dependent. You can always add additional interfaces when you'll need them, this example project will inherit quite a bit of them to show you potential usage
// ReSharper disable once UnusedType.Global - this is example plugin class that isn't used in our main code
internal sealed class ExamplePlugin : IASF, IBot, IBotCommand, IBotConnection, IBotFriendRequest, IBotMessage, IBotModules, IBotTradeOffer {
// Plugins can expose custom properties for our GET /Api/Plugins API call, simply annotate them with [JsonProperty] (or keep public)
[JsonProperty]
public bool CustomIsEnabledField { get; private set; } = true;
// This is used for identification purposes, typically you want to use a friendly name of your plugin here, such as the name of your main class
// Please note that this property can have direct dependencies only on structures that were initialized by the constructor, as it's possible to be called before OnLoaded() takes place
public string Name => nameof(ExamplePlugin);
@ -51,6 +47,10 @@ namespace ArchiSteamFarm.CustomPlugins.ExamplePlugin {
// Please note that this property can have direct dependencies only on structures that were initialized by the constructor, as it's possible to be called before OnLoaded() takes place
public Version Version => typeof(ExamplePlugin).Assembly.GetName().Version ?? throw new InvalidOperationException(nameof(Version));
// Plugins can expose custom properties for our GET /Api/Plugins API call, simply annotate them with [JsonProperty] (or keep public)
[JsonProperty]
public bool CustomIsEnabledField { get; private set; } = true;
// This method, apart from being called before any bot initialization takes place, allows you to read custom global config properties that are not recognized by ASF
// Thanks to that, you can extend default ASF config with your own stuff, then parse it here in order to customize your plugin during runtime
// Keep in mind that, as noted in the interface, additionalConfigProperties can be null if no custom, unrecognized properties are found by ASF, you should handle that case appropriately

View file

@ -200,6 +200,9 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)]
public bool ShutdownOnFarmingFinished { get; private set; } = DefaultShutdownOnFarmingFinished;
[JsonProperty(Required = Required.DisallowNull)]
public ulong SteamMasterClanID { get; private set; } = DefaultSteamMasterClanID;
[JsonProperty]
public string? SteamTradeToken { get; private set; } = DefaultSteamTradeToken;
@ -215,9 +218,6 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)]
public bool UseLoginKeys { get; private set; } = DefaultUseLoginKeys;
[JsonProperty(Required = Required.DisallowNull)]
public ulong SteamMasterClanID { get; private set; } = DefaultSteamMasterClanID;
[JsonExtensionData]
internal Dictionary<string, JToken>? AdditionalProperties {
get;

View file

@ -126,6 +126,56 @@ namespace ArchiSteamFarm {
private static readonly SemaphoreSlim WriteSemaphore = new(1, 1);
[JsonIgnore]
[PublicAPI]
public WebProxy? WebProxy {
get {
if (BackingWebProxy != null) {
return BackingWebProxy;
}
if (string.IsNullOrEmpty(WebProxyText)) {
return null;
}
Uri uri;
try {
uri = new Uri(WebProxyText!);
} catch (UriFormatException e) {
ASF.ArchiLogger.LogGenericException(e);
return null;
}
WebProxy proxy = new() {
Address = uri,
BypassProxyOnLocal = true
};
if (!string.IsNullOrEmpty(WebProxyUsername) || !string.IsNullOrEmpty(WebProxyPassword)) {
NetworkCredential credentials = new();
if (!string.IsNullOrEmpty(WebProxyUsername)) {
credentials.UserName = WebProxyUsername;
}
if (!string.IsNullOrEmpty(WebProxyPassword)) {
credentials.Password = WebProxyPassword;
}
proxy.Credentials = credentials;
}
BackingWebProxy = proxy;
return proxy;
}
}
[JsonProperty]
internal readonly string? IPCPassword = DefaultIPCPassword;
[JsonProperty(Required = Required.DisallowNull)]
public bool AutoRestart { get; private set; } = DefaultAutoRestart;
@ -186,6 +236,12 @@ namespace ArchiSteamFarm {
[JsonProperty]
public string? SteamMessagePrefix { get; private set; } = DefaultSteamMessagePrefix;
[JsonProperty(Required = Required.DisallowNull)]
public ulong SteamOwnerID { get; private set; } = DefaultSteamOwnerID;
[JsonProperty(Required = Required.DisallowNull)]
public ProtocolTypes SteamProtocols { get; private set; } = DefaultSteamProtocols;
[JsonProperty(Required = Required.DisallowNull)]
public EUpdateChannel UpdateChannel { get; private set; } = DefaultUpdateChannel;
@ -195,68 +251,12 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)]
public ushort WebLimiterDelay { get; private set; } = DefaultWebLimiterDelay;
[JsonIgnore]
[PublicAPI]
public WebProxy? WebProxy {
get {
if (BackingWebProxy != null) {
return BackingWebProxy;
}
if (string.IsNullOrEmpty(WebProxyText)) {
return null;
}
Uri uri;
try {
uri = new Uri(WebProxyText!);
} catch (UriFormatException e) {
ASF.ArchiLogger.LogGenericException(e);
return null;
}
WebProxy proxy = new() {
Address = uri,
BypassProxyOnLocal = true
};
if (!string.IsNullOrEmpty(WebProxyUsername) || !string.IsNullOrEmpty(WebProxyPassword)) {
NetworkCredential credentials = new();
if (!string.IsNullOrEmpty(WebProxyUsername)) {
credentials.UserName = WebProxyUsername;
}
if (!string.IsNullOrEmpty(WebProxyPassword)) {
credentials.Password = WebProxyPassword;
}
proxy.Credentials = credentials;
}
BackingWebProxy = proxy;
return proxy;
}
}
[JsonProperty(PropertyName = nameof(WebProxy))]
public string? WebProxyText { get; private set; } = DefaultWebProxyText;
[JsonProperty]
public string? WebProxyUsername { get; private set; } = DefaultWebProxyUsername;
[JsonProperty]
internal readonly string? IPCPassword = DefaultIPCPassword;
[JsonProperty(Required = Required.DisallowNull)]
public ulong SteamOwnerID { get; private set; } = DefaultSteamOwnerID;
[JsonProperty(Required = Required.DisallowNull)]
public ProtocolTypes SteamProtocols { get; private set; } = DefaultSteamProtocols;
[JsonExtensionData]
internal Dictionary<string, JToken>? AdditionalProperties {
get;

View file

@ -36,24 +36,18 @@ namespace ArchiSteamFarm.IPC.Requests {
[JsonProperty(Required = Required.Always)]
public bool Accept { get; private set; }
/// <summary>
/// Specifies the type of confirmations to handle. If not provided, all confirmation types are considered for an action.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public MobileAuthenticator.Confirmation.EType? AcceptedType { get; private set; }
/// <summary>
/// Specifies whether we should wait for the confirmations to arrive, in case they're not available immediately. This option makes sense only if <see cref="AcceptedCreatorIDs" /> is specified as well, and in this case ASF will add a few more tries if needed to ensure that all specified IDs are handled. Useful if confirmations are generated with a delay on Steam network side, which happens fairly often.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public bool WaitIfNeeded { get; private set; }
/// <summary>
/// Specifies IDs of the confirmations that we're supposed to handle. CreatorID of the confirmation is equal to ID of the object that triggered it - e.g. ID of the trade offer, or ID of the market listing. If not provided, or empty array, all confirmation IDs are considered for an action.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public ImmutableHashSet<ulong>? AcceptedCreatorIDs { get; private set; }
/// <summary>
/// Specifies the type of confirmations to handle. If not provided, all confirmation types are considered for an action.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public MobileAuthenticator.Confirmation.EType? AcceptedType { get; private set; }
/// <summary>
/// A helper property which works the same as <see cref="AcceptedCreatorIDs" /> but with values written as strings - for javascript compatibility purposes. Use either this one, or <see cref="AcceptedCreatorIDs" />, not both.
/// </summary>
@ -80,6 +74,12 @@ namespace ArchiSteamFarm.IPC.Requests {
}
}
/// <summary>
/// Specifies whether we should wait for the confirmations to arrive, in case they're not available immediately. This option makes sense only if <see cref="AcceptedCreatorIDs" /> is specified as well, and in this case ASF will add a few more tries if needed to ensure that all specified IDs are handled. Useful if confirmations are generated with a delay on Steam network side, which happens fairly often.
/// </summary>
[JsonProperty(Required = Required.DisallowNull)]
public bool WaitIfNeeded { get; private set; }
[JsonConstructor]
private TwoFactorAuthenticationConfirmationsRequest() { }
}