changed from creating new settings instance into using a shared one

This commit is contained in:
ctih1 2025-07-23 15:42:13 +03:00
parent 7e21a10dde
commit ade9d88086
18 changed files with 252 additions and 43 deletions

View file

@ -7,10 +7,9 @@ import discord.ext.commands
import modules.keys as k
from modules.permission import requires_admin
from modules.sentenceprocessing import send_message
from modules.settings import Settings as SettingsManager
from modules.settings import instance as settings_manager
import requests
settings_manager = SettingsManager()
settings = settings_manager.settings
@ -159,13 +158,11 @@ class BaseCommands(commands.Cog):
response = requests.post(
"https://litterbox.catbox.moe/resources/internals/api.php",
data={"reqtype": "fileupload", "time": "1h", "fileToUpload": data},
data={"reqtype": "fileupload", "time": "1h"},
files={"fileToUpload": data},
)
print(response.text)
print(response.status_code)
# await send_message(ctx, memorylitter.stdout.strip())
await send_message(ctx, response.text)
async def setup(bot: discord.ext.commands.Bot):

View file

@ -3,9 +3,9 @@ from discord.ext import commands
import discord.ext
import discord.ext.commands
from modules.permission import requires_admin
from modules.settings import Settings as SettingsManager
from modules.settings import instance as settings_manager
from modules.globalvars import available_cogs
settings_manager = SettingsManager()
settings = settings_manager.settings
@ -23,6 +23,15 @@ class CogManager(commands.Cog):
await self.bot.load_extension(COG_PREFIX + cog_name)
await ctx.send(f"Loaded cog `{cog_name}` successfully.")
settings["bot"]["enabled_cogs"].append(cog_name)
settings_manager.add_admin_log_event(
{
"action": "add",
"author": ctx.author.id,
"change": "enabled_cogs",
"messageId": ctx.message.id,
"target": cog_name,
}
)
settings_manager.commit()
except Exception as e:
@ -69,6 +78,15 @@ class CogManager(commands.Cog):
await self.bot.unload_extension(COG_PREFIX + cog_name)
await ctx.send(f"Unloaded cog `{cog_name}` successfully.")
settings["bot"]["enabled_cogs"].remove(cog_name)
settings_manager.add_admin_log_event(
{
"action": "del",
"author": ctx.author.id,
"change": "enabled_cogs",
"messageId": ctx.message.id,
"target": cog_name,
}
)
settings_manager.commit()
except Exception as e:
await ctx.send(f"Error unloading cog `{cog_name}`: {e}")
@ -102,7 +120,8 @@ class CogManager(commands.Cog):
title="Loaded Cogs",
description="Here is a list of all currently loaded cogs:",
)
embed.add_field(name="Cogs", value="\n".join(cogs), inline=False)
embed.add_field(name="Loaded cogs", value="\n".join(cogs), inline=False)
embed.add_field(name="Available cogs", value="\n".join(available_cogs()))
await ctx.send(embed=embed)

View file

@ -24,9 +24,8 @@ import markovify
logger = logging.getLogger("goober")
from modules.settings import Settings as SettingsManager
from modules.settings import instance as settings_manager
settings_manager = SettingsManager()
settings = settings_manager.settings

View file

@ -0,0 +1,118 @@
import discord
from discord.ext import commands
from modules.permission import requires_admin
from modules.settings import instance as settings_manager
settings = settings_manager.settings
class PermissionManager(commands.Cog):
def __init__(self, bot):
self.bot = bot
@requires_admin()
@commands.command()
async def add_owner(self, ctx: commands.Context, member: discord.Member):
settings["bot"]["owner_ids"].append(member.id)
settings_manager.add_admin_log_event(
{
"action": "add",
"author": ctx.author.id,
"change": "owner_ids",
"messageId": ctx.message.id,
"target": member.id,
}
)
settings_manager.commit()
embed = discord.Embed(
title="Permissions",
description=f"Set {member.name} as an owner",
color=discord.Color.blue(),
)
await ctx.send(embed=embed)
@requires_admin()
@commands.command()
async def remove_owner(self, ctx: commands.Context, member: discord.Member):
try:
settings["bot"]["owner_ids"].remove(member.id)
settings_manager.add_admin_log_event(
{
"action": "del",
"author": ctx.author.id,
"change": "owner_ids",
"messageId": ctx.message.id,
"target": member.id,
}
)
settings_manager.commit()
except ValueError:
await ctx.send("User is not an owner!")
return
embed = discord.Embed(
title="Permissions",
description=f"Removed {member.name} from being an owner",
color=discord.Color.blue(),
)
await ctx.send(embed=embed)
@requires_admin()
@commands.command()
async def blacklist_user(self, ctx: commands.Context, member: discord.Member):
settings["bot"]["blacklisted_users"].append(member.id)
settings_manager.add_admin_log_event(
{
"action": "add",
"author": ctx.author.id,
"change": "blacklisted_users",
"messageId": ctx.message.id,
"target": member.id,
}
)
settings_manager.commit()
embed = discord.Embed(
title="Blacklist",
description=f"Added {member.name} to the blacklist",
color=discord.Color.blue(),
)
await ctx.send(embed=embed)
@requires_admin()
@commands.command()
async def unblacklist_user(self, ctx: commands.Context, member: discord.Member):
try:
settings["bot"]["blacklisted_users"].remove(member.id)
settings_manager.add_admin_log_event(
{
"action": "del",
"author": ctx.author.id,
"change": "blacklisted_users",
"messageId": ctx.message.id,
"target": member.id,
}
)
settings_manager.commit()
except ValueError:
await ctx.send("User is not on the blacklist!")
return
embed = discord.Embed(
title="Blacklist",
description=f"Removed {member.name} from blacklist",
color=discord.Color.blue(),
)
await ctx.send(embed=embed)
async def setup(bot):
await bot.add_cog(PermissionManager(bot))