Fixed !help not processing certain help sections correctly if example details were missing.
parent
5730840209
commit
87d05d961a
6
bots.py
6
bots.py
|
@ -35,7 +35,7 @@ except json.JSONDecodeError as e:
|
||||||
# Simple Logging System
|
# Simple Logging System
|
||||||
###############################
|
###############################
|
||||||
|
|
||||||
def log(message, level="INFO"):
|
def log(message, level="INFO", exec_info=False):
|
||||||
"""
|
"""
|
||||||
A simple logging function with adjustable log levels.
|
A simple logging function with adjustable log levels.
|
||||||
Logs messages in a structured format.
|
Logs messages in a structured format.
|
||||||
|
@ -56,6 +56,10 @@ def log(message, level="INFO"):
|
||||||
timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
|
timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
log_message = f"[{timestamp} - {uptime_str}] [{level}] {message}"
|
log_message = f"[{timestamp} - {uptime_str}] [{level}] {message}"
|
||||||
|
|
||||||
|
# If traceback is requested (e.g., for errors)
|
||||||
|
if exec_info or level == "CRITICAL" or level == "FATAL":
|
||||||
|
log_message += f"\n{traceback.format_exc()}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(log_message) # Print to terminal
|
print(log_message) # Print to terminal
|
||||||
if level == "FATAL":
|
if level == "FATAL":
|
||||||
|
|
|
@ -10,6 +10,7 @@ def setup(bot, db_conn=None, log=None):
|
||||||
"""
|
"""
|
||||||
Attach commands to the Discord bot, store references to db/log.
|
Attach commands to the Discord bot, store references to db/log.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@bot.command(name="greet")
|
@bot.command(name="greet")
|
||||||
@monitor_cmds(bot.log)
|
@monitor_cmds(bot.log)
|
||||||
async def cmd_greet(ctx):
|
async def cmd_greet(ctx):
|
||||||
|
|
|
@ -383,9 +383,13 @@ def build_discord_help_message(cmd_name, cmd_help_dict):
|
||||||
if examples:
|
if examples:
|
||||||
lines.append("\nExample usage:")
|
lines.append("\nExample usage:")
|
||||||
for ex in examples:
|
for ex in examples:
|
||||||
ex_cmd = ex.split(" : ")[0]
|
ex_arr = ex.split(" : ", 1) # Split into max 2 parts
|
||||||
ex_note = ex.split(" : ")[1]
|
|
||||||
lines.append(f"- `{ex_cmd}`\n {ex_note}")
|
# Handle missing description case
|
||||||
|
ex_cmd = ex_arr[0]
|
||||||
|
ex_note = str(f"\n {ex_arr[1]}") if len(ex_arr) > 1 else ""
|
||||||
|
|
||||||
|
lines.append(f"- `{ex_cmd}`{ex_note}")
|
||||||
|
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue