Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
76 lines (67 loc) · 2.28 KB
/
Copy pathutils.py
File metadata and controls
76 lines (67 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import discord
from discord.ext import commands
import config
import functools
import inspect
# Command permission decorators
def owner_only():
"""Decorator that restricts command usage to the bot owner only."""
async def predicate(ctx):
return ctx.author.id == config.OWNER_ID
return commands.check(predicate)
def mod_only():
"""Decorator that restricts command usage to server moderators or bot owner."""
async def predicate(ctx):
if ctx.author.id == config.OWNER_ID:
return True
if not ctx.guild:
return False
return any(role.id in config.MOD_ROLES for role in ctx.author.roles)
return commands.check(predicate)
# Help formatting utilities
class HelpInfo:
"""Class to store and manage command help information."""
_commands = {
"owner": [],
"mod": [],
"general": []
}
@classmethod
def add_command(cls, category, name, description, usage=None):
"""Register a command's help information."""
cls._commands[category].append({
"name": name,
"description": description,
"usage": usage
})
@classmethod
def get_all_commands(cls):
"""Get all registered commands organized by category."""
return cls._commands
@classmethod
def get_command_by_name(cls, name):
"""Find a command by its name."""
for category, cmds in cls._commands.items():
for cmd in cmds:
if cmd["name"] == name:
return cmd, category
return None, None
def command_help(category, description, usage=None):
"""Decorator to add help documentation to a command."""
def decorator(func):
cmd_name = func.__name__
HelpInfo.add_command(category, cmd_name, description, usage)
@functools.wraps(func)
async def wrapper(*args, **kwargs):
return await func(*args, **kwargs)
return wrapper
return decorator
# Helper functions for creating embeds
def create_embed(title, description=None, color=config.EMBED_COLOR):
"""Create a consistent Discord embed with the bot's styling."""
embed = discord.Embed(
title=title,
description=description,
color=color
)
return embed