Merge pull request #65 from deathbybandaid/development

Development
This commit is contained in:
Deathbybandaid 2019-06-19 07:51:41 -04:00 committed by GitHub
commit f23f622e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
84 changed files with 502 additions and 2 deletions

View File

@ -0,0 +1,89 @@
# 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
import time
class Sherlock():
def __init__(self):
self.header = {'User-Agent': str(UserAgent().chrome)}
self.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 social_network in list(valid_usernames_dict.keys()):
self.dict[social_network] = valid_usernames_dict[social_network]
self.dict[social_network]["cache"] = dict()
def check_network(self, username, social_network):
if username in list(self.dict[social_network]["cache"].keys()):
if time.time() - self.dict[social_network]["cache"][username]["time"] <= 1800:
return self.dict[social_network]["cache"][username]["exists"]
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)
user_exists = False
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:
user_exists = True
elif error_type == "status_code":
# Checks if the status code of the repsonse is 404
if not r.status_code == 404:
user_exists = True
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:
user_exists = True
self.dict[social_network]["cache"][username] = {
"time": time.time(),
"exists": user_exists
}
if user_exists:
return True
else:
return False
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()

View File

@ -333,7 +333,7 @@ def read_directory_json_to_dict(directories, configtypename="Config File", log_f
if len(os.listdir(directory)) > 0:
for file in os.listdir(directory):
filepath = os.path.join(directory, file)
if os.path.isfile(filepath):
if os.path.isfile(filepath) and filepath.endswith('.json'):
filesprocess.append(filepath)
for filepath in filesprocess:
@ -356,7 +356,8 @@ def read_directory_json_to_dict(directories, configtypename="Config File", log_f
filecount += 1
slashsplit = str(filepath).split("/")
filename = slashsplit[-1]
configs_dict[filename] = dict_from_file
filename_base = os.path.basename(filename).rsplit('.', 1)[0]
configs_dict[filename_base] = dict_from_file
else:
fileopenfail += 1

View File

@ -24,6 +24,7 @@ from .Users import *
from .AI import *
from .Google import *
from .Gif import *
from .Sherlock import *
from .configure import *

View File

@ -0,0 +1,5 @@
{
"url": "https://500px.com/{}",
"errorType": "message",
"errorMsg": "Sorry, no such page."
}

View File

@ -0,0 +1,4 @@
{
"url": "https://about.me/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://angel.co/{}",
"errorType": "message",
"errorMsg": "We couldn't find what you were looking for."
}

View File

@ -0,0 +1,5 @@
{
"url": "https://blip.fm/{}",
"errorType": "message",
"errorMsg": "Page Not Found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.bandcamp.com/{}",
"errorType": "message",
"errorMsg": "Sorry, that something isn’t here"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.behance.net/{}",
"errorType": "message",
"errorMsg": "Oops! We can’t find that page."
}

View File

@ -0,0 +1,4 @@
{
"url": "https://bitbucket.org/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://{}.blogspot.com",
"errorType": "status_code",
"noPeriod": "True"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://buzzfeed.com/{}",
"errorType": "message",
"errorMsg": "We can't find the page you're looking for."
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.canva.com/{}",
"errorType": "message",
"errorMsg": "Not found (404)"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://cash.me/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.codecademy.com/{}",
"errorType": "message",
"errorMsg": "404 error"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.codementor.io/{}",
"errorType": "message",
"errorMsg": "404"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.colourlovers.com/love/{}",
"errorType": "message",
"errorMsg": "Page Not Loved"
}

View File

@ -0,0 +1,6 @@
{
"url": "https://{}.contently.com/",
"errorType": "message",
"errorMsg": "We can't find that page!",
"noPeriod": "True"
}

View File

@ -0,0 +1,6 @@
{
"url": "https://www.dailymotion.com/{}",
"errorType": "message",
"errorMsg": "Page not found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.designspiration.net/{}",
"errorType": "message",
"errorMsg": "Content Not Found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://{}.deviantart.com",
"errorType": "status_code",
"noPeriod": "True"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://disqus.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,6 @@
{
"url": "https://dribbble.com/{}",
"errorType": "message",
"errorMsg": "Whoops, that page is gone.",
"noPeriod": "True"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.ebay.com/usr/{}",
"errorType": "message",
"errorMsg": "The User ID you entered was not found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://ello.co/{}",
"errorType": "message",
"errorMsg": "We couldn't find the page you're looking for"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://www.etsy.com/shop/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://www.facebook.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://www.flickr.com/people/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://flipboard.com/@{}",
"errorType": "message",
"errorMsg": "loading"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://fotolog.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://foursquare.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.github.com/{}",
"errorType": "status_code",
"noPeriod": "True"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://www.goodreads.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://plus.google.com/+{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "http://en.gravatar.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.gumroad.com/{}",
"errorType": "message",
"errorMsg": "Page not found."
}

View File

@ -0,0 +1,5 @@
{
"url": "https://news.ycombinator.com/user?id={}",
"errorType": "message",
"errorMsg": "No such user."
}

View File

@ -0,0 +1,5 @@
{
"url": "https://hackerone.com/{}",
"errorType": "message",
"errorMsg": "Page not found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://houzz.com/user/{}",
"errorType": "message",
"errorMsg": "The page you requested was not found."
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.ifttt.com/p/{}",
"errorType": "message",
"errorMsg": "The requested page or file does not exist"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://imgur.com/user/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.instagram.com/{}",
"errorType": "message",
"errorMsg": "The link you followed may be broken"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.instructables.com/member/{}",
"errorType": "message",
"errorMsg": "404: We're sorry, things break sometimes"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://keybase.io/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,6 @@
{
"url": "https://www.kongregate.com/accounts/{}",
"errorType": "message",
"errorMsg": "Sorry, no account with that name was found.",
"noPeriod": "True"
}

View File

@ -0,0 +1,6 @@
{
"url": "https://{}.livejournal.com",
"errorType": "message",
"errorMsg": "Unknown Journal",
"noPeriod": "True"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://medium.com/@{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.mixcloud.com/{}",
"errorType": "message",
"errorMsg": "Page Not Found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://{}.newgrounds.com",
"errorType": "status_code",
"noPeriod": "True"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://pastebin.com/u/{}",
"errorType": "response_url",
"errorUrl": "https://pastebin.com/index"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://www.patreon.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.pexels.com/@{}",
"errorType": "message",
"errorMsg": "Ouch, something went wrong!"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.pinterest.com/{}",
"errorType": "response_url",
"errorUrl": "https://www.pinterest.com/?show_error=true"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.reddit.com/user/{}",
"errorType": "message",
"errorMsg": "page not found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.reverbnation.com/{}",
"errorType": "message",
"errorMsg": "Sorry, we couldn't find that page"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.roblox.com/user.aspx?username={}",
"errorType": "message",
"errorMsg": "Page cannot be found or no longer exists"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.scribd.com/{}",
"errorType": "message",
"errorMsg": "Page not found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://{}.slack.com",
"errorType": "status_code",
"noPeriod": "True"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://slideshare.net/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://soundcloud.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://open.spotify.com/user/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://steamcommunity.com/id/{}",
"errorType": "message",
"errorMsg": "The specified profile could not be found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.gotinder.com/@{}",
"errorType": "message",
"errorMsg": "Looking for Someone?"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.trakt.tv/users/{}",
"errorType": "message",
"errorMsg": "404"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.trip.skyscanner.com/user/{}",
"errorType": "message",
"errorMsg": "Page not found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://tripadvisor.com/members/{}",
"errorType": "message",
"errorMsg": "This page is on vacation…"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.twitter.com/{}",
"errorType": "message",
"errorMsg": "page doesn’t exist"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://unsplash.com/@{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://vk.com/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,4 @@
{
"url": "https://vsco.co/{}",
"errorType": "status_code"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://vimeo.com/{}",
"errorType": "message",
"errorMsg": "404 Not Found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.wattpad.com/user/{}",
"errorType": "message",
"errorMsg": "This page seems to be missing..."
}

View File

@ -0,0 +1,5 @@
{
"url": "https://weheartit.com/{}",
"errorType": "message",
"errorMsg": "Oops! You've landed on a moving target!"
}

View File

@ -0,0 +1,6 @@
{
"url": "https://{}.wordpress.com",
"errorType": "response_url",
"errorUrl": "wordpress.com/typo/?subdomain=",
"noPeriod": "True"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://www.youtube.com/{}",
"errorType": "message",
"errorMsg": "Not Found"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://devrant.com/users/{}",
"errorType": "response_url",
"errorUrl": "https://devrant.com/"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://imgsrc.ru/main/user.php?user={}",
"errorType": "response_url",
"errorUrl": "https://imgsrc.ru/"
}

View File

@ -0,0 +1,5 @@
{
"url": "https://last.fm/user/{}",
"errorType": "message",
"errorMsg": "Whoops! Sorry, but this page doesn't exist."
}

View File

@ -0,0 +1,49 @@
# 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):
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.inlist(username, netlist):
checklistname = SpiceBot.inlist_match(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:
in_social = SpiceBot.sherlock.check_network(username, social_network)
if in_social:
inlist.append(social_network)
else:
notinlist.append(social_network)
if len(inlist):
if checklistname != 'all':
bot.osd(["The username " + username + " is in " + checklist[0], SpiceBot.sherlock.dict.get(social_network).get("url").format(username)])
else:
bot.osd(["The username " + username + " is in the following:", spicemanip.main(inlist, "andlist")], trigger.nick, 'NOTICE')
if len(notinlist):
if checklistname != 'all':
bot.osd(["The username " + username + " is NOT in the following:", spicemanip.main(notinlist, "andlist")])
else:
bot.osd(["The username " + username + " is NOT in the following:", spicemanip.main(notinlist, "andlist")], trigger.nick, 'NOTICE')

View File

@ -19,6 +19,7 @@ from .BotPrivs import *
from .Search import *
from .AI import *
from .Gif import *
from .Sherlock import *
__author__ = 'Sam Zick'
__email__ = 'sam@deathbybandaid.net'