mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 15:09:54 -05:00
sherlock
This commit is contained in:
parent
6c8f814451
commit
7bae4b8620
43
sopel_modules/SpiceBot/Sherlock.py
Normal file
43
sopel_modules/SpiceBot/Sherlock.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# coding=utf8
|
||||||
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
"""A way to search google"""
|
||||||
|
|
||||||
|
import sopel_modules
|
||||||
|
|
||||||
|
from .Tools import read_directory_json_to_dict
|
||||||
|
|
||||||
|
import os
|
||||||
|
from fake_useragent import UserAgent
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class Sherlock():
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.header = {'User-Agent': str(UserAgent().chrome)}
|
||||||
|
self.dict - dict()
|
||||||
|
|
||||||
|
dir_to_scan = []
|
||||||
|
for plugin_dir in set(sopel_modules.__path__):
|
||||||
|
configsdir = os.path.join(plugin_dir, "SpiceBot_Configs")
|
||||||
|
usercfgdir = os.path.join(configsdir, "sherlock")
|
||||||
|
dir_to_scan.append(usercfgdir)
|
||||||
|
|
||||||
|
valid_usernames_dict = read_directory_json_to_dict(dir_to_scan, "Gif API", "SpiceBot_Gif")
|
||||||
|
|
||||||
|
for sherlockdict in list(valid_usernames_dict.keys()):
|
||||||
|
self.dict[sherlockdict] = valid_usernames_dict[sherlockdict]
|
||||||
|
self.dict[sherlockdict]["cache"] = dict()
|
||||||
|
|
||||||
|
def make_request(self, url, error_type, social_network):
|
||||||
|
try:
|
||||||
|
r = requests.get(url, headers=self.header)
|
||||||
|
if r.status_code:
|
||||||
|
return r, error_type
|
||||||
|
except Exception as e:
|
||||||
|
returnval = e
|
||||||
|
returnval = None
|
||||||
|
return returnval, ""
|
||||||
|
|
||||||
|
|
||||||
|
sherlock = Sherlock()
|
||||||
@ -24,6 +24,7 @@ from .Users import *
|
|||||||
from .AI import *
|
from .AI import *
|
||||||
from .Google import *
|
from .Google import *
|
||||||
from .Gif import *
|
from .Gif import *
|
||||||
|
from .Sherlock import *
|
||||||
|
|
||||||
|
|
||||||
from .configure import *
|
from .configure import *
|
||||||
|
|||||||
75
sopel_modules/SpiceBot_Core_Commands/Sherlock.py
Normal file
75
sopel_modules/SpiceBot_Core_Commands/Sherlock.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# coding=utf8
|
||||||
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
|
||||||
|
# sopel imports
|
||||||
|
import sopel.module
|
||||||
|
|
||||||
|
import spicemanip
|
||||||
|
|
||||||
|
import sopel_modules.SpiceBot as SpiceBot
|
||||||
|
|
||||||
|
|
||||||
|
@SpiceBot.prerun.prerun('module')
|
||||||
|
@sopel.module.commands('sherlock', 'username')
|
||||||
|
def bot_command_sherlock(bot, trigger):
|
||||||
|
|
||||||
|
data = SpiceBot.sherlock.dict
|
||||||
|
netlist = list(SpiceBot.sherlock.dict.keys())
|
||||||
|
|
||||||
|
username = spicemanip.main(trigger.sb["args"], 1) or trigger.nick
|
||||||
|
trigger.sb["args"] = spicemanip.main(trigger.sb["args"], "2+", 'list')
|
||||||
|
|
||||||
|
checklist = netlist
|
||||||
|
checklistname = 'all'
|
||||||
|
if SpiceBot.bot_check_inlist(bot, username, netlist):
|
||||||
|
checklistname = SpiceBot.inlist_match(bot, username, netlist)
|
||||||
|
checklist = [checklistname]
|
||||||
|
username = spicemanip.main(trigger.sb["args"], 1) or trigger.nick
|
||||||
|
|
||||||
|
bot.osd("Checking username " + username + " in " + checklistname + " network.")
|
||||||
|
|
||||||
|
inlist = []
|
||||||
|
notinlist = []
|
||||||
|
|
||||||
|
for social_network in checklist:
|
||||||
|
|
||||||
|
url = data.get(social_network).get("url").format(username)
|
||||||
|
error_type = data.get(social_network).get("errorType")
|
||||||
|
cant_have_period = data.get(social_network).get("noPeriod")
|
||||||
|
|
||||||
|
if ("." in username) and (cant_have_period == "True"):
|
||||||
|
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 checklistname != 'all':
|
||||||
|
bot.osd(["The username " + username + " is in " + checklist[0]])
|
||||||
|
else:
|
||||||
|
bot.osd(["The username " + username + " is in the following:", spicemanip.main(inlist, "andlist")])
|
||||||
|
if notinlist != []:
|
||||||
|
bot.osd(["The username " + username + " is NOT in the following:", spicemanip.main(notinlist, "andlist")])
|
||||||
@ -19,6 +19,7 @@ from .BotPrivs import *
|
|||||||
from .Search import *
|
from .Search import *
|
||||||
from .AI import *
|
from .AI import *
|
||||||
from .Gif import *
|
from .Gif import *
|
||||||
|
from .Sherlock import *
|
||||||
|
|
||||||
__author__ = 'Sam Zick'
|
__author__ = 'Sam Zick'
|
||||||
__email__ = 'sam@deathbybandaid.net'
|
__email__ = 'sam@deathbybandaid.net'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user