Commit b708a39e authored by nanahira's avatar nanahira

fix incorrect ghost ban check

parent 1726827e
Pipeline #18577 passed with stage
in 59 seconds
...@@ -44,6 +44,7 @@ FeaturesDict = { ...@@ -44,6 +44,7 @@ FeaturesDict = {
"verified_phone_label_enabled": False, "verified_phone_label_enabled": False,
"responsive_web_twitter_blue_verified_badge_is_enabled": False, "responsive_web_twitter_blue_verified_badge_is_enabled": False,
"view_counts_public_visibility_enabled": False, "view_counts_public_visibility_enabled": False,
"view_counts_everywhere_api_enabled": False,
} }
FeaturesJson = json.dumps(FeaturesDict) FeaturesJson = json.dumps(FeaturesDict)
...@@ -250,7 +251,7 @@ def searchban(screen_name): ...@@ -250,7 +251,7 @@ def searchban(screen_name):
try: try:
repliesJson = replies.json() repliesJson = replies.json()
print(repliesJson) # print(repliesJson)
maindata = repliesJson["data"]["user"]["result"]["timeline"]["timeline"]["instructions"] maindata = repliesJson["data"]["user"]["result"]["timeline"]["timeline"]["instructions"]
for d in maindata: for d in maindata:
if d["type"] == "TimelineAddEntries": if d["type"] == "TimelineAddEntries":
...@@ -280,36 +281,31 @@ def searchban(screen_name): ...@@ -280,36 +281,31 @@ def searchban(screen_name):
tweetdetails = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["TweetDetail"], "TweetDetail"), params={"variables": json.dumps(tweet_detail_vars), "features": FeaturesJson}) tweetdetails = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["TweetDetail"], "TweetDetail"), params={"variables": json.dumps(tweet_detail_vars), "features": FeaturesJson})
insts = tweetdetails.json()["data"]["threaded_conversation_with_injections"]["instructions"] insts = tweetdetails.json()["data"]["threaded_conversation_with_injections"]["instructions"]
ghostban = True
inReplyToGhost = reply["id_str"]
inReplyToShowMore = reply["id_str"]
showmore = False showmore = False
for inst in insts: for inst in insts:
if inst["type"] == "TimelineAddEntries": if inst["type"] == "TimelineAddEntries":
for ent in inst["entries"]: for ent in inst["entries"]:
print("Current entry of {} is: {}".format(screen_name, ent["entryId"])) print("Current entry of {} is: {}".format(screen_name, ent["entryId"]))
if ent["entryId"].startswith("conversationthread"): if ent["entryId"].startswith("conversationthread") and ghostban:
ghostban = True
inReplyTo = reply["id_str"]
for item in ent["content"]["items"]: for item in ent["content"]["items"]:
if "tweet_results" in item["item"]["itemContent"]: #print("Current sub entry of {} {} is: {}".format(screen_name, ent["entryId"], item["item"]["itemContent"]))
if item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id: if "tweet_results" in item["item"]["itemContent"] and item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id:
returnjson["tests"]["ghost"] = {"ban": False, "in_reply_to": item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]} validId = item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]
ghostban = False returnjson["tests"]["ghost"] = {"ban": False, "in_reply_to": validId}
break ghostban = False
else: print("Found valid reply {}, so {} is not ghost banned.".format(validId, screen_name))
inReplyTo = item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"] break
if ghostban:
print("{} is ghost banned.".format(screen_name))
returnjson["tests"]["ghost"] = {"ban": True, "in_reply_to": inReplyTo}
if ent["entryId"].startswith("cursor-bottom"): if ent["entryId"].startswith("cursor-bottom"):
print("{}'s test touched bottom.".format(screen_name)) print("{}'s test touched bottom.".format(screen_name))
#returnjson["tests"]["ghost"] = {} #returnjson["tests"]["ghost"] = {}
#returnjson["tests"]["more_replies"] = {} #returnjson["tests"]["more_replies"] = {}
break break
if ent["entryId"].startswith("cursor-showmorethreadsprompt"): if ent["entryId"].startswith("cursor-showmorethreadsprompt") and not showmore:
showmore = True # showmore = True
cursor_vars = tweet_detail_vars cursor_vars = tweet_detail_vars
cursor_vars["cursor"] = ent["content"]["itemContent"]["value"] cursor_vars["cursor"] = ent["content"]["itemContent"]["value"]
cursor = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["TweetDetail"], "TweetDetail"), params={"variables": json.dumps(cursor_vars), "features": FeaturesJson}) cursor = twitter_b.get("https://twitter.com/i/api/graphql/{}/{}".format(ENDPOINT["TweetDetail"], "TweetDetail"), params={"variables": json.dumps(cursor_vars), "features": FeaturesJson})
...@@ -319,6 +315,7 @@ def searchban(screen_name): ...@@ -319,6 +315,7 @@ def searchban(screen_name):
if c_i["type"] == "TimelineAddEntries": if c_i["type"] == "TimelineAddEntries":
if len(c_i["entries"]) == 0: if len(c_i["entries"]) == 0:
returnjson["tests"]["more_replies"] = {"ban": True} returnjson["tests"]["more_replies"] = {"ban": True}
showmore = True
break break
for c_ent in c_i["entries"]: for c_ent in c_i["entries"]:
if c_ent["entryId"].startswith("conversationthread"): if c_ent["entryId"].startswith("conversationthread"):
...@@ -326,20 +323,24 @@ def searchban(screen_name): ...@@ -326,20 +323,24 @@ def searchban(screen_name):
print("Checking more contents of {}".format(screen_name)) print("Checking more contents of {}".format(screen_name))
for c_item in c_ent["content"]["items"]: for c_item in c_ent["content"]["items"]:
if c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id: if c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["user_id_str"] == user_id:
inReplyTo = c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"] inReplyToShowMore = c_item["item"]["itemContent"]["tweet_results"]["result"]["legacy"]["id_str"]
# returnjson["tests"]["ghost"] = {"ban": False, "in_reply_to": inReplyTo} # returnjson["tests"]["ghost"] = {"ban": False, "in_reply_to": inReplyToShowMore}
returnjson["tests"]["more_replies"] = {"ban": True, "in_reply_to": inReplyTo} returnjson["tests"]["more_replies"] = {"ban": True, "in_reply_to": inReplyToShowMore}
print("{} is reply deboosted.".format(screen_name)) print("{} is reply deboosted because of {}.".format(screen_name, inReplyToShowMore))
showmore = True
# more = False # more = False
break break
#if more: #if more:
# print("{} is both ghost banned and reply deboosted.".format(screen_name)) # print("{} is both ghost banned and reply deboosted.".format(screen_name))
# returnjson["tests"]["ghost"] = {"ban": True} # returnjson["tests"]["ghost"] = {"ban": True}
# returnjson["tests"]["more_replies"] = {"ban": True} # returnjson["tests"]["more_replies"] = {"ban": True}
if ghostban:
print("{} is ghost banned.".format(screen_name))
returnjson["tests"]["ghost"] = {"ban": True, "in_reply_to": inReplyToGhost}
if not showmore: if not showmore:
returnjson["tests"]["more_replies"] = { returnjson["tests"]["more_replies"] = {
"ban": False, "ban": False,
"in_reply_to": reply["id_str"], "in_reply_to": inReplyToShowMore,
} }
replyTweet = reply["in_reply_to_status_id_str"] replyTweet = reply["in_reply_to_status_id_str"]
for testField in ["ghost", "more_replies"]: for testField in ["ghost", "more_replies"]:
...@@ -357,8 +358,8 @@ def searchban(screen_name): ...@@ -357,8 +358,8 @@ def searchban(screen_name):
#print(returnjson["tests"]["ghost"]) #print(returnjson["tests"]["ghost"])
# No search ban => No ghost ban # No search ban => No ghost ban
if returnjson["tests"]["search"] and returnjson["tests"]["search"] != "_error" and "ban" in returnjson["tests"]["ghost"] and returnjson["tests"]["ghost"]["ban"] == True: #if returnjson["tests"]["search"] and returnjson["tests"]["search"] != "_error" and "ban" in returnjson["tests"]["ghost"] and returnjson["tests"]["ghost"]["ban"] == True:
returnjson["tests"]["ghost"]["ban"] = False # returnjson["tests"]["ghost"]["ban"] = False
# No ghost ban && unknown more replies => No more replies ban # No ghost ban && unknown more replies => No more replies ban
if "ban" not in returnjson["tests"]["more_replies"] and "ban" in returnjson["tests"]["ghost"] and returnjson["tests"]["ghost"]["ban"] == False: if "ban" not in returnjson["tests"]["more_replies"] and "ban" in returnjson["tests"]["ghost"] and returnjson["tests"]["ghost"]["ban"] == False:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment