SteamInviteHelper-ASF
SteamInviteHelper-ASF copied to clipboard
[Suggestion] Add a rule to check if user commented in bot's profile before inviting.
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.
Good suggestion! I will add this when I got time on hand
Is this already implemented/ready with 3897b4c?
Can you release it since you already implemented it on the last commit please?
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 --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<Bot, Config> FriendInviteConfigs = new ConcurrentDictionary<Bot, Config>();
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<Action> actions = new List<Action>();
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<string> actionpriority = config.ActionPriority;
@@ -299,41 +300,60 @@ namespace SteamInviteHelper_ASF
List<KeyValuePair<string, string>> comments = new List<KeyValuePair<string, string>>();
var nodes = htmlDocument.DocumentNode.SelectNodes(@"//div[contains(@class, 'commentthread_comment') and contains(@class, 'responsive_body_text')]");
+ var groupedData = new List<KeyValuePair<string, string>>().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<string, string>(authorProfileID, comment));
- }
+ string authorProfileID = authorUri.Segments[authorUri.Segments.Count() - 1].Replace(@"/", "");
+ comments.Add(new KeyValuePair<string, string>(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)
Updated to latest ASF: https://github.com/Lucki/SteamInviteHelper-ASF/releases/tag/1.0.4