Skip to content

Commit 918539f

Browse files
committed
Tidy up whois, add docstring
1 parent 1812d5c commit 918539f

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

plugins/whois.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
from contextlib import suppress
1+
"""
2+
whois.py
3+
Provides a command to allow users to look up information on domain names.
4+
"""
25

36
import pythonwhois
7+
from contextlib import suppress
48

59
from cloudbot import hook
610

@@ -10,9 +14,13 @@ def whois(text):
1014
"""<domain> -- Does a whois query on <domain>."""
1115
domain = text.strip().lower()
1216

13-
data = pythonwhois.get_whois(domain, normalized=True)
17+
try:
18+
data = pythonwhois.get_whois(domain, normalized=True)
19+
except pythonwhois.shared.WhoisException:
20+
return "Invalid input."
1421
info = []
1522

23+
# We suppress errors here because different domains provide different data fields
1624
with suppress(KeyError):
1725
info.append("\x02Registrar\x02: {}".format(data["registrar"][0]))
1826

0 commit comments

Comments
 (0)