Skip to content

Commit

Permalink
dig.py: Retire dig command
Browse files Browse the repository at this point in the history
The jsondns API no longer exists
  • Loading branch information
linuxdaemon committed Dec 22, 2019
1 parent 507073e commit cdab11c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix listfacts not listing some facts
### Removed
- Removed rottentomatoes plugin as the API has been removed
- Removed dig plugin as jsondns is gone

## [1.2.0] 2019-11-27
- Many undocumented changes
Expand Down
38 changes: 3 additions & 35 deletions plugins/dig.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
import requests

from cloudbot import hook


@hook.command
def dig(text, nick, notice):
"""<domain> <recordtype> - returns a list of records for the specified domain valid record types are A, NS, TXT,
and MX. If a record type is not chosen A will be the default."""
args = text.split()
domain = args.pop(0)

if args:
rtype = args.pop(0).upper()
else:
rtype = "A"

if rtype not in ("A", "NS", "MX", "TXT"):
rtype = "A"

url = "http://dig.jsondns.org/IN/{}/{}".format(domain, rtype)
r = requests.get(url)
r.raise_for_status()
results = r.json()
if results['header']['rcode'] == "NXDOMAIN":
return "no dns record for {} was found".format(domain)
notice("The following records were found for \x02{}\x02: ".format(domain), nick)
for r in range(len(results['answer'])):
domain = results['answer'][r]['name']
rtype = results['answer'][r]['type']
ttl = results['answer'][r]['ttl']
if rtype == "MX":
rdata = results['answer'][r]['rdata'][1]
elif rtype == "TXT":
rdata = results['answer'][r]['rdata'][0]
else:
rdata = results['answer'][r]['rdata']
notice("name: \x02{}\x02 type: \x02{}\x02 ttl: \x02{}\x02 rdata: \x02{}\x02".format(
domain, rtype, ttl, rdata), nick)
def dig():
"""- This command is retired"""
return "The jsondns API no longer exists. This command is retired."
4 changes: 4 additions & 0 deletions tests/plugin_tests/test_dig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_dig():
from plugins import dig
s = "The jsondns API no longer exists. This command is retired."
assert dig.dig() == s

0 comments on commit cdab11c

Please sign in to comment.