This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/geoip.py

21 lines
620 B
Python
Raw Normal View History

from util import hook
import os.path
import pygeoip
2011-11-20 10:23:31 +01:00
# initalise geolocation database
geo = pygeoip.GeoIP(os.path.abspath("./plugins/data/geoip.dat"))
2011-11-20 10:23:31 +01:00
2012-02-29 09:29:53 +01:00
2011-11-20 10:23:31 +01:00
@hook.command
def geoip(inp):
"geoip <host/ip> -- Gets the location of <host/ip>"
try:
record = geo.record_by_name(inp)
except:
return "Sorry, I can't locate that in my database."
2012-05-07 01:58:29 +02:00
record["_cc"] = record["country_code"] or "N/A"
record["_country"] = record["country_name"] or "Unknown"
record["_city"] = record["metro_code"] or record["city"] or "Unknown"
return "Country: %(_country)s (%(_cc)s), City: %(_city)s" % record