mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Code review
This commit is contained in:
parent
91e97a2452
commit
152ba0bdf2
10 changed files with 34 additions and 129 deletions
|
@ -1,5 +1,6 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeEditing/TypingAssist/SmartIndentOnEnter/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=Strings_002E_003F_003F_002D_003F_003F_002Eresx/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=CF84911C_002D2C4C_002D4195_002D8AF3_002DABBB6D3DE9AA_002Fd_003Awww/@EntryIndexedValue">ExplicitlyExcluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=CF84911C_002D2C4C_002D4195_002D8AF3_002DABBB6D3DE9AA_002Fd_003Awww/@EntryIndexedValue">CF84911C-2C4C-4195-8AF3-ABBB6D3DE9AA/d:www</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/IncludeWarningsInSwea/@EntryValue">True</s:Boolean>
|
||||
|
@ -41,6 +42,7 @@
|
|||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToConstant_002ELocal/@EntryIndexedValue">SUGGESTION</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToExpressionBodyWhenPossible/@EntryIndexedValue">SUGGESTION</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToLambdaExpressionWhenPossible/@EntryIndexedValue">SUGGESTION</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=DuplicateResource/@EntryIndexedValue">HINT</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceDoWhileStatementBraces/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceFixedStatementBraces/@EntryIndexedValue">WARNING</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnforceForeachStatementBraces/@EntryIndexedValue">WARNING</s:String>
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using ArchiSteamFarm.Localization;
|
||||
|
|
|
@ -755,11 +755,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (resultInSeconds == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (byte) (resultInSeconds / 86400);
|
||||
return resultInSeconds == 0 ? (byte?) 0 : (byte) (resultInSeconds / 86400);
|
||||
}
|
||||
|
||||
internal async Task<string> GetTradeToken() {
|
||||
|
@ -1042,11 +1038,7 @@ namespace ArchiSteamFarm {
|
|||
Dictionary<string, string> data = new Dictionary<string, string>(2) { { "wallet_code", key } };
|
||||
|
||||
Steam.RedeemWalletResponse response = await UrlPostToJsonObjectWithSession<Steam.RedeemWalletResponse>(SteamStoreURL, request, data).ConfigureAwait(false);
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (response.Result, response.PurchaseResultDetail);
|
||||
return response == null ? ((EResult Result, EPurchaseResultDetail? PurchaseResult)?) null : (response.Result, response.PurchaseResultDetail);
|
||||
}
|
||||
|
||||
internal async Task<bool> SendTradeOffer(ulong partnerID, IReadOnlyCollection<Steam.Asset> itemsToGive, string token = null) {
|
||||
|
@ -1274,11 +1266,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
|
||||
int index = hashName.IndexOf('-');
|
||||
if (index <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return uint.TryParse(hashName.Substring(0, index), out uint appID) ? appID : 0;
|
||||
return (index > 0) && uint.TryParse(hashName.Substring(0, index), out uint appID) && (appID != 0) ? appID : 0;
|
||||
}
|
||||
|
||||
private static Steam.Asset.EType GetItemType(string name) {
|
||||
|
|
|
@ -492,11 +492,7 @@ namespace ArchiSteamFarm {
|
|||
return (appID, DateTime.MinValue);
|
||||
}
|
||||
|
||||
if (!productInfoResultSet.Complete || productInfoResultSet.Failed) {
|
||||
return (optimisticDiscovery ? appID : 0, DateTime.MinValue);
|
||||
}
|
||||
|
||||
return (appID, DateTime.MinValue);
|
||||
return ((productInfoResultSet.Complete && !productInfoResultSet.Failed) || optimisticDiscovery ? appID : 0, DateTime.MinValue);
|
||||
}
|
||||
|
||||
internal static HashSet<Bot> GetBots(string args) {
|
||||
|
@ -737,11 +733,7 @@ namespace ArchiSteamFarm {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (IsOwner(steamID)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetSteamUserPermission(steamID) >= BotConfig.EPermission.Master;
|
||||
return IsOwner(steamID) || (GetSteamUserPermission(steamID) >= BotConfig.EPermission.Master);
|
||||
}
|
||||
|
||||
internal bool IsPriorityIdling(uint appID) {
|
||||
|
@ -1557,11 +1549,7 @@ namespace ArchiSteamFarm {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (IsOwner(steamID)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return SteamFamilySharingIDs.Contains(steamID) || (GetSteamUserPermission(steamID) >= BotConfig.EPermission.FamilySharing);
|
||||
return IsOwner(steamID) || SteamFamilySharingIDs.Contains(steamID) || (GetSteamUserPermission(steamID) >= BotConfig.EPermission.FamilySharing);
|
||||
}
|
||||
|
||||
private bool IsMasterClanID(ulong steamID) {
|
||||
|
@ -1579,11 +1567,7 @@ namespace ArchiSteamFarm {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (IsOwner(steamID)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return GetSteamUserPermission(steamID) >= BotConfig.EPermission.Operator;
|
||||
return IsOwner(steamID) || (GetSteamUserPermission(steamID) >= BotConfig.EPermission.Operator);
|
||||
}
|
||||
|
||||
private static bool IsOwner(ulong steamID) {
|
||||
|
@ -3798,13 +3782,7 @@ namespace ArchiSteamFarm {
|
|||
|
||||
await LimitGiftsRequestsAsync().ConfigureAwait(false);
|
||||
|
||||
Dictionary<uint, string> ownedGames;
|
||||
if (await ArchiWebHandler.HasValidApiKey().ConfigureAwait(false)) {
|
||||
ownedGames = await ArchiWebHandler.GetOwnedGames(CachedSteamID).ConfigureAwait(false);
|
||||
} else {
|
||||
ownedGames = await ArchiWebHandler.GetMyOwnedGames().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Dictionary<uint, string> ownedGames = await ArchiWebHandler.HasValidApiKey().ConfigureAwait(false) ? await ArchiWebHandler.GetOwnedGames(CachedSteamID).ConfigureAwait(false) : await ArchiWebHandler.GetMyOwnedGames().ConfigureAwait(false);
|
||||
if ((ownedGames == null) || (ownedGames.Count == 0)) {
|
||||
return (FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(ownedGames))), null);
|
||||
}
|
||||
|
@ -3884,11 +3862,7 @@ namespace ArchiSteamFarm {
|
|||
|
||||
Dictionary<uint, ushort> ownedGameCounts = new Dictionary<uint, ushort>();
|
||||
foreach (uint gameID in validResults.Where(validResult => (validResult.OwnedGameIDs != null) && (validResult.OwnedGameIDs.Count > 0)).SelectMany(validResult => validResult.OwnedGameIDs)) {
|
||||
if (ownedGameCounts.TryGetValue(gameID, out ushort count)) {
|
||||
ownedGameCounts[gameID] = ++count;
|
||||
} else {
|
||||
ownedGameCounts[gameID] = 1;
|
||||
}
|
||||
ownedGameCounts[gameID] = ownedGameCounts.TryGetValue(gameID, out ushort count) ? ++count : (ushort) 1;
|
||||
}
|
||||
|
||||
IEnumerable<string> extraResponses = ownedGameCounts.Select(kv => FormatStaticResponse(string.Format(Strings.BotOwnsOverviewPerGame, kv.Value, validResults.Count, kv.Key)));
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
@ -1042,31 +1043,10 @@ namespace ArchiSteamFarm {
|
|||
PlayableAppID = appID;
|
||||
}
|
||||
|
||||
public bool Equals(Game other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ReSharper disable once PossibleUnintendedReferenceComparison - we indeed want to compare those two by reference
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return AppID == other.AppID;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return obj is Game game && Equals(game);
|
||||
}
|
||||
[SuppressMessage("ReSharper", "PossibleUnintendedReferenceComparison")]
|
||||
public bool Equals(Game other) => (other != null) && ((other == this) || (AppID == other.AppID));
|
||||
|
||||
public override bool Equals(object obj) => (obj != null) && ((obj == this) || (obj is Game game && Equals(game)));
|
||||
public override int GetHashCode() => (int) (AppID - 1 - int.MaxValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -953,11 +953,7 @@ namespace ArchiSteamFarm {
|
|||
if (authorized) {
|
||||
FailedAuthorizations.TryRemove(ipAddress, out _);
|
||||
} else {
|
||||
if (FailedAuthorizations.TryGetValue(ipAddress, out attempts)) {
|
||||
FailedAuthorizations[ipAddress] = ++attempts;
|
||||
} else {
|
||||
FailedAuthorizations[ipAddress] = 1;
|
||||
}
|
||||
FailedAuthorizations[ipAddress] = FailedAuthorizations.TryGetValue(ipAddress, out attempts) ? ++attempts : (byte) 1;
|
||||
}
|
||||
} finally {
|
||||
AuthorizationSemaphore.Release();
|
||||
|
|
|
@ -523,11 +523,7 @@ namespace ArchiSteamFarm.Json {
|
|||
itemsPerType = new Dictionary<Asset.EType, uint> { [item.Type] = item.Amount };
|
||||
itemsToGivePerGame[item.RealAppID] = itemsPerType;
|
||||
} else {
|
||||
if (itemsPerType.TryGetValue(item.Type, out uint amount)) {
|
||||
itemsPerType[item.Type] = amount + item.Amount;
|
||||
} else {
|
||||
itemsPerType[item.Type] = item.Amount;
|
||||
}
|
||||
itemsPerType[item.Type] = itemsPerType.TryGetValue(item.Type, out uint amount) ? amount + item.Amount : item.Amount;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -538,11 +534,7 @@ namespace ArchiSteamFarm.Json {
|
|||
|
||||
itemsToReceivePerGame[item.RealAppID] = itemsPerType;
|
||||
} else {
|
||||
if (itemsPerType.TryGetValue(item.Type, out uint amount)) {
|
||||
itemsPerType[item.Type] = amount + item.Amount;
|
||||
} else {
|
||||
itemsPerType[item.Type] = item.Amount;
|
||||
}
|
||||
itemsPerType[item.Type] = itemsPerType.TryGetValue(item.Type, out uint amount) ? amount + item.Amount : item.Amount;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,49 +33,41 @@ namespace ArchiSteamFarm {
|
|||
|
||||
#if NET472
|
||||
internal static async Task<WebSocketReceiveResult> ReceiveAsync(this WebSocket webSocket, byte[] buffer, CancellationToken cancellationToken) => await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
internal static async Task SendAsync(this WebSocket webSocket, byte[] buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) {
|
||||
await webSocket.SendAsync(new ArraySegment<byte>(buffer), messageType, endOfMessage, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static async Task SendAsync(this WebSocket webSocket, byte[] buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken) => await webSocket.SendAsync(new ArraySegment<byte>(buffer), messageType, endOfMessage, cancellationToken).ConfigureAwait(false);
|
||||
internal static string[] Split(this string text, char separator, StringSplitOptions options = StringSplitOptions.None) => text.Split(new[] { separator }, options);
|
||||
#endif
|
||||
|
||||
internal static class File {
|
||||
#pragma warning disable 1998
|
||||
internal static async Task AppendAllTextAsync(string path, string contents) {
|
||||
internal static class File {
|
||||
internal static async Task AppendAllTextAsync(string path, string contents) =>
|
||||
#if NET472
|
||||
System.IO.File.AppendAllText(path, contents);
|
||||
#else
|
||||
await System.IO.File.AppendAllTextAsync(path, contents).ConfigureAwait(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static async Task<byte[]> ReadAllBytesAsync(string path) {
|
||||
internal static async Task<byte[]> ReadAllBytesAsync(string path) =>
|
||||
#if NET472
|
||||
return System.IO.File.ReadAllBytes(path);
|
||||
System.IO.File.ReadAllBytes(path);
|
||||
#else
|
||||
return await System.IO.File.ReadAllBytesAsync(path).ConfigureAwait(false);
|
||||
await System.IO.File.ReadAllBytesAsync(path).ConfigureAwait(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static async Task<string> ReadAllTextAsync(string path) {
|
||||
internal static async Task<string> ReadAllTextAsync(string path) =>
|
||||
#if NET472
|
||||
return System.IO.File.ReadAllText(path);
|
||||
System.IO.File.ReadAllText(path);
|
||||
#else
|
||||
return await System.IO.File.ReadAllTextAsync(path).ConfigureAwait(false);
|
||||
await System.IO.File.ReadAllTextAsync(path).ConfigureAwait(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static async Task WriteAllTextAsync(string path, string contents) {
|
||||
internal static async Task WriteAllTextAsync(string path, string contents) =>
|
||||
#if NET472
|
||||
System.IO.File.WriteAllText(path, contents);
|
||||
#else
|
||||
await System.IO.File.WriteAllTextAsync(path, contents).ConfigureAwait(false);
|
||||
#endif
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
}
|
||||
#pragma warning restore 1998
|
||||
|
||||
internal static class Path {
|
||||
internal static string GetRelativePath(string relativeTo, string path) {
|
||||
|
@ -86,14 +78,11 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
|
||||
string result = path.Substring(relativeTo.Length);
|
||||
|
||||
if ((result[0] == System.IO.Path.DirectorySeparatorChar) || (result[0] == System.IO.Path.AltDirectorySeparatorChar)) {
|
||||
return result.Substring(1);
|
||||
}
|
||||
|
||||
return result;
|
||||
return (result[0] == System.IO.Path.DirectorySeparatorChar) || (result[0] == System.IO.Path.AltDirectorySeparatorChar) ? result.Substring(1) : result;
|
||||
#else
|
||||
#pragma warning disable IDE0022
|
||||
return System.IO.Path.GetRelativePath(relativeTo, path);
|
||||
#pragma warning restore IDE0022
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,18 +46,7 @@ namespace ArchiSteamFarm {
|
|||
|
||||
private ServerRecordEndPoint() { }
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return obj is ServerRecordEndPoint serverRecord && Equals(serverRecord);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) => (obj != null) && ((obj == this) || (obj is ServerRecordEndPoint serverRecord && Equals(serverRecord)));
|
||||
public override int GetHashCode() => (Host, Port, ProtocolTypes).GetHashCode();
|
||||
|
||||
private bool Equals(ServerRecordEndPoint other) => string.Equals(Host, other.Host) && (Port == other.Port) && (ProtocolTypes == other.ProtocolTypes);
|
||||
|
|
|
@ -78,11 +78,7 @@ namespace ArchiSteamFarm {
|
|||
// This has to be done as we might have multiple items of given ClassID with multiple amounts
|
||||
Dictionary<ulong, uint> itemAmounts = new Dictionary<ulong, uint>();
|
||||
foreach (Steam.Asset item in inventory) {
|
||||
if (itemAmounts.TryGetValue(item.ClassID, out uint amount)) {
|
||||
itemAmounts[item.ClassID] = amount + item.Amount;
|
||||
} else {
|
||||
itemAmounts[item.ClassID] = item.Amount;
|
||||
}
|
||||
itemAmounts[item.ClassID] = itemAmounts.TryGetValue(item.ClassID, out uint amount) ? amount + item.Amount : item.Amount;
|
||||
}
|
||||
|
||||
// Calculate our value of items to give on per-game basis
|
||||
|
|
Loading…
Reference in a new issue