rewrote env parts and fixed some frigging issues

This commit is contained in:
ctih1 2025-07-22 19:32:19 +03:00
parent 99ab5d334e
commit f7042ed8a7
23 changed files with 3070 additions and 280 deletions

View file

@ -1,6 +1,11 @@
import discord
from discord.ext import commands
from modules.globalvars import ownerid
import discord.ext
import discord.ext.commands
from modules.settings import Settings as SettingsManager
settings_manager = SettingsManager()
settings = settings_manager.settings
COG_PREFIX = "assets.cogs."
@ -9,10 +14,34 @@ class CogManager(commands.Cog):
self.bot = bot
@commands.command()
async def load(self, ctx, cog_name: str = None):
if ctx.author.id != ownerid:
async def enable(self, ctx, cog_name: str):
if ctx.author.id not in settings["bot"]["owner_ids"]:
await ctx.send("You do not have permission to use this command.")
return
try:
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.commit()
except Exception as e:
await ctx.send(f"Error enabling cog `{cog_name}`: {e}")
@commands.command()
async def load(self, ctx, cog_name: str | None = None):
if ctx.author.id not in settings["bot"]["owner_ids"]:
await ctx.send("You do not have permission to use this command.")
return
if cog_name is None:
await ctx.send("Give cog_name")
return
if cog_name[:-3] not in settings["bot"]["enabled_cogs"]:
await ctx.send("Please enable the cog first!")
return
if cog_name is None:
await ctx.send("Please provide the cog name to load.")
return
@ -23,8 +52,8 @@ class CogManager(commands.Cog):
await ctx.send(f"Error loading cog `{cog_name}`: {e}")
@commands.command()
async def unload(self, ctx, cog_name: str = None):
if ctx.author.id != ownerid:
async def unload(self, ctx, cog_name: str | None = None):
if ctx.author.id not in settings["bot"]["owner_ids"]:
await ctx.send("You do not have permission to use this command.")
return
if cog_name is None:
@ -37,13 +66,34 @@ class CogManager(commands.Cog):
await ctx.send(f"Error unloading cog `{cog_name}`: {e}")
@commands.command()
async def reload(self, ctx, cog_name: str = None):
if ctx.author.id != ownerid:
async def disable(self, ctx, cog_name: str | None = None):
if ctx.author.id not in settings["bot"]["owner_ids"]:
await ctx.send("You do not have permission to use this command.")
return
if cog_name is None:
await ctx.send("Please provide the cog name to disable.")
return
try:
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.commit()
except Exception as e:
await ctx.send(f"Error unloading cog `{cog_name}`: {e}")
@commands.command()
async def reload(self, ctx, cog_name: str | None = None):
if ctx.author.id not in settings["bot"]["owner_ids"]:
await ctx.send("You do not have permission to use this command.")
return
if cog_name is None:
await ctx.send("Please provide the cog name to reload.")
return
if cog_name[:-3] not in settings["bot"]["enabled_cogs"]:
await ctx.send("Please enable the cog first!")
return
try:
await self.bot.unload_extension(COG_PREFIX + cog_name)
await self.bot.load_extension(COG_PREFIX + cog_name)

View file

@ -1,9 +1,12 @@
import discord
import discord.context_managers
from discord.ext import commands
from modules.globalvars import ownerid
import logging
from typing import Literal, get_args, cast
from modules.settings import Settings as SettingsManager
settings_manager = SettingsManager()
settings = settings_manager.settings
logger = logging.getLogger("goober")
@ -22,10 +25,10 @@ class FileSync(commands.Cog):
await ctx.send("Invalid mode, use 's' or 'r'.")
return
self.mode: AvailableModes = cast(AvailableModes, mode.lower())
self.mode = cast(AvailableModes, mode.lower())
self.peer_id = peer.id
if ctx.author.id != ownerid:
if ctx.author.id not in settings["bot"]["owner_ids"]:
await ctx.send("You don't have permission to execute this command.")
return

View file

@ -1,9 +1,9 @@
import discord
from discord.ext import commands
from modules.image import *
from modules.volta.main import _
from PIL import Image, ImageEnhance, ImageFilter, ImageOps, ImageChops, ImageColor
import os, random, shutil, tempfile
import modules.keys as k
async def deepfryimage(path):
with Image.open(path).convert("RGB") as im:
@ -66,7 +66,7 @@ class whami(commands.Cog):
else:
fallback_image = get_random_asset_image()
if fallback_image is None:
await ctx.reply(_('no_image_available'))
await ctx.reply(k.no_image_available())
return
temp_input = tempfile.mktemp(suffix=os.path.splitext(fallback_image)[1])
shutil.copy(fallback_image, temp_input)
@ -74,7 +74,7 @@ class whami(commands.Cog):
else:
fallback_image = get_random_asset_image()
if fallback_image is None:
await ctx.reply(_('no_image_available'))
await ctx.reply(k.no_image_available())
return
temp_input = tempfile.mktemp(suffix=os.path.splitext(fallback_image)[1])
shutil.copy(fallback_image, temp_input)
@ -85,7 +85,7 @@ class whami(commands.Cog):
if output_path is None or not os.path.isfile(output_path):
if temp_input and os.path.exists(temp_input):
os.remove(temp_input)
await ctx.reply(_('failed_generate_image'))
await ctx.reply(k.failed_generate_image())
return
deepfried_path = await deepfryimage(output_path)

