####################################################
# by wiebe @ QuakeNet
#
# http://www.iana.org/cctld/cctld-whois.htm
# http://www.iana.org/gtld/gtld.htm
####################################################


####################################################
# tld:help:pubm
####################################################
bind pubm fvlomn|fvlomn "% ${botnet-nick} help tld" tld:help:pubm
proc tld:help:pubm { n u h c t } {
  if {[matchattr $h bkZ]} { return 0 }
  lappend o "tld: usage tld <TLD>|<country>"
  lappend o "tld: shows country and TLD for the given input, wildcards are supported"
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "tld: " } }
  putloglev c $c "help: $n $u $h $c tld"
  return 1
}


####################################################
# tld:help:msg
####################################################
bind msgm fvlomn|fvlomn "help tld" tld:help:msgm
proc tld:help:msgm { n u h t } {
  if {[matchattr $h bkZ]} { return 0 }
  lappend o "tld: usage tld <TLD>|<country>"
  lappend o "tld: shows country and TLD for the given input, wildcards are supported"
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "tld: " } }
  putcmdlog "($n!$u) !$h! help tld"
  return 1
}


####################################################
# tld:pubm
####################################################
bind pubm fvlomn|fvlomn "% ${botnet-nick} tld" tld:pubm
bind pubm fvlomn|fvlomn "% ${botnet-nick} tld *" tld:pubm
proc tld:pubm { n u h c t } {
  if {[matchattr $h bkZ]} { return 0 }
  set t [join [lrange [split $t] 2 end]]
  if {[string equal $t ""]} {
    lappend o "tld: usage tld <TLD>|<country>"
  } else {
    set o [tld:tld $t]; set m [lindex [split [getchanmode $c]] 0]
    if {![string match *m* $m] || [botisop $c] || [botishalfop $c] || [botisvoice $c]} {
      if {[string match *c* $m] } { set o [stripcodes bcru $o] }
      if {[string equal [info procs privmsg] ""]} { foreach l $o { puthelp "PRIVMSG $c :$l" }
      } else { foreach l $o { privmsg $c $l puthelp "tld: " } }
      set o ""
    }
  }
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "tld: " } }
  putloglev c $c "tld: $n $u $h $c $t"
  return 1
}


####################################################
# tld:msg
####################################################
bind msg fvlomn|fvlomn tld tld:msg
proc tld:msg { n u h t } {
  if {[matchattr $h bkZ]} { return 0 }
  if {[string equal $t ""]} { lappend o "tld: usage tld <TLD>|<country>"
  } else { set o [tld:tld $t] }
  if {[string equal [info procs cnotice] ""]} { foreach l $o { puthelp "NOTICE $n :$l" }
  } else { foreach l $o { cnotice $n $l puthelp "tld: " } }
  return 1
}


####################################################
# tld:dcc
####################################################
bind dcc -|- tld tld:dcc
proc tld:dcc { h i t } {
  if {[string equal $t ""]} {
    lappend o "tld: usage tld <TLD>|<country>"
    lappend o "tld: shows country and TLD for the given input, wildcards are supported"
  } else { set o [tld:tld $t] }
  foreach l $o { putidx $i $l }
  return 1
}


