Added whois action

This commit is contained in:
aewens 2018-09-13 21:45:00 -04:00
parent 626c0c4883
commit e7424f690b
3 changed files with 35 additions and 0 deletions

View File

@ -3,6 +3,7 @@ from actions.summon import summon
from actions.access import banish, pardon
from actions.control import puppet, nomad
from actions.stupid import hmm, hmmscore, hmmscoreboard
from actions.web import whois
actions = [
{
@ -54,5 +55,10 @@ actions = [
"type": "response",
"pattern": "!hmmscoreboard",
"callback": hmmscoreboard
},
{
"type": "response",
"pattern": ";;!whois \S+",
"callback": whois
}
]

View File

29
actions/web.py Normal file
View File

@ -0,0 +1,29 @@
from urllib.request import Request, urlopen
from urllib.error import HTTPError
from json import loads
def whois(self, name, source, response):
botnick = self.bot.botnick
domain = response.split("!whois ")[1]
api_url = "https://api.jsonwhoisapi.com/v1/whois"
api_key = self.bot.settings.get("extras", dict()).get("jsonwhoisapi", "")
req = Request("{}?identifier={}".format(api_url, domain))
req.add_header("Authorization", api_key)
try:
data = loads(urlopen(req).read())
except HTTPError:
self.bot.send_message(source, "{} cannot exist".format(domain))
return
registered = data.get("registered", None)
if registered is not None:
nameservers = len(data.get("nameservers", ""))
registrar = data.get("registrar", dict())
is_registered = "id" in registrar or nameservers > 0
status = "registered" if is_registered else "available"
self.bot.send_message(source, "{} is '{}'".format(domain, status))
else:
self.bot.send_message(source, "{} might be available".format(domain))