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

@ -4,9 +4,8 @@ from discord.ext import commands
import logging
from typing import Literal, get_args, cast
from modules.permission import requires_admin
from modules.settings import Settings as SettingsManager
from modules.settings import instance as settings_manager
settings_manager = SettingsManager()
settings = settings_manager.settings

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))

View file

@ -3,9 +3,8 @@ import discord
from collections import defaultdict, Counter
import datetime
from modules.permission import requires_admin
from modules.settings import Settings as SettingsManager
from modules.settings import instance as settings_manager
settings_manager = SettingsManager()
settings = settings_manager.settings

View file

@ -3,6 +3,8 @@ from discord.ext import commands
from modules.globalvars import RED, GREEN, RESET, LOCAL_VERSION_FILE
import os
from modules.permission import requires_admin
class songchange(commands.Cog):
def __init__(self, bot):
@ -17,15 +19,10 @@ class songchange(commands.Cog):
global local_version
local_version = get_local_version()
@requires_admin()
@commands.command()
async def changesong(self, ctx):
if LOCAL_VERSION_FILE > "0.11.8":
await ctx.send(
f"Goober is too old! you must have version 0.11.8 you have {local_version}"
)
return
await ctx.send("Check the terminal! (this does not persist across restarts)")
song = input("\nEnter a song:\n")
async def changesong(self, ctx, song: str):
await ctx.send(f"Changed song to {song}")
try:
await self.bot.change_presence(
activity=discord.Activity(

View file

@ -6,9 +6,8 @@ import json
import asyncio
from urllib.parse import urljoin
from modules.permission import requires_admin
from modules.settings import Settings as SettingsManager
from modules.settings import instance as settings_manager
settings_manager = SettingsManager()
settings = settings_manager.settings

View file

@ -73,5 +73,5 @@
"command_stats_embed_field2name": "Version",
"command_stats_embed_field2value": "Version local: {local_version} \nUltima version: {latest_version}",
"command_stats_embed_field3name": "informacion sobre las variables",
"command_stats_embed_field3value": "Nombre: {NAME} \nPrefijo: {PREFIX} \nID del propietario: {ownerid}\nLinea de ping: {PING_LINE} \nCompartir memoria habilitada: {showmemenabled} \nEntrenamiento de usuario habilitado: {USERTRAIN_ENABLED} \nCancion: {song} \nTexto de bienvenida: ```{splashtext}```"
"command_stats_embed_field3value": "Nombre: {NAME} \nPrefijo: {PREFIX} \nID del propietario: {ownerid}\nLinea de ping: {PING_LINE} \nCompartir memoria habilitada: {showmemenabled} \nEntrenamiento de usuario habilitado: {USERTRAIN_ENABLED} \nCancion: {song} \nTexto de bienvenida: ```{splashtext}```"
}