OokamiPupV2/cmd_common/common_commands.py

49 lines
1.7 KiB
Python

# cmd_common/common_commands.py
import random
import time
from modules import utility
import globals
def generate_howl_message(username: str) -> str:
"""
Return a random howl message (0-100).
- If 0%: a fail message.
- If 100%: a perfect success.
- Otherwise: normal message with the random %.
"""
howl_percentage = random.randint(0, 100)
if howl_percentage == 0:
return f"Uh oh, {username} failed with a miserable 0% howl ..."
elif howl_percentage == 100:
return f"Wow, {username} performed a perfect 100% howl!"
else:
return f"{username} howled at {howl_percentage}%!"
def ping() -> str:
"""
Returns a dynamic, randomized uptime response.
"""
# Use function to retrieve correct startup time and calculate uptime
elapsed = time.time() - globals.get_bot_start_time()
uptime_str, uptime_s = utility.format_uptime(elapsed)
# Define threshold categories
thresholds = [3600, 10800, 21600, 43200, 86400, 172800, 259200, 345600,
432000, 518400, 604800, 1209600, 2592000, 7776000, 15552000, 23328000, 31536000]
# Find the highest matching threshold
selected_threshold = max([t for t in thresholds if uptime_s >= t], default=3600)
# Get a random response from the dictionary
response = utility.get_random_reply("ping_replies", str(selected_threshold), uptime_str=uptime_str)
return response
def greet(target_display_name: str, platform_name: str) -> str:
"""
Returns a greeting string for the given user displayname on a given platform.
"""
return f"Hello {target_display_name}, welcome to {platform_name}!"