View file

@ -2,7 +2,10 @@ from discord.ext import commands
import discord
from collections import defaultdict, Counter
import datetime
from modules.globalvars import ownerid
from modules.settings import Settings as SettingsManager
settings_manager = SettingsManager()
settings = settings_manager.settings
class StatsCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@ -31,7 +34,7 @@ class StatsCog(commands.Cog):
@commands.command()
async def spyware(self, ctx):
if ctx.author.id != ownerid:
if ctx.author.id not in settings["bot"]["owner_ids"]:
return
uptime = datetime.datetime.utcnow() - self.start_time
hours_elapsed = max((uptime.total_seconds() / 3600), 1)

View file

@ -14,12 +14,12 @@ MODEL_MATCH_STRING = r"[0-9]{2}_[0-9]{2}_[0-9]{4}-[0-9]{2}_[0-9]{2}"
try:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Embedding, LSTM, Dense
from tensorflow.keras.backend import clear_session
import keras
from keras.preprocessing.text import Tokenizer
from keras.preprocessing.sequence import pad_sequences
from keras.models import Sequential, load_model
from keras.layers import Embedding, LSTM, Dense
from keras.backend import clear_session
if tf.config.list_physical_devices('GPU'):
print("Using GPU acceleration")

View file

@ -5,7 +5,10 @@ from bs4 import BeautifulSoup
import json
import asyncio
from urllib.parse import urljoin
from modules.globalvars import ownerid
from modules.settings import Settings as SettingsManager
settings_manager = SettingsManager()
settings = settings_manager.settings
class WebScraper(commands.Cog):
def __init__(self, bot):
self.bot = bot
@ -81,7 +84,7 @@ class WebScraper(commands.Cog):
@commands.command()
async def start_scrape(self, ctx, start_url: str):
"""Command to start the scraping process."""
if ctx.author.id != ownerid:
if ctx.author.id not in settings["bot"]["owner_ids"]:
await ctx.send("You do not have permission to use this command.")
return
@ -99,7 +102,7 @@ class WebScraper(commands.Cog):
@commands.command()
async def undo_scrape(self, ctx):
"""Command to undo the last scrape."""
if ctx.author.id != ownerid:
if ctx.author.id not in settings["bot"]["owner_ids"]:
await ctx.send("You do not have permission to use this command.")
return

View file

@ -99,6 +99,9 @@ class GooberWeb(commands.Cog):
print("Goober web server started on port 8080")
async def stop_web_server(self):
if self.site is None or self.runner is None:
return
await self.site.stop()
await self.runner.cleanup()
print("Web server stopped")

View file

@ -131,6 +131,12 @@
"command_stats_embed_field2name": "Version",
"command_stats_embed_field2value": "Local: {local_version} \nLatest: {latest_version}",
"command_stats_embed_field3name": "Variable Info",
"command_stats_embed_field3value": "Name: {NAME} \nPrefix: {PREFIX} \nOwner ID: {ownerid}\nPing line: {PING_LINE} \nMemory Sharing Enabled: {showmemenabled} \nUser Training Enabled: {USERTRAIN_ENABLED}\nSong: {song} \nSplashtext: ```{splashtext}```"
"command_stats_embed_field3value": "Name: {NAME} \nPrefix: {PREFIX} \nOwner ID: {ownerid}\nPing line: {PING_LINE} \nMemory Sharing Enabled: {showmemenabled} \nUser Training Enabled: {USERTRAIN_ENABLED}\nSong: {song} \nSplashtext: ```{splashtext}```",
"no_image_available": "No images available!",
"failed_generate_image": "Failed to generate an image",
"markov_model_not_found": "Markov model not found!",
"blacklisted": "blacklisted",
"blacklisted_user": "Blacklisted user",
"edit_fail": "Failed to edit message"
}

View file

@ -102,7 +102,7 @@
"command_markov_retrain": "Uudelleenkoulutetaan markov-mallia... Odota.",
"command_markov_memory_not_found": "Virhe: muistitiedostoa ei löytynyt!",
"command_markov_memory_is_corrupt": "Virhe: muistitiedosto on korruptoitu!",
"command_markov_retraining": "Käsitellään {processed_data}/{data_size} datapisteestä...",
"command_markov_retraining": "Käsitellään {processed_data}/{data_size} datapistettä...",
"command_markov_retrain_successful": "Markov-malli koulutettiin uudestaan {data_size} datapisteellä!",
"command_desc_talk":"puhuu ja sillei",
"command_talk_insufficent_text": "Minun pitää oppia lisää viesteistä ennen kun puhun.",
@ -131,5 +131,6 @@
"command_stats_embed_field2value": "Paikallinen: {local_version} \nUusin: {latest_version}",
"command_stats_embed_field3name": "Muuttajainformaatio",
"command_stats_embed_field3value": "Nimi: {NAME} \nEtuliite: {PREFIX} \nOmistajan ID: {ownerid}\nPing-linja: {PING_LINE} \nMuistin jako päällä: {showmemenabled} \nOppiminen käyttäjistä: {USERTRAIN_ENABLED}\nLaulu: {song} \nRoisketeksti: ```{splashtext}```"
}