diff --git a/utils/user_info.py b/utils/user_info.py new file mode 100755 index 0000000..20068e5 --- /dev/null +++ b/utils/user_info.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import requests + +def location(character): + """ + Return a tuple of physical location information about + the player playing `character`. + """ + session = character.sessions.get()[0] + address = session.address + if address == "127.0.0.1": + return ("Localhost", None, None, address) + + response = requests.get(f'https://ipapi.co/{address}/json/', + timeout=1).json() + city = response.get("city") or "Unknown City" + region = response.get("region") or "Unknown Region" + country = response.get("country_name") or "Unknown Country" + return (city, region, country, address)