REF: Made sure everything conforms to Flake8's standards
FIX: Fixed the Permission issues with logger FEAT: Changed how the XP system works. Now does a scaling curve with xp being 1-5
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
# modules/admin/logger_module.py
|
||||
import discord
|
||||
import logging
|
||||
import logging.config
|
||||
|
||||
import discord
|
||||
from discord import app_commands
|
||||
|
||||
from .logging_config import logging_config
|
||||
|
||||
|
||||
@ -10,20 +13,52 @@ class LoggerModule:
|
||||
self.bot = bot
|
||||
logging.config.dictConfig(logging_config)
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.add_logging_commands()
|
||||
|
||||
def add_logging_commands(self):
|
||||
@self.bot.tree.command(name="log_test",
|
||||
description="Test the logging system")
|
||||
@self.bot.tree.command(name="log_test", description="Test the logging system") # noqa: E501
|
||||
async def log_test(interaction: discord.Interaction):
|
||||
self.logger.debug("This is a debug message")
|
||||
self.logger.info("This is an info message")
|
||||
self.logger.warning("This is a warning message")
|
||||
self.logger.error("This is an error message")
|
||||
self.logger.critical("This is a critical message")
|
||||
await interaction.response.send_message("Logging test completed."
|
||||
"Check the logs!")
|
||||
await interaction.response.send_message(
|
||||
"Logging test completed. Check the logs!"
|
||||
)
|
||||
|
||||
@self.bot.tree.command(
|
||||
name="set_log_level", description="Set the logging level (Owner/Admin only)" # noqa: E501
|
||||
)
|
||||
@app_commands.choices(
|
||||
level=[
|
||||
app_commands.Choice(name="DEBUG", value="DEBUG"),
|
||||
app_commands.Choice(name="INFO", value="INFO"),
|
||||
app_commands.Choice(name="WARNING", value="WARNING"),
|
||||
app_commands.Choice(name="ERROR", value="ERROR"),
|
||||
app_commands.Choice(name="CRITICAL", value="CRITICAL"),
|
||||
]
|
||||
)
|
||||
async def set_log_level(
|
||||
interaction: discord.Interaction, level: app_commands.Choice[str]
|
||||
):
|
||||
guild = interaction.guild
|
||||
if guild is not None and (
|
||||
interaction.user.id == guild.owner_id
|
||||
or any(
|
||||
role.permissions.administrator for role in interaction.user.roles # noqa: E501
|
||||
)
|
||||
):
|
||||
logging.getLogger().setLevel(level.value)
|
||||
await interaction.response.send_message(
|
||||
f"Logging level set to {level.value}"
|
||||
)
|
||||
else:
|
||||
await interaction.response.send_message(
|
||||
"You do not have permission to set the logging level.",
|
||||
ephemeral=True,
|
||||
)
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
logger_module = LoggerModule(bot)
|
||||
logger_module.add_logging_commands()
|
||||
LoggerModule(bot)
|
||||
|
@ -1,7 +1,5 @@
|
||||
# modules/admin/logging_config.py
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
import os
|
||||
|
||||
LOG_DIR = "logs"
|
||||
@ -14,9 +12,7 @@ logging_config = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"standard": {
|
||||
"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
|
||||
},
|
||||
"standard": {"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"},
|
||||
},
|
||||
"handlers": {
|
||||
"console": {
|
||||
@ -29,7 +25,7 @@ logging_config = {
|
||||
"class": "logging.handlers.RotatingFileHandler",
|
||||
"formatter": "standard",
|
||||
"filename": LOG_FILE,
|
||||
"maxBytes": 1024*1024*5, # 5 MB
|
||||
"maxBytes": 1024 * 1024 * 5, # 5 MB
|
||||
"backupCount": 3,
|
||||
},
|
||||
},
|
||||
|
@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
import discord
|
||||
from discord import app_commands
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -47,7 +48,7 @@ class PolicyModule:
|
||||
embed=discord.Embed(
|
||||
title="Privacy Policy",
|
||||
description=privacy_policy_text,
|
||||
color=discord.Color.blue()
|
||||
color=discord.Color.blue(),
|
||||
)
|
||||
)
|
||||
logger.info(f"User {interaction.user.id} viewed the privacy policy")
|
||||
@ -93,7 +94,7 @@ class PolicyModule:
|
||||
embed=discord.Embed(
|
||||
title="Terms of Service",
|
||||
description=tos_text,
|
||||
color=discord.Color.blue()
|
||||
color=discord.Color.blue(),
|
||||
)
|
||||
)
|
||||
logger.info(f"User {interaction.user.id} viewed the terms of service")
|
||||
|
Reference in New Issue
Block a user