moss-n-puddles/utils/user_info.py
2025-08-18 17:15:42 -07:00

21 lines
654 B
Python
Executable file

#!/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)