mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-12 14:39:54 -05:00
update retrievalmethod
This commit is contained in:
parent
418f88a61d
commit
b90f6c7b6d
@ -29,6 +29,40 @@ class Sherlock():
|
|||||||
self.dict[sherlockdict] = valid_usernames_dict[sherlockdict]
|
self.dict[sherlockdict] = valid_usernames_dict[sherlockdict]
|
||||||
self.dict[sherlockdict]["cache"] = dict()
|
self.dict[sherlockdict]["cache"] = dict()
|
||||||
|
|
||||||
|
def check_network(self, username, social_network):
|
||||||
|
url = self.dict.get(social_network).get("url").format(username)
|
||||||
|
error_type = self.dict.get(social_network).get("errorType")
|
||||||
|
cant_have_period = self.dict.get(social_network).get("noPeriod")
|
||||||
|
|
||||||
|
if ("." in username) and (cant_have_period == "True"):
|
||||||
|
while ("." in username):
|
||||||
|
username = username.replace(".", '')
|
||||||
|
|
||||||
|
r, error_type = self.make_request(url=url, error_type=error_type, social_network=social_network)
|
||||||
|
|
||||||
|
if error_type == "message":
|
||||||
|
error = self.dict.get(social_network).get("errorMsg")
|
||||||
|
# Checks if the error message is in the HTML
|
||||||
|
if error not in r.text:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
elif error_type == "status_code":
|
||||||
|
# Checks if the status code of the repsonse is 404
|
||||||
|
if not r.status_code == 404:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
elif error_type == "response_url":
|
||||||
|
error = self.dict.get(social_network).get("errorUrl")
|
||||||
|
# Checks if the redirect url is the same as the one defined in data.json
|
||||||
|
if error not in r.url:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def make_request(self, url, error_type, social_network):
|
def make_request(self, url, error_type, social_network):
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, headers=self.header)
|
r = requests.get(url, headers=self.header)
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import sopel_modules.SpiceBot as SpiceBot
|
|||||||
@sopel.module.commands('sherlock', 'username')
|
@sopel.module.commands('sherlock', 'username')
|
||||||
def bot_command_sherlock(bot, trigger):
|
def bot_command_sherlock(bot, trigger):
|
||||||
|
|
||||||
data = SpiceBot.sherlock.dict
|
|
||||||
netlist = list(SpiceBot.sherlock.dict.keys())
|
netlist = list(SpiceBot.sherlock.dict.keys())
|
||||||
|
|
||||||
username = spicemanip.main(trigger.sb["args"], 1) or trigger.nick
|
username = spicemanip.main(trigger.sb["args"], 1) or trigger.nick
|
||||||
@ -28,43 +27,15 @@ def bot_command_sherlock(bot, trigger):
|
|||||||
|
|
||||||
bot.osd("Checking username " + username + " in " + checklistname + " network.")
|
bot.osd("Checking username " + username + " in " + checklistname + " network.")
|
||||||
|
|
||||||
inlist = []
|
inlist, notinlist = [], []
|
||||||
notinlist = []
|
|
||||||
|
|
||||||
for social_network in checklist:
|
for social_network in checklist:
|
||||||
|
|
||||||
url = data.get(social_network).get("url").format(username)
|
in_social = SpiceBot.sherlock.check_network(username, social_network)
|
||||||
error_type = data.get(social_network).get("errorType")
|
if in_social:
|
||||||
cant_have_period = data.get(social_network).get("noPeriod")
|
inlist.append(social_network)
|
||||||
|
else:
|
||||||
if ("." in username) and (cant_have_period == "True"):
|
notinlist.append(social_network)
|
||||||
while ("." in username):
|
|
||||||
username = username.replace(".", '')
|
|
||||||
|
|
||||||
r, error_type = SpiceBot.sherlock.make_request(url=url, error_type=error_type, social_network=social_network)
|
|
||||||
|
|
||||||
if error_type == "message":
|
|
||||||
error = data.get(social_network).get("errorMsg")
|
|
||||||
# Checks if the error message is in the HTML
|
|
||||||
if error not in r.text:
|
|
||||||
inlist.append(social_network)
|
|
||||||
else:
|
|
||||||
notinlist.append(social_network)
|
|
||||||
|
|
||||||
elif error_type == "status_code":
|
|
||||||
# Checks if the status code of the repsonse is 404
|
|
||||||
if not r.status_code == 404:
|
|
||||||
inlist.append(social_network)
|
|
||||||
else:
|
|
||||||
notinlist.append(social_network)
|
|
||||||
|
|
||||||
elif error_type == "response_url":
|
|
||||||
error = data.get(social_network).get("errorUrl")
|
|
||||||
# Checks if the redirect url is the same as the one defined in data.json
|
|
||||||
if error not in r.url:
|
|
||||||
inlist.append(social_network)
|
|
||||||
else:
|
|
||||||
notinlist.append(social_network)
|
|
||||||
|
|
||||||
if inlist != []:
|
if inlist != []:
|
||||||
if checklistname != 'all':
|
if checklistname != 'all':
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user