Skip to content

Commit 3550387

Browse files
authored
Merge branch 'gonzobot' into gonzobot+format-fixes
2 parents 78f65c4 + 9bfdbca commit 3550387

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

plugins/whois.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
Provides a command to allow users to look up information on domain names.
44
"""
55

6+
import sys
67
from contextlib import suppress
78

89
import pythonwhois
910

1011
from cloudbot import hook
1112

13+
if sys.version_info < (3, 7, 0):
14+
import pythonwhois
15+
else:
16+
pythonwhois = None
17+
1218

1319
@hook.command
1420
def whois(text, reply):
15-
"""<domain> -- Does a whois query on <domain>."""
21+
"""<domain> - Does a whois query on <domain>."""
22+
if pythonwhois is None:
23+
return "The pythonwhois library does not work on this version of Python."
24+
1625
domain = text.strip().lower()
1726

1827
try:
@@ -25,13 +34,16 @@ def whois(text, reply):
2534

2635
# We suppress errors here because different domains provide different data fields
2736
with suppress(KeyError):
28-
info.append("\x02Registrar\x02: {}".format(data["registrar"][0]))
37+
info.append(("Registrar", data["registrar"][0]))
2938

3039
with suppress(KeyError):
31-
info.append("\x02Registered\x02: {}".format(data["creation_date"][0].strftime("%d-%m-%Y")))
40+
info.append(("Registered", data["creation_date"][0].strftime("%d-%m-%Y")))
3241

3342
with suppress(KeyError):
34-
info.append("\x02Expires\x02: {}".format(data["expiration_date"][0].strftime("%d-%m-%Y")))
43+
info.append(("Expires", data["expiration_date"][0].strftime("%d-%m-%Y")))
44+
45+
if not info:
46+
return "No information returned."
3547

36-
info_text = ", ".join(info)
48+
info_text = ", ".join("\x02{name}\x02: {info}".format(name=name, info=i) for name, i in info)
3749
return "{} - {}".format(domain, info_text)

0 commit comments

Comments
 (0)