brianzhouzc / SteamInviteHelper-ASF

An ASF plugin that process steam invites automatically
50 stars 9 forks source link

[Suggestion] Add a rule to check if user commented in bot's profile before inviting. #1

Open Rudokhvist opened 5 years ago

Rudokhvist commented 5 years ago

Hello! First of all, thank you for making this plugin, I haven't tried it yet but it looks promising. I have a suggestion for further improving it. Many users have a rule like "comment in my profile with the reason before adding me", so it would be nice to handle this case automatically, i.e. to have a rule that will check for profile comments from the same account as the one inviting to friend, and taking action appropriately. As an extra feature to the above - consider adding one more rule that will check that comment contains some text.

brianzhouzc commented 5 years ago

Good suggestion! I will add this when I got time on hand

Lucki commented 5 years ago

Is this already implemented/ready with 3897b4c?

Rysanlos commented 5 years ago

Can you release it since you already implemented it on the last commit please?

Lucki commented 4 years ago

Is this already implemented/ready with 3897b4c?

No it's not.

Here's some simple, hackish, not the slightest tested, without any error checking code: ~~~ diff diff --git a/SteamInviteHelper-ASF/Config.cs b/SteamInviteHelper-ASF/Config.cs index b9d6383..2055203 100644 --- a/SteamInviteHelper-ASF/Config.cs +++ b/SteamInviteHelper-ASF/Config.cs @@ -12,7 +12,7 @@ namespace SteamInviteHelper_ASF { class Config { - private const string defaultConfig = @"{""SteamInviteHelper"":{""Enabled"":true,""ActionPriority"":[""block"",""ignore"",""add"",""none""],""PrivateProfile"":{""action"":""block""},""SteamRepScammer"":{""action"":""block""},""SteamLevel"":[{""condition"":""default"",""value"":-1,""action"":""none""},{""condition"":""less_than"",""value"":1,""action"":""block""},{""condition"":""less_than"",""value"":5,""action"":""ignore""}],""VACBanned"":[{""condition"":""default"",""value"":-1,""action"":""none""},{""condition"":""more_than"",""value"":1,""action"":""ignore""}],""GameBanned"":[{""condition"":""default"",""value"":-1,""action"":""none""},{""condition"":""more_than"",""value"":1,""action"":""ignore""}],""DaysSinceLastBan"":[{""condition"":""default"",""value"":-1,""action"":""none""},{""condition"":""less_than"",""value"":90,""action"":""ignore""}],""CommunityBanned"":{""action"":""none""},""EconomyBanned"":{""action"":""none""},""ProfileName"":[{""condition"":""default"",""value"":"""",""action"":""none""},{""condition"":""contain"",""value"":""shittygamblingsite.com"",""action"":""ignore""}]}}"; + private const string defaultConfig = @"{""SteamInviteHelper"":{""Enabled"":true,""ActionPriority"":[""block"",""ignore"",""add"",""none""],""PrivateProfile"":{""action"":""block""},""SteamRepScammer"":{""action"":""block""},""SteamLevel"":[{""condition"":""default"",""value"":-1,""action"":""none""},{""condition"":""less_than"",""value"":1,""action"":""block""},{""condition"":""less_than"",""value"":5,""action"":""ignore""}],""VACBanned"":[{""condition"":""default"",""value"":-1,""action"":""none""},{""condition"":""more_than"",""value"":1,""action"":""ignore""}],""GameBanned"":[{""condition"":""default"",""value"":-1,""action"":""none""},{""condition"":""more_than"",""value"":1,""action"":""ignore""}],""DaysSinceLastBan"":[{""condition"":""default"",""value"":-1,""action"":""none""},{""condition"":""less_than"",""value"":90,""action"":""ignore""}],""CommunityBanned"":{""action"":""none""},""EconomyBanned"":{""action"":""none""},""ProfileName"":[{""condition"":""default"",""value"":"""",""action"":""none""},{""condition"":""contain"",""value"":""shittygamblingsite.com"",""action"":""ignore""}],""Comments"":[{""condition"":""default"",""value"":"""",""action"":""none""},{""condition"":""less_than"",""value"":""1"",""action"":""ignore""}]}}"; public static ConcurrentDictionary FriendInviteConfigs = new ConcurrentDictionary(); public bool Enabled { get; set; } diff --git a/SteamInviteHelper-ASF/FriendInviteHandler.cs b/SteamInviteHelper-ASF/FriendInviteHandler.cs index 6ff340e..71e5ede 100644 --- a/SteamInviteHelper-ASF/FriendInviteHandler.cs +++ b/SteamInviteHelper-ASF/FriendInviteHandler.cs @@ -18,8 +18,6 @@ namespace SteamInviteHelper_ASF UserProfile userProfile = await UserProfile.BuildUserProfile(SteamID.ConvertToUInt64(), bot); Logger.LogDebug("[PROFILE DETAILS]: " + userProfile.ToString()); - await processCommentedOnProfile(userProfile, bot); - List actions = new List(); actions.Add(processPrivateProfile(userProfile, bot)); @@ -49,6 +47,9 @@ namespace SteamInviteHelper_ASF actions.Add(processProfileName(userProfile, bot)); Logger.LogDebug("[ACTION PROFILE NAME]: " + processProfileName(userProfile, bot).action); + actions.Add(await processCommentedOnProfile(userProfile, bot)); + Logger.LogDebug("[ACTION COMMENTED]: " + await processCommentedOnProfile(userProfile, bot)); + Config.FriendInviteConfigs.TryGetValue(bot, out Config config); List actionpriority = config.ActionPriority; @@ -299,41 +300,60 @@ namespace SteamInviteHelper_ASF List> comments = new List>(); var nodes = htmlDocument.DocumentNode.SelectNodes(@"//div[contains(@class, 'commentthread_comment') and contains(@class, 'responsive_body_text')]"); + var groupedData = new List>().ToLookup(x => x.Key, x => x.Value); - foreach (HtmlNode node in nodes) + if (nodes != null) { - HtmlNode authorLinkNode = node.SelectSingleNode(@".//a[contains(@class, 'hoverunderline') and contains(@class, 'commentthread_author_link')]"); - HtmlNode commentNode = node.SelectSingleNode(@".//div[contains(@class, 'commentthread_comment_text')]"); + foreach (HtmlNode node in nodes) + { + HtmlNode authorLinkNode = node.SelectSingleNode(@".//a[contains(@class, 'hoverunderline') and contains(@class, 'commentthread_author_link')]"); + HtmlNode commentNode = node.SelectSingleNode(@".//div[contains(@class, 'commentthread_comment_text')]"); - Uri authorUri = new Uri(authorLinkNode.GetAttributeValue("href", "")); - string comment = commentNode.InnerText.Trim().Normalize(); + Uri authorUri = new Uri(authorLinkNode.GetAttributeValue("href", "")); + string comment = commentNode.InnerText.Trim().Normalize(); - string authorProfileID = authorUri.Segments[authorUri.Segments.Count() - 1].Replace(@"/", ""); - comments.Add(new KeyValuePair(authorProfileID, comment)); - } + string authorProfileID = authorUri.Segments[authorUri.Segments.Count() - 1].Replace(@"/", ""); + comments.Add(new KeyValuePair(authorProfileID, comment)); + } - Uri senderProfileUri = new Uri(userProfile.profileUrl); - string senderProfileID = senderProfileUri.Segments[senderProfileUri.Segments.Count() - 1].Replace(@"/", ""); + Uri senderProfileUri = new Uri(userProfile.profileUrl); + string senderProfileID = senderProfileUri.Segments[senderProfileUri.Segments.Count() - 1].Replace(@"/", ""); - Config.FriendInviteConfigs.TryGetValue(bot, out Config config); + groupedData = comments.ToLookup(x => x.Key, x => x.Value); + } - var groupedData = comments.ToLookup(x => x.Key, x => x.Value); + Config.FriendInviteConfigs.TryGetValue(bot, out Config config); + string defaultAction = "none"; foreach (ConfigItem item in config.Comments) { switch (item.condition) { - case "commented": - if (groupedData.) - { + case "less_than": + if (!groupedData.Contains(userProfile.steamId64.ToString()) && (Convert.ToInt32(item.value) > 0)) + return new Action(item.action, "Number of comments < " + Convert.ToInt32(item.value)); - } + if (groupedData.Contains(userProfile.steamId64.ToString()) && (groupedData[userProfile.steamId64.ToString()].Count() < Convert.ToInt32(item.value))) + return new Action(item.action, "Number of comments < " + Convert.ToInt32(item.value)); + break; + case "more_than": + if (groupedData.Contains(userProfile.steamId64.ToString()) && (groupedData[userProfile.steamId64.ToString()].Count() > Convert.ToInt32(item.value))) + return new Action(item.action, "Number of comments > " + Convert.ToInt32(item.value)); + break; + case "equal": + if (groupedData.Contains(userProfile.steamId64.ToString()) && groupedData[userProfile.steamId64.ToString()].Contains(item.value)) + return new Action(item.action, "Comment is " + item.value); break; case "contain": + if (groupedData.Contains(userProfile.steamId64.ToString()) && (groupedData[userProfile.steamId64.ToString()].Where(comment => comment.Contains(item.value, StringComparison.OrdinalIgnoreCase)).Count() > 0)) + return new Action(item.action, "Profile comment contains " + item.value); + break; + case "default": + defaultAction = item.action; break; } } - return null; + return new Action(defaultAction); } public override void HandleMsg(IPacketMsg packetMsg) ~~~

SteamInviteHelper-ASF.zip

Lucki commented 4 years ago

Updated to latest ASF: https://github.com/Lucki/SteamInviteHelper-ASF/releases/tag/1.0.4