####################################################
# tld:tld
####################################################
proc tld:tld { t } {
  set c(.ac) "Ascension Island"; set c(.ad) "Andorra"; set c(.ae) "United Arab Emirates"
  set c(.af) "Afghanistan"; set c(.ag) "Antigua and Barbuda"; set c(.ai) "Anguilla"
  set c(.al) "Albania"; set c(.am) "Armenia"; set c(.an) "Netherlands Antilles"
  set c(.ao) "Angola"; set c(.aq) "Antarctica"; set c(.ar) "Argentina"
  set c(.as) "American Samoa"; set c(.at) "Austria"; set c(.au) "Australia"
  set c(.aw) "Aruba"; set c(.az) "Azerbaijan"; set c(.ax) "Aland Islands"
  set c(.ba) "Bosnia and Herzegovina"; set c(.bb) "Barbados"; set c(.bd) "Bangladesh"
  set c(.be) "Belgium"; set c(.bf) "Burkina Faso"; set c(.bg) "Bulgaria"
  set c(.bh) "Bahrain"; set c(.bi) "Burundi"; set c(.bj) "Benin"
  set c(.bm) "Bermuda"; set c(.bn) "Brunei Darussalam"; set c(.bo) "Bolivia"
  set c(.br) "Brazil"; set c(.bs) "Bahamas"; set c(.bt) "Bhutan"
  set c(.bv) "Bouvet Island"; set c(.bw) "Botswana"; set c(.by) "Belarus"
  set c(.bz) "Belize"; set c(.ca) "Canada"; set c(.cc) "Cocos (Keeling) Islands"
  set c(.cd) "Congo, The Democratic Republic of the"; set c(.cf) "Central African Republic"
  set c(.cg) "Congo, Republic of"; set c(.ch) "Switzerland"; set c(.ci) "Cote d'Ivoire"
  set c(.ck) "Cook Islands"; set c(.cl) "Chile"; set c(.cm) "Cameroon"
  set c(.cn) "China"; set c(.co) "Colombia"; set c(.cr) "Costa Rica"
  set c(.cs) "Serbia and Montenegro"; set c(.cu) "Cuba"; set c(.cv) "Cape Verde"
  set c(.cx) "Christmas Island"; set c(.cy) "Cyprus"; set c(.cz) "Czech Republic"
  set c(.de) "Germany"; set c(.dj) "Djibouti"; set c(.dk) "Denmark"
  set c(.dm) "Dominica"; set c(.do) "Dominican Republic"; set c(.dz) "Algeria"
  set c(.ec) "Ecuador"; set c(.ee) "Estonia"; set c(.eg) "Egypt"; set c(.eh) "Western Sahara"
  set c(.er) "Eritrea"; set c(.es) "Spain"; set c(.et) "Ethiopia"
  set c(.eu) "European Union"; set c(.fi) "Finland"; set c(.fj) "Fiji"
  set c(.fk) "Falkland Islands (Malvinas)"; set c(.fm) "Micronesia, Federal State of"
  set c(.fo) "Faroe Islands"; set c(.fr) "France"; set c(.ga) "Gabon"
  set c(.gb) "United Kingdom"; set c(.gd) "Grenada"; set c(.ge) "Georgia"
  set c(.gf) "French Guiana"; set c(.gg) "Guernsey"; set c(.gh) "Ghana"
  set c(.gi) "Gibraltar"; set c(.gl) "Greenland"; set c(.gm) "Gambia"
  set c(.gn) "Guinea"; set c(.gp) "Guadeloupe"; set c(.gq) "Equatorial Guinea"
  set c(.gr) "Greece"; set c(.gs) "South Georgia and the South Sandwich Islands"
  set c(.gt) "Guatemala"; set c(.gu) "Guam"; set c(.gw) "Guinea-Bissau"
  set c(.gy) "Guyana"; set c(.hk) "Hong Kong"; set c(.hm) "Heard and McDonald Islands"
  set c(.hn) "Honduras"; set c(.hr) "Croatia/Hrvatska"; set c(.ht) "Haiti"
  set c(.hu) "Hungary"; set c(.id) "Indonesia"; set c(.ie) "Ireland"
  set c(.il) "Israel"; set c(.im) "Isle of Man"; set c(.in) "India"
  set c(.io) "British Indian Ocean Territory"; set c(.iq) "Iraq"
  set c(.ir) "Iran, Islamic Republic of"; set c(.is) "Iceland";  set c(.it) "Italy"
  set c(.je) "Jersey"; set c(.jm) "Jamaica"; set c(.jo) "Jordan"
  set c(.jp) "Japan"; set c(.ke) "Kenya"; set c(.kg) "Kyrgyzstan"
  set c(.kh) "Cambodia"; set c(.ki) "Kiribati"; set c(.km) "Comoros"
  set c(.kn) "Saint Kitts and Nevis"; set c(.kp) "Korea, Democratic People's Republic"
  set c(.kr) "Korea, Republic of"; set c(.kw) "Kuwait"; set c(.ky) "Cayman Islands"
  set c(.kz) "Kazakhstan"; set c(.la) "Lao People's Democratic Republic"; set c(.lb) "Lebanon"
  set c(.lc) "Saint Lucia"; set c(.li) "Liechtenstein"; set c(.lk) "Sri Lanka"
  set c(.lr) "Liberia"; set c(.ls) "Lesotho"; set c(.lt) "Lithuania"
  set c(.lu) "Luxembourg"; set c(.lv) "Latvia"; set c(.ly) "Libyan Arab Jamahiriya"
  set c(.ma) "Morocco"; set c(.mc) "Monaco"; set c(.md) "Moldova, Republic of"
  set c(.mg) "Madagascar"; set c(.mh) "Marshall Islands"
  set c(.mk) "Macedonia, The Former Yugoslav Republic of"; set c(.ml) "Mali"
  set c(.mm) "Myanmar"; set c(.mn) "Mongolia"; set c(.mo) "Macau"
  set c(.mp) "Northern Mariana Islands"; set c(.mq) "Martinique"; set c(.mr) "Mauritania"
  set c(.ms) "Montserrat"; set c(.mt) "Malta"; set c(.mu) "Mauritius"
  set c(.mv) "Maldives"; set c(.mw) "Malawi"; set c(.mx) "Mexico"
  set c(.my) "Malaysia"; set c(.mz) "Mozambique"; set c(.na) "Namibia"
  set c(.nc) "New Caledonia"; set c(.ne) "Niger"; set c(.nf) "Norfolk Island"
  set c(.ng) "Nigeria"; set c(.ni) "Nicaragua"; set c(.nl) "Netherlands"
  set c(.no) "Norway"; set c(.np) "Nepal"; set c(.nr) "Nauru"
  set c(.nu) "Niue"; set c(.nz) "New Zealand"; set c(.om) "Oman"
  set c(.pa) "Panama"; set c(.pe) "Peru"; set c(.pf) "French Polynesia"
  set c(.pg) "Papua New Guinea"; set c(.ph) "Philippines"; set c(.pk) "Pakistan"
  set c(.pl) "Poland"; set c(.pm) "Saint Pierre and Miquelon"; set c(.pn) "Pitcairn Island"
  set c(.pr) "Puerto Rico"; set c(.ps) "Palestinian Territories"; set c(.pt) "Portugal"
  set c(.pw) "Palau"; set c(.py) "Paraguay"; set c(.qa) "Qatar"
  set c(.re) "Reunion Island"; set c(.ro) "Romania"; set c(.ru) "Russian Federation"
  set c(.rw) "Rwanda"; set c(.sa) "Saudi Arabia"; set c(.sb) "Solomon Islands"
  set c(.sc) "Seychelles"; set c(.sd) "Sudan"; set c(.se) "Sweden"
  set c(.sg) "Singapore"; set c(.sh) "Saint Helena"; set c(.si) "Slovenia"
  set c(.sj) "Svalbard and Jan Mayen Islands"; set c(.sk) "Slovak Republic"
  set c(.sl) "Sierra Leone"; set c(.sm) "San Marino"; set c(.sn) "Senegal"
  set c(.so) "Somalia"; set c(.sr) "Suriname"; set c(.st) "Sao Tome and Principe"
  set c(.sv) "El Salvador"; set c(.sy) "Syrian Arab Republic"; set c(.sz) "Swaziland"
  set c(.tc) "Turks and Caicos Islands"; set c(.td) "Chad"
  set c(.tf) "French Southern Territories"; set c(.tg) "Togo"
  set c(.th) "Thailand"; set c(.tj) "Tajikistan"; set c(.tk) "Tokelau"; set c(.tl) "Timor-Leste"
  set c(.tm) "Turkmenistan"; set c(.tn) "Tunisia"; set c(.to) "Tonga"
  set c(.tp) "East Timor"; set c(.tr) "Turkey"; set c(.tt) "Trinidad and Tobago"
  set c(.tv) "Tuvalu"; set c(.tw) "Taiwan"; set c(.tz) "Tanzania"
  set c(.ua) "Ukraine"; set c(.ug) "Uganda"; set c(.uk) "United Kingdom"
  set c(.um) "United States Minor Outlying Islands"; set c(.us) "United States"
  set c(.uy) "Uruguay"; set c(.uz) "Uzbekistan"; set c(.va) "Holy See (Vatican City State)"
  set c(.vc) "Saint Vincent and the Grenadines"; set c(.ve) "Venezuela"
  set c(.vg) "Virgin Islands, British"; set c(.vi) "Virgin Islands, U.S."
  set c(.vn) "Vietnam"; set c(.vu) "Vanuatu"; set c(.wf) "Wallis and Futuna Islands"
  set c(.ws) "Samoa"; set c(.ye) "Yemen"; set c(.yt) "Mayotte"; set c(.yu) "Yugoslavia"
  set c(.za) "South Africa"; set c(.zm) "Zambia"; set c(.zw) "Zimbabwe"

  set d(.aero) "The  .aero domain  is reserved for members of the air-transport industry and is sponsored by Société Internationale de Télécommunications Aéronautiques (SITA)."
  set d(.biz) "The .biz domain is restricted to businesses and is operated by NeuLevel, Inc."
  set d(.cat) "The .cat domain is reserved for the Catalan linguistic and cultural community and is sponsored by Fundació puntCat"
  set d(.com) "The .com domain is operated by VeriSign Global Registry Services."
  set d(.coop) "The .coop domain is reserved for cooperative associations and is sponsored by Dot Cooperation LLC."
  set d(.info) "The .info domain is operated by Afilias Limited."
  set d(.jobs) "The .jobs domain is reserved for human resource managers and is sponsored by Employ Media LLC."
  set d(.mobi) "The .mobi domain is reserved for consumers and providers of mobile products and services and is sponsored by mTLD Top Level Domain, Ltd."
  set d(.museum) "The .museum domain is reserved for museums and is sponsored by the Museum Domain Management Association."
  set d(.name) "The .name domain is reserved for individuals and is operated by Global Name Registry."
  set d(.net) "The .net domain is operated by VeriSign Global Registry Services."
  set d(.org) "The .org domain is operated by Public Interest Registry. It is intended to serve the noncommercial community, but all are eligible to register within .org."
  set d(.pro) "The .pro domain is restricted to credentialed professionals and related entities and is operated by RegistryPro."
  set d(.travel) "The .travel domain is reserved for entities whose primary area of activity is in the travel industry and is sponsored by Tralliance Corporation."
  set d(.gov) "The .gov domain is reserved exclusively for the United States Government. It is operated by the US General Services Administration."
  set d(.edu) "The .edu domain is reserved for postsecondary institutions accredited by an agency on the U.S. Department of Education's list of Nationally Recognized Accrediting Agencies and is registered only through Educause."
  set d(.mil) "The .mil domain is reserved exclusively for the United States Military. It is operated by the US DoD Network Information Center."
  set d(.int) "The .int domain is used only for registering organizations established by international treaties between governments. It is operated by the IANA .int Domain Registry"

  set x [string tolower $t]
  if {![string match ".*" $x]} { set x ".$x" }
  if {[info exists c($x)]} { lappend o "tld: $x = $c($x)"
  } elseif {[info exists d($x)]} { lappend o "tld: $x = $d($x)"
  } else {
    regsub -all {[][\\]} $t {\\\0} x; set r ""; set a 0
    foreach b [lsort -dictionary [array names c]] {
      if {![string match -nocase $x $b] && ![string match -nocase $x $c($b)]} { continue }
      lappend r "$b = $c($b)"; incr a 1
      if {$a > 20} { break }
    }
    foreach b [lsort -dictionary [array names d]] {
      if {$a > 0} { break }
      if {![string match -nocase $x $b] && ![string match -nocase $x $d($b)]} { continue }
      lappend r "$b = $d($b)"; break
    }
    if {![string equal $r ""]} { lappend o "tld: [join $r "     "]"
    } else { lappend o "tld: nothing found for $t" }
  }
  return $o
}


set scriptdb(tld) {
  "provides tld command showing info about top level domains (TLDs)"
}

