Forgot a drop of code.

This commit is contained in:
Howard Abrams 2025-08-18 17:15:42 -07:00
parent e2a43b8694
commit 9d9908ba68

20
utils/user_info.py Executable file
View file

@ -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)