Cleanup after #794

@vital7

Steam.cs:
- Add missing constructor for json deserialization
- Change name into UserPrivacy since we use it for both request and response, no longer response only
- Move ECommentPermission one level above, it's not internal member of PrivacySettings
- Make UserPrivacy constructor accept PrivacySettings, since PrivacySettings is internal and not private.
- Make ECommentPermission underlying type of byte

ArchiWebHandler.cs:
- Put function in proper place alphabetically
- Cast CommentPermission to new underlying type of byte
- Remove mapping, AWH should not be in charge of correcting a caller, unless that caller can't be corrected earlier (e.g. direct Steam response). Since Bot is in charge of calling AWH, Bot should do the correction, not AWH.

Bot.cs:
- Change command to !privacy bot n,n,n,n,n,n, this makes it possible for mixing it with enum members (such as !privacy bot public,private,friendsonly,public,public), which would be preferred way of execution instead of cryptic numbers.
- Make appropriate mapping between general and comments, since userspace is in charge of that.
- Add comments and correct creating UserPrivacy object.
- Make the default option private and let user skip extra options if he wants to edit e.g. only profile to public.

Apart from that, general error handling and a lot of other misc fixed, including renaming NonZeroResponse to NumberResponse, which makes more sense.
This commit is contained in:
JustArchi
2018-05-19 20:50:26 +02:00
parent 9b7dfd065d
commit ed2a068c51
3 changed files with 145 additions and 140 deletions

View File

@@ -119,6 +119,28 @@ namespace ArchiSteamFarm {
return htmlDocument?.DocumentNode.SelectSingleNode("//div[@class='add_free_content_success_area']") != null;
}
internal async Task<bool> ChangePrivacySettings(Steam.UserPrivacy userPrivacy) {
string request = GetAbsoluteProfileURL() + "/ajaxsetprivacy";
// Extra entry for sessionID
Dictionary<string, string> data = new Dictionary<string, string>(3) {
{ "eCommentPermission", ((byte) userPrivacy.CommentPermission).ToString() },
{ "Privacy", JsonConvert.SerializeObject(userPrivacy.Settings) }
};
Steam.NumberResponse response = await UrlPostToJsonObjectWithSession<Steam.NumberResponse>(SteamCommunityURL, request, data).ConfigureAwait(false);
if (response == null) {
return false;
}
if (!response.Success) {
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
return false;
}
return true;
}
internal async Task<bool> ClearFromDiscoveryQueue(uint appID) {
if (appID == 0) {
Bot.ArchiLogger.LogNullError(nameof(appID));
@@ -133,44 +155,6 @@ namespace ArchiSteamFarm {
return await UrlPostWithSession(SteamStoreURL, request, data).ConfigureAwait(false);
}
internal async Task<bool> ChangePrivacySettings(Steam.PrivacyResponse privacySettings) {
string request = GetAbsoluteProfileURL() + "/ajaxsetprivacy";
// We have to do this because Steam uses the same numbers for settings except comments, this has its special numbers, fuck Steam
Steam.PrivacyResponse.ECommentPermission commentPermission;
switch (privacySettings.Comments) {
case Steam.PrivacyResponse.PrivacySettings.EPrivacySetting.Public:
commentPermission = Steam.PrivacyResponse.ECommentPermission.Public;
break;
case Steam.PrivacyResponse.PrivacySettings.EPrivacySetting.FriendsOnly:
commentPermission = Steam.PrivacyResponse.ECommentPermission.FriendsOnly;
break;
case Steam.PrivacyResponse.PrivacySettings.EPrivacySetting.Private:
commentPermission = Steam.PrivacyResponse.ECommentPermission.Private;
break;
default:
Bot.ArchiLogger.LogGenericWarning(string.Format(Strings.ErrorIsInvalid, nameof(commentPermission)));
return false;
}
Dictionary<string, string> data = new Dictionary<string, string>(3) {
{ "Privacy", JsonConvert.SerializeObject(privacySettings.Settings) },
{ "eCommentPermission", ((int) commentPermission).ToString() }
};
Steam.NonZeroResponse response = await UrlPostToJsonObjectWithSession<Steam.NonZeroResponse>(SteamCommunityURL, request, data).ConfigureAwait(false);
if (response == null) {
return false;
}
if (!response.Success) {
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
return false;
}
return true;
}
internal async Task<bool> DeclineTradeOffer(ulong tradeID) {
if (tradeID == 0) {
Bot.ArchiLogger.LogNullError(nameof(tradeID));
@@ -1318,28 +1302,28 @@ namespace ArchiSteamFarm {
// This json is encoded as html attribute, don't forget to decode it
json = WebUtility.HtmlDecode(json);
Steam.PrivacyResponse privacyResponse;
Steam.UserPrivacy userPrivacy;
try {
privacyResponse = JsonConvert.DeserializeObject<Steam.PrivacyResponse>(json);
userPrivacy = JsonConvert.DeserializeObject<Steam.UserPrivacy>(json);
} catch (JsonException e) {
Bot.ArchiLogger.LogGenericException(e);
return null;
}
if (privacyResponse == null) {
Bot.ArchiLogger.LogNullError(nameof(privacyResponse));
if (userPrivacy == null) {
Bot.ArchiLogger.LogNullError(nameof(userPrivacy));
return null;
}
switch (privacyResponse.Settings.Inventory) {
case Steam.PrivacyResponse.PrivacySettings.EPrivacySetting.FriendsOnly:
case Steam.PrivacyResponse.PrivacySettings.EPrivacySetting.Private:
switch (userPrivacy.Settings.Inventory) {
case Steam.UserPrivacy.PrivacySettings.EPrivacySetting.FriendsOnly:
case Steam.UserPrivacy.PrivacySettings.EPrivacySetting.Private:
return false;
case Steam.PrivacyResponse.PrivacySettings.EPrivacySetting.Public:
case Steam.UserPrivacy.PrivacySettings.EPrivacySetting.Public:
return true;
default:
Bot.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(privacyResponse.Settings.Inventory), privacyResponse.Settings.Inventory));
Bot.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(userPrivacy.Settings.Inventory), userPrivacy.Settings.Inventory));
return null;
}
}