added bitly.py and haveibeenpwned.py.
This commit is contained in:
parent
223333cff2
commit
16d1af9057
2 changed files with 56 additions and 0 deletions
30
modules/bitly.py
Normal file
30
modules/bitly.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import re
|
||||
import Utils
|
||||
|
||||
URL_BITLYSHORTEN = "https://api-ssl.bitly.com/v3/shorten"
|
||||
REGEX_URL = re.compile("https?://", re.I)
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
bot.events.on("get").on("shortlink").hook(self.shortlink)
|
||||
bot.events.on("received").on("command").on("shorten"
|
||||
).hook(self.shorten, min_args=1)
|
||||
|
||||
def shortlink(self, event):
|
||||
url = event["url"]
|
||||
if not re.match(REGEX_URL, url):
|
||||
url = "http://%s" % url
|
||||
data = Utils.get_url(URL_BITLYSHORTEN, get_params={
|
||||
"access_token": self.bot.config["bitly-api-key"],
|
||||
"longUrl": url}, json=True)
|
||||
if data and data["data"]:
|
||||
return data["data"]["url"]
|
||||
|
||||
def shorten(self, event):
|
||||
link = self.bot.events.on("get").on("shortlink").call(
|
||||
url=event["args"])[0]
|
||||
if link:
|
||||
event["stdout"].write("Short URL: %s" % link)
|
||||
else:
|
||||
event["stderr"].write("Unable to shorten that URL.")
|
26
modules/haveibeenpwned.py
Normal file
26
modules/haveibeenpwned.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import Utils
|
||||
|
||||
URL_HAVEIBEENPWNEDAPI = "https://haveibeenpwned.com/api/v2/breachedaccount/%s"
|
||||
URL_HAVEIBEENPWNED = "https://haveibeenpwned.com/"
|
||||
|
||||
class Module(object):
|
||||
def __init__(self, bot):
|
||||
bot.events.on("received").on("command").on("beenpwned").hook(
|
||||
self.beenpwned, min_args=1,
|
||||
help="Find out if a username, email or similar has appeared "
|
||||
"in any hacked databased")
|
||||
|
||||
def beenpwned(self, event):
|
||||
page = Utils.get_url(URL_HAVEIBEENPWNEDAPI % event["args"], json=True,
|
||||
code=True)
|
||||
if page:
|
||||
code, page = page
|
||||
if code == 200:
|
||||
event["stdout"].write(
|
||||
"It seems '%s' has been pwned. check on %s." % (event["args"],
|
||||
URL_HAVEIBEENPWNED))
|
||||
else:
|
||||
event["stdout"].write("It seems '%s' has not been pwned" % (
|
||||
event["args"]))
|
||||
else:
|
||||
event["stderr"].write("Failed to load results")
|
Loading…
Reference in a new issue