Add domainhack plugin
This commit is contained in:
parent
a416d0c3e4
commit
0c85029b80
|
@ -0,0 +1,37 @@
|
|||
import plugin, requests, dictdata
|
||||
import os.path as fs
|
||||
|
||||
domain_blacklist = dictdata.DictData("dh_blacklist.json")
|
||||
#domain_blacklist = dict(blacklist=domain_blacklist)
|
||||
|
||||
if not fs.exists("tlds.txt"):
|
||||
r = requests.get("http://data.iana.org/TLD/tlds-alpha-by-domain.txt")
|
||||
r.raise_for_status()
|
||||
with open("tlds.txt","w") as f: f.write(r.text)
|
||||
with open("tlds.txt") as f: tlds = [l.lower().strip() for l in f if l.strip() and not l.startswith("#")]
|
||||
|
||||
def get_domainhacks(*args):
|
||||
word = "-".join(args).lower()
|
||||
possible_hacks = []
|
||||
for tld in tlds:
|
||||
if tld in domain_blacklist["blacklist"]: continue
|
||||
if not (tld in word): continue
|
||||
index = word.rfind(tld)
|
||||
prefix = word[:index].rstrip("-")
|
||||
suffix = word[index+len(tld):].lstrip("-")
|
||||
dh = dict()
|
||||
dh["prefix"]=prefix
|
||||
dh["tld"]=tld
|
||||
dh["suffix"]=suffix
|
||||
dh["full"]="{}.{}/{}".format(prefix,tld,suffix).rstrip("/")
|
||||
possible_hacks.append(dh)
|
||||
possible_hacks.sort(key=lambda x: len(x["suffix"]))
|
||||
return [x for x in possible_hacks if len(x["suffix"])==len(possible_hacks[0]["suffix"])]
|
||||
|
||||
@plugin.command("domainhack","<word> [word word...]")
|
||||
def domainhack_cmd(bot,channel,nick,*words):
|
||||
hacks = get_domainhacks(*words)
|
||||
if not hacks:
|
||||
bot.say(channel,nick+": Unfortunately, no domain hack for that exists (that I know of)!")
|
||||
return
|
||||
bot.say(channel,nick+": Domain hacks include "+", ".join([x["full"] for x in hacks]))
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue