diff --git a/ArchiSteamFarm/ArchiHandler.cs b/ArchiSteamFarm/ArchiHandler.cs index 7c410d0c8..57ade0702 100644 --- a/ArchiSteamFarm/ArchiHandler.cs +++ b/ArchiSteamFarm/ArchiHandler.cs @@ -38,6 +38,7 @@ namespace ArchiSteamFarm { private readonly ArchiLogger ArchiLogger; private readonly SteamUnifiedMessages.UnifiedService UnifiedChatRoomService; + private readonly SteamUnifiedMessages.UnifiedService UnifiedClanChatRoomsService; private readonly SteamUnifiedMessages.UnifiedService UnifiedFriendMessagesService; private readonly SteamUnifiedMessages.UnifiedService UnifiedPlayerService; @@ -50,6 +51,7 @@ namespace ArchiSteamFarm { ArchiLogger = archiLogger; UnifiedChatRoomService = steamUnifiedMessages.CreateService(); + UnifiedClanChatRoomsService = steamUnifiedMessages.CreateService(); UnifiedFriendMessagesService = steamUnifiedMessages.CreateService(); UnifiedPlayerService = steamUnifiedMessages.CreateService(); } @@ -161,6 +163,39 @@ namespace ArchiSteamFarm { return response.Result == EResult.OK; } + internal async Task GetClanChatGroupID(ulong steamID) { + if ((steamID == 0) || !new SteamID(steamID).IsClanAccount) { + ArchiLogger.LogNullError(nameof(steamID)); + return 0; + } + + CClanChatRooms_GetClanChatRoomInfo_Request request = new CClanChatRooms_GetClanChatRoomInfo_Request { + autocreate = true, + steamid = steamID + }; + + SteamUnifiedMessages.ServiceMethodResponse response; + + try { + response = await UnifiedClanChatRoomsService.SendMessage(x => x.GetClanChatRoomInfo(request)); + } catch (Exception e) { + ArchiLogger.LogGenericWarningException(e); + return 0; + } + + if (response == null) { + ArchiLogger.LogNullError(nameof(response)); + return 0; + } + + if (response.Result != EResult.OK) { + return 0; + } + + CClanChatRooms_GetClanChatRoomInfo_Response body = response.GetDeserializedResponse(); + return body.chat_group_summary.chat_group_id; + } + internal async Task> GetMyChatGroupIDs() { CChatRoom_GetMyChatRoomGroups_Request request = new CChatRoom_GetMyChatRoomGroups_Request(); diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 5f2548e6c..3cefc4787 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -1766,14 +1766,18 @@ namespace ArchiSteamFarm { await ArchiHandler.JoinChatRoomGroup(chatGroupID).ConfigureAwait(false); } - private async Task JoinMasterClanAndChat() { - if (BotConfig.SteamMasterClanID != 0) { - await ArchiWebHandler.JoinGroup(BotConfig.SteamMasterClanID).ConfigureAwait(false); + private async Task JoinMasterChatGroupID() { + if (BotConfig.SteamMasterClanID == 0) { + return; } - if (BotConfig.SteamMasterChatGroupID != 0) { - await JoinChatGroupID(BotConfig.SteamMasterChatGroupID).ConfigureAwait(false); + ulong chatGroupID = await ArchiHandler.GetClanChatGroupID(BotConfig.SteamMasterClanID).ConfigureAwait(false); + + if (chatGroupID == 0) { + return; } + + await JoinChatGroupID(chatGroupID).ConfigureAwait(false); } private static async Task LimitGiftsRequestsAsync() { @@ -1967,11 +1971,7 @@ namespace ArchiSteamFarm { switch (friend.SteamID.AccountType) { case EAccountType.Clan when IsMasterClanID(friend.SteamID): ArchiHandler.AcknowledgeClanInvite(friend.SteamID, true); - - if (BotConfig.SteamMasterChatGroupID != 0) { - await JoinChatGroupID(BotConfig.SteamMasterChatGroupID).ConfigureAwait(false); - } - + await JoinMasterChatGroupID().ConfigureAwait(false); break; case EAccountType.Clan: if (BotConfig.BotBehaviour.HasFlag(BotConfig.EBotBehaviour.RejectInvalidGroupInvites)) { @@ -2286,7 +2286,15 @@ namespace ArchiSteamFarm { SteamFriends.SetPersonaState(BotConfig.OnlineStatus); } - Utilities.InBackground(JoinMasterClanAndChat); + if (BotConfig.SteamMasterClanID != 0) { + Utilities.InBackground( + async () => { + await ArchiWebHandler.JoinGroup(BotConfig.SteamMasterClanID).ConfigureAwait(false); + await JoinMasterChatGroupID().ConfigureAwait(false); + } + ); + } + break; case EResult.InvalidPassword: case EResult.NoConnection: diff --git a/ArchiSteamFarm/BotConfig.cs b/ArchiSteamFarm/BotConfig.cs index 515e39774..02ab9d430 100644 --- a/ArchiSteamFarm/BotConfig.cs +++ b/ArchiSteamFarm/BotConfig.cs @@ -114,9 +114,6 @@ namespace ArchiSteamFarm { [JsonProperty] internal string SteamLogin { get; set; } - [JsonProperty(Required = Required.DisallowNull)] - internal ulong SteamMasterChatGroupID { get; private set; } - [JsonProperty(Required = Required.DisallowNull)] internal ulong SteamMasterClanID { get; private set; } @@ -128,19 +125,6 @@ namespace ArchiSteamFarm { private bool ShouldSerializeSensitiveDetails = true; - [JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamMasterChatGroupID), Required = Required.DisallowNull)] - private string SSteamMasterChatGroupID { - get => SteamMasterChatGroupID.ToString(); - set { - if (string.IsNullOrEmpty(value) || !ulong.TryParse(value, out ulong result)) { - ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(SSteamMasterChatGroupID))); - return; - } - - SteamMasterChatGroupID = result; - } - } - [JsonProperty(PropertyName = SharedInfo.UlongCompatibilityStringPrefix + nameof(SteamMasterClanID), Required = Required.DisallowNull)] private string SSteamMasterClanID { get => SteamMasterClanID.ToString(); @@ -228,6 +212,11 @@ namespace ArchiSteamFarm { return null; } + if ((botConfig.SteamMasterClanID != 0) && !new SteamID(botConfig.SteamMasterClanID).IsClanAccount) { + ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.SteamMasterClanID), botConfig.SteamMasterClanID)); + return null; + } + foreach (EPermission permission in botConfig.SteamUserPermissions.Values) { if (!Enum.IsDefined(typeof(EPermission), permission)) { ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorConfigPropertyInvalid, nameof(botConfig.SteamUserPermissions), permission)); diff --git a/ArchiSteamFarm/config/example.json b/ArchiSteamFarm/config/example.json index 5b5207c8b..32148f1d1 100644 --- a/ArchiSteamFarm/config/example.json +++ b/ArchiSteamFarm/config/example.json @@ -26,7 +26,6 @@ "SendTradePeriod": 0, "ShutdownOnFarmingFinished": false, "SteamLogin": null, - "SteamMasterChatGroupID": 0, "SteamMasterClanID": 0, "SteamParentalPIN": "0", "SteamPassword": null, @@ -34,4 +33,4 @@ "SteamUserPermissions": {}, "TradingPreferences": 0, "UseLoginKeys": true -} \ No newline at end of file +} diff --git a/ArchiSteamFarm/config/minimal.json b/ArchiSteamFarm/config/minimal.json index a75051327..9699bdba5 100644 --- a/ArchiSteamFarm/config/minimal.json +++ b/ArchiSteamFarm/config/minimal.json @@ -2,4 +2,4 @@ "Enabled": false, "SteamLogin": null, "SteamPassword": null -} \ No newline at end of file +}