33Provides a command to allow users to look up information on domain names.
44"""
55
6+ import sys
67from contextlib import suppress
78
89import pythonwhois
910
1011from 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
1420def 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 (" \x02 Registrar \x02 : {}" . format ( data ["registrar" ][0 ]))
37+ info .append (( "Registrar" , data ["registrar" ][0 ]))
2938
3039 with suppress (KeyError ):
31- info .append (" \x02 Registered \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 ("\x02 Expires\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