47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
# cmd_common/common_commands.py
|
|
import random
|
|
import time
|
|
from modules import utility
|
|
import globals
|
|
|
|
def howl(username: str) -> str:
|
|
"""
|
|
Generates a howl response based on a random percentage.
|
|
Uses a dictionary to allow flexible, randomized responses.
|
|
"""
|
|
howl_percentage = random.randint(0, 100)
|
|
|
|
# Round percentage down to nearest 10 (except 0 and 100)
|
|
rounded_percentage = 0 if howl_percentage == 0 else 100 if howl_percentage == 100 else (howl_percentage // 10) * 10
|
|
|
|
# Fetch a random response from the dictionary
|
|
response = utility.get_random_reply("howl_replies", str(rounded_percentage), username=username, howl_percentage=howl_percentage)
|
|
|
|
return response
|
|
|
|
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}!" |