Send login notification with location information

This commit is contained in:
Howard Abrams 2025-08-15 21:41:57 -07:00
parent 262121d236
commit a73faf0161

View file

@ -11,13 +11,16 @@ creation commands.
from datetime import datetime, timedelta from datetime import datetime, timedelta
from re import match, compile, sub from re import match, compile, sub
import requests
from evennia.commands.command import InterruptCommand from evennia.commands.command import InterruptCommand
from evennia.contrib.game_systems.gendersub import GenderCharacter from evennia.contrib.game_systems.gendersub import GenderCharacter
from evennia.contrib.rpg.rpsystem import ContribRPCharacter, send_emote from evennia.contrib.rpg.rpsystem import ContribRPCharacter, send_emote
from evennia.prototypes.spawner import spawn from evennia.prototypes.spawner import spawn
from evennia.utils import delay, logger, int2str from evennia.utils import delay, logger, int2str
from evennia.utils.search import (search_object, search_account, from evennia.utils.search import (search_object, search_account,
search_objects_by_typeclass) search_objects_by_typeclass,
search_channel)
from utils.word_list import routput, choices, fix_msg from utils.word_list import routput, choices, fix_msg
from typeclasses.objects import Object, ObjectParent from typeclasses.objects import Object, ObjectParent
@ -130,9 +133,9 @@ class Character(Object, GenderCharacter, ContribRPCharacter):
self.db.thrown_times = 0 self.db.thrown_times = 0
self.db.knocker_conversation_state = None self.db.knocker_conversation_state = None
self.ndb.cozy_house_number_of_bookshelves = 0 self.ndb.cozy_house_number_of_bookshelves = 0
self.db.received_pipe=False self.db.received_pipe = False
self.ndb.assortment_of_jars_view_index=0 self.ndb.assortment_of_jars_view_index = 0
self.ndb.shelf_full_of_jars_view_index=0 self.ndb.shelf_full_of_jars_view_index = 0
self.db.wee_beastie_friendly_level = 0 self.db.wee_beastie_friendly_level = 0
self.db.big_hairy_beast_friendly_level = 0 self.db.big_hairy_beast_friendly_level = 0
@ -150,6 +153,21 @@ class Character(Object, GenderCharacter, ContribRPCharacter):
self.delete_inv("typeclasses.drinkables.Cocktail") self.delete_inv("typeclasses.drinkables.Cocktail")
self.move_to(search_object("mp05").first(), quiet=True, use_destination=True) self.move_to(search_object("mp05").first(), quiet=True, use_destination=True)
def location_info(self):
"""
Return string containing location information from IP address.
"""
ip_address = self.account.sessions.get()[0].address
if ip_address == "127.0.0.1":
return "(from localhost)"
response = requests.get(f'https://ipapi.co/{ip_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 f"(from {city}, {region}, {country})"
def at_post_puppet(self, **kwargs): def at_post_puppet(self, **kwargs):
""" """
Setup the character based for _this world_. Setup the character based for _this world_.
@ -157,6 +175,25 @@ class Character(Object, GenderCharacter, ContribRPCharacter):
New accounts, guest accounts, and those that woke up New accounts, guest accounts, and those that woke up
with a hangover in the bar, need consideration. with a hangover in the bar, need consideration.
""" """
account = self.account
player = account.key
if player not in ("rob", "george", "darol", "rick", "howard"):
# Does everyone need to know about people logging in?
# pub = search_channel("Public").first()
# if pub:
# pub.msg(msg)
name = self.name
desc = self.db._sdesc
where = self.location_info()
msg = f"{name}, the {desc}, played by `{player}`, connected {where}."
logger.info(msg)
# Send an notification about the login:
requests.post("https://ntfy.sh/moss-n-puddles-user-login", timeout=2,
data=msg.encode(encoding='utf-8'))
if self.db.guest_account: if self.db.guest_account:
self.guest_account_setup() self.guest_account_setup()
elif not self.db.visited: elif not self.db.visited: