2025-01-05 21:03:49 +01:00
|
|
|
import os
|
|
|
|
import re
|
2025-06-22 19:07:41 +02:00
|
|
|
import json
|
|
|
|
import time
|
|
|
|
import random
|
|
|
|
import traceback
|
2025-01-05 21:03:49 +01:00
|
|
|
import subprocess
|
2025-06-29 19:44:56 +02:00
|
|
|
import tempfile
|
|
|
|
import shutil
|
2025-07-21 22:10:00 +02:00
|
|
|
import psutil
|
2025-07-01 20:26:48 +02:00
|
|
|
import asyncio
|
2025-07-18 01:30:57 +02:00
|
|
|
import platform
|
2025-07-05 20:15:54 +02:00
|
|
|
import sys
|
|
|
|
from typing import List, Dict, Set, Optional, Tuple, Any, Union, Callable, Coroutine, TypeVar, Type
|
2025-07-08 17:02:10 +03:00
|
|
|
import logging
|
2025-06-27 19:45:44 +02:00
|
|
|
from modules.globalvars import *
|
|
|
|
from modules.prestartchecks import start_checks
|
2025-07-08 17:02:10 +03:00
|
|
|
from modules.logger import GooberFormatter
|
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger("goober")
|
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
console_handler = logging.StreamHandler()
|
|
|
|
console_handler.setLevel(logging.DEBUG)
|
|
|
|
console_handler.setFormatter(GooberFormatter())
|
|
|
|
|
|
|
|
file_handler = logging.FileHandler("log.txt", mode="w+", encoding="UTF-8")
|
|
|
|
file_handler.setLevel(logging.DEBUG)
|
|
|
|
file_handler.setFormatter(GooberFormatter(colors=False))
|
|
|
|
|
|
|
|
logger.addHandler(console_handler)
|
|
|
|
logger.addHandler(file_handler)
|
|
|
|
|
2025-06-27 19:45:44 +02:00
|
|
|
# Print splash text and check for updates
|
|
|
|
print(splashtext) # Print splash text (from modules/globalvars.py)
|
|
|
|
start_checks()
|
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
import requests
|
|
|
|
import discord
|
2025-06-28 16:56:05 -04:00
|
|
|
from discord.ext import commands
|
2025-07-07 13:05:50 +02:00
|
|
|
from discord import app_commands
|
2025-07-05 20:15:54 +02:00
|
|
|
from discord import Colour, Embed, File, Interaction, Message
|
|
|
|
from discord.abc import Messageable
|
2025-06-28 16:56:05 -04:00
|
|
|
from discord.ext import commands
|
2025-06-27 19:45:44 +02:00
|
|
|
|
2025-07-07 13:05:50 +02:00
|
|
|
from modules.volta.main import _, set_language
|
2025-06-20 23:48:10 +02:00
|
|
|
from modules.markovmemory import *
|
|
|
|
from modules.version import *
|
2025-06-21 12:00:49 +02:00
|
|
|
from modules.sentenceprocessing import *
|
2025-06-22 20:49:07 +02:00
|
|
|
from modules.unhandledexception import handle_exception
|
2025-06-27 19:45:44 +02:00
|
|
|
sys.excepthook = handle_exception
|
2025-07-22 19:34:46 +02:00
|
|
|
check_for_update()
|
2025-07-05 20:15:54 +02:00
|
|
|
T = TypeVar('T')
|
|
|
|
MessageContext = Union[commands.Context, discord.Interaction]
|
|
|
|
MessageReference = Union[Message, discord.WebhookMessage]
|
2025-03-16 16:39:26 +01:00
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
# Constants with type hints
|
|
|
|
positive_gifs: List[str] = os.getenv("POSITIVE_GIFS", "").split(',')
|
|
|
|
currenthash: str = ""
|
|
|
|
launched: bool = False
|
|
|
|
slash_commands_enabled: bool = False
|
2025-01-05 21:03:49 +01:00
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Load memory and Markov model for text generation
|
2025-07-05 20:15:54 +02:00
|
|
|
memory: List[str] = load_memory()
|
|
|
|
markov_model: Optional[markovify.Text] = load_markov_model()
|
2025-01-05 21:03:49 +01:00
|
|
|
if not markov_model:
|
2025-07-08 17:02:10 +03:00
|
|
|
logger.error(_('markov_model_not_found'))
|
2025-01-05 21:03:49 +01:00
|
|
|
memory = load_memory()
|
|
|
|
markov_model = train_markov_model(memory)
|
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
generated_sentences: Set[str] = set()
|
|
|
|
used_words: Set[str] = set()
|
|
|
|
|
2025-07-22 19:34:46 +02:00
|
|
|
def get_git_remote_url():
|
|
|
|
try:
|
|
|
|
url = subprocess.check_output(
|
|
|
|
["git", "config", "--get", "remote.origin.url"],
|
|
|
|
text=True,
|
|
|
|
stderr=subprocess.DEVNULL,
|
|
|
|
).strip()
|
|
|
|
return url
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
return "Unknown"
|
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
async def load_cogs_from_folder(bot, folder_name="assets/cogs"):
|
|
|
|
for filename in os.listdir(folder_name):
|
|
|
|
if filename.endswith(".py") and not filename.startswith("_"):
|
|
|
|
cog_name = filename[:-3]
|
|
|
|
module_path = folder_name.replace("/", ".").replace("\\", ".") + f".{cog_name}"
|
|
|
|
try:
|
|
|
|
await bot.load_extension(module_path)
|
2025-07-08 17:02:10 +03:00
|
|
|
logger.info(f"{(_('loaded_cog'))} {cog_name}")
|
2025-07-05 20:15:54 +02:00
|
|
|
except Exception as e:
|
2025-07-08 17:02:10 +03:00
|
|
|
logger.error(f"{(_('cog_fail'))} {cog_name} {e}")
|
2025-07-05 20:15:54 +02:00
|
|
|
traceback.print_exc()
|
2025-01-05 21:03:49 +01:00
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Event: Called when the bot is ready
|
2025-01-05 21:03:49 +01:00
|
|
|
@bot.event
|
2025-07-05 20:15:54 +02:00
|
|
|
async def on_ready() -> None:
|
2025-06-21 00:33:33 +02:00
|
|
|
global launched
|
2025-06-22 20:49:07 +02:00
|
|
|
global slash_commands_enabled
|
2025-06-23 14:10:59 +02:00
|
|
|
global NAME
|
2025-07-17 15:22:39 +02:00
|
|
|
global status
|
2025-07-05 20:15:54 +02:00
|
|
|
|
|
|
|
folder_name: str = "cogs"
|
|
|
|
if launched:
|
2025-06-21 00:35:02 +02:00
|
|
|
return
|
2025-07-05 20:15:54 +02:00
|
|
|
|
2025-06-22 21:51:27 +02:00
|
|
|
await load_cogs_from_folder(bot)
|
2025-01-05 21:03:49 +01:00
|
|
|
try:
|
2025-07-05 20:15:54 +02:00
|
|
|
synced: List[discord.app_commands.AppCommand] = await bot.tree.sync()
|
2025-07-08 17:02:10 +03:00
|
|
|
logger.info(f"{_('synced_commands')} {len(synced)} {(_('synced_commands2'))}")
|
2025-01-05 21:03:49 +01:00
|
|
|
slash_commands_enabled = True
|
2025-07-08 17:02:10 +03:00
|
|
|
logger.info(f"{(_('started')).format(name=NAME)}")
|
2025-06-22 19:07:41 +02:00
|
|
|
except discord.errors.Forbidden as perm_error:
|
2025-07-08 17:02:10 +03:00
|
|
|
logger.error(f"Permission error while syncing commands: {perm_error}")
|
|
|
|
logger.error("Make sure the bot has the 'applications.commands' scope and is invited with the correct permissions.")
|
2025-06-22 19:07:41 +02:00
|
|
|
quit()
|
2025-01-05 21:03:49 +01:00
|
|
|
except Exception as e:
|
2025-07-08 17:02:10 +03:00
|
|
|
logger.error(f"{_('fail_commands_sync')} {e}")
|
2025-03-16 16:39:26 +01:00
|
|
|
traceback.print_exc()
|
|
|
|
quit()
|
2025-07-05 20:15:54 +02:00
|
|
|
|
2025-01-05 21:03:49 +01:00
|
|
|
if not song:
|
2025-07-17 15:22:39 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
status = {
|
|
|
|
"idle": discord.Status.idle,
|
|
|
|
"dnd": discord.Status.dnd,
|
|
|
|
"invisible": discord.Status.invisible,
|
|
|
|
"online": discord.Status.online
|
|
|
|
}.get(status.lower(), discord.Status.online)
|
|
|
|
await bot.change_presence(status=status, activity=discord.Activity(type=discord.ActivityType.listening, name=f"{song}"))
|
2025-06-21 00:29:44 +02:00
|
|
|
launched = True
|
2025-06-22 20:49:07 +02:00
|
|
|
@bot.event
|
2025-07-05 20:15:54 +02:00
|
|
|
async def on_command_error(ctx: commands.Context, error: commands.CommandError) -> None:
|
2025-06-22 20:49:07 +02:00
|
|
|
from modules.unhandledexception import handle_exception
|
|
|
|
|
|
|
|
if isinstance(error, commands.CommandInvokeError):
|
2025-07-05 20:15:54 +02:00
|
|
|
original: Exception = error.original
|
2025-06-22 20:49:07 +02:00
|
|
|
handle_exception(
|
|
|
|
type(original), original, original.__traceback__,
|
|
|
|
context=f"Command: {ctx.command} | User: {ctx.author}"
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
handle_exception(
|
|
|
|
type(error), error, error.__traceback__,
|
|
|
|
context=f"Command: {ctx.command} | User: {ctx.author}"
|
|
|
|
)
|
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
@bot.hybrid_command(description=f"{(_('command_desc_retrain'))}")
|
|
|
|
async def retrain(ctx: commands.Context) -> None:
|
2025-01-05 21:03:49 +01:00
|
|
|
if ctx.author.id != ownerid:
|
|
|
|
return
|
2025-07-22 19:34:46 +02:00
|
|
|
global markov_model
|
2025-01-05 21:03:49 +01:00
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
message_ref: MessageReference = await send_message(ctx, f"{(_('command_markov_retrain'))}")
|
2025-01-05 21:03:49 +01:00
|
|
|
try:
|
|
|
|
with open(MEMORY_FILE, 'r') as f:
|
2025-07-05 20:15:54 +02:00
|
|
|
memory: List[str] = json.load(f)
|
2025-01-05 21:03:49 +01:00
|
|
|
except FileNotFoundError:
|
2025-07-05 20:15:54 +02:00
|
|
|
await send_message(ctx, f"{(_('command_markov_memory_not_found'))}")
|
2025-01-05 21:03:49 +01:00
|
|
|
return
|
|
|
|
except json.JSONDecodeError:
|
2025-07-05 20:15:54 +02:00
|
|
|
await send_message(ctx, f"{(_('command_markov_memory_is_corrupt'))}")
|
2025-01-05 21:03:49 +01:00
|
|
|
return
|
2025-07-05 20:15:54 +02:00
|
|
|
data_size: int = len(memory)
|
|
|
|
processed_data: int = 0
|
|
|
|
processing_message_ref: MessageReference = await send_message(ctx, f"{(_('command_markov_retraining')).format(processed_data=processed_data, data_size=data_size)}")
|
2025-01-05 21:03:49 +01:00
|
|
|
markov_model = train_markov_model(memory)
|
|
|
|
save_markov_model(markov_model)
|
2025-07-09 15:05:06 +02:00
|
|
|
await send_message(ctx, f"{_('command_markov_retrain_successful').format(data_size=data_size)}", edit=True, message_reference=processing_message_ref)
|
2025-01-05 21:03:49 +01:00
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
@bot.hybrid_command(description=f"{(_('command_desc_talk'))}")
|
|
|
|
async def talk(ctx: commands.Context, sentence_size: int = 5) -> None:
|
2025-01-05 21:03:49 +01:00
|
|
|
if not markov_model:
|
2025-07-05 20:15:54 +02:00
|
|
|
await send_message(ctx, f"{(_('command_talk_insufficent_text'))}")
|
2025-01-05 21:03:49 +01:00
|
|
|
return
|
|
|
|
|
2025-07-22 20:03:11 +02:00
|
|
|
response = None
|
2025-03-23 20:18:52 +01:00
|
|
|
for _ in range(20):
|
|
|
|
if sentence_size == 1:
|
2025-07-22 20:03:11 +02:00
|
|
|
sentence = markov_model.make_short_sentence(max_chars=100, tries=100)
|
|
|
|
response = sentence.split()[0] if sentence else None
|
2025-03-23 20:18:52 +01:00
|
|
|
else:
|
|
|
|
response = markov_model.make_sentence(tries=100, max_words=sentence_size)
|
|
|
|
|
2025-01-05 21:03:49 +01:00
|
|
|
if response and response not in generated_sentences:
|
2025-03-23 20:18:52 +01:00
|
|
|
if sentence_size > 1:
|
|
|
|
response = improve_sentence_coherence(response)
|
2025-01-05 21:03:49 +01:00
|
|
|
generated_sentences.add(response)
|
|
|
|
break
|
|
|
|
else:
|
2025-07-05 20:15:54 +02:00
|
|
|
await send_message(ctx, f"{(_('command_talk_generation_fail'))}")
|
2025-07-22 20:03:11 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
cleaned = re.sub(r'[^\w\s]', '', response).lower()
|
|
|
|
coherent = rephrase_for_coherence(cleaned)
|
|
|
|
|
|
|
|
if random.random() < 0.9 and is_positive(coherent):
|
|
|
|
gif_url = random.choice(positive_gifs)
|
|
|
|
message = f"{coherent}\n[jif]({gif_url})"
|
|
|
|
else:
|
|
|
|
message = coherent
|
|
|
|
|
|
|
|
logger.info(message)
|
|
|
|
os.environ['gooberlatestgen'] = message
|
|
|
|
await send_message(ctx, message)
|
|
|
|
|
2025-01-05 21:03:49 +01:00
|
|
|
|
2025-07-21 22:10:00 +02:00
|
|
|
@bot.hybrid_command(description=f"RAM")
|
|
|
|
async def ramusage(ctx):
|
|
|
|
process = psutil.Process(os.getpid())
|
|
|
|
mem = process.memory_info().rss
|
2025-07-22 19:34:46 +02:00
|
|
|
await send_message(ctx, f"{mem / 1024 / 1024:.2f} MB")
|
2025-07-21 22:10:00 +02:00
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
bot.remove_command('help')
|
2025-06-22 19:07:41 +02:00
|
|
|
# Command: Show help information
|
2025-07-05 20:15:54 +02:00
|
|
|
@bot.hybrid_command(description=f"{(_('command_desc_help'))}")
|
|
|
|
async def help(ctx: commands.Context) -> None:
|
|
|
|
embed: discord.Embed = discord.Embed(
|
|
|
|
title=f"{(_('command_help_embed_title'))}",
|
|
|
|
description=f"{(_('command_help_embed_desc'))}",
|
2025-06-27 19:17:13 +02:00
|
|
|
color=Colour(0x000000)
|
2025-01-05 21:03:49 +01:00
|
|
|
)
|
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
command_categories: Dict[str, List[str]] = {
|
2025-07-07 16:26:37 +02:00
|
|
|
f"{(_('command_help_categories_general'))}": ["mem", "talk", "about", "ping", "impact", "demotivator", "help"],
|
|
|
|
f"{(_('command_help_categories_admin'))}": ["stats", "retrain", "setlanguage"]
|
2025-01-05 21:03:49 +01:00
|
|
|
}
|
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
custom_commands: List[str] = []
|
2025-01-05 21:03:49 +01:00
|
|
|
for cog_name, cog in bot.cogs.items():
|
|
|
|
for command in cog.get_commands():
|
2025-07-05 20:15:54 +02:00
|
|
|
if command.name not in command_categories[f"{(_('command_help_categories_general'))}"] and command.name not in command_categories[f"{(_('command_help_categories_admin'))}"]:
|
2025-01-05 21:03:49 +01:00
|
|
|
custom_commands.append(command.name)
|
|
|
|
|
|
|
|
if custom_commands:
|
2025-07-05 20:15:54 +02:00
|
|
|
embed.add_field(name=f"{(_('command_help_categories_custom'))}", value="\n".join([f"{PREFIX}{command}" for command in custom_commands]), inline=False)
|
2025-01-05 21:03:49 +01:00
|
|
|
|
|
|
|
for category, commands_list in command_categories.items():
|
2025-07-05 20:15:54 +02:00
|
|
|
commands_in_category: str = "\n".join([f"{PREFIX}{command}" for command in commands_list])
|
2025-01-05 21:03:49 +01:00
|
|
|
embed.add_field(name=category, value=commands_in_category, inline=False)
|
|
|
|
|
|
|
|
await send_message(ctx, embed=embed)
|
|
|
|
|
2025-07-07 13:05:50 +02:00
|
|
|
@bot.hybrid_command(description=f"{(_('command_desc_setlang'))}")
|
|
|
|
@app_commands.describe(locale="Choose your language")
|
|
|
|
async def setlanguage(ctx: commands.Context, locale: str) -> None:
|
2025-07-07 16:26:37 +02:00
|
|
|
if ctx.author.id != ownerid:
|
2025-07-19 00:30:57 +02:00
|
|
|
await ctx.send(":thumbsdown:")
|
2025-07-07 16:26:37 +02:00
|
|
|
return
|
2025-07-07 13:05:50 +02:00
|
|
|
await ctx.defer()
|
|
|
|
set_language(locale)
|
|
|
|
await ctx.send(":thumbsup:")
|
|
|
|
|
2025-01-05 21:03:49 +01:00
|
|
|
@bot.event
|
2025-07-05 20:15:54 +02:00
|
|
|
async def on_message(message: discord.Message) -> None:
|
2025-06-28 16:56:05 -04:00
|
|
|
global memory, markov_model
|
2025-01-05 21:03:49 +01:00
|
|
|
if message.author.bot:
|
|
|
|
return
|
|
|
|
|
|
|
|
if str(message.author.id) in BLACKLISTED_USERS:
|
|
|
|
return
|
2025-07-17 15:22:39 +02:00
|
|
|
|
2025-01-05 21:03:49 +01:00
|
|
|
if message.content.startswith((f"{PREFIX}talk", f"{PREFIX}mem", f"{PREFIX}help", f"{PREFIX}stats", f"{PREFIX}")):
|
2025-07-08 17:02:10 +03:00
|
|
|
logger.info(f"{(_('command_ran')).format(message=message)}")
|
2025-01-05 21:03:49 +01:00
|
|
|
await bot.process_commands(message)
|
|
|
|
return
|
|
|
|
|
|
|
|
if message.content:
|
|
|
|
if not USERTRAIN_ENABLED:
|
|
|
|
return
|
2025-07-18 00:49:04 +02:00
|
|
|
formatted_message: str = message.content
|
|
|
|
cleaned_message: str = formatted_message
|
2025-07-22 19:34:46 +02:00
|
|
|
save_memory(memory)
|
2025-01-05 21:03:49 +01:00
|
|
|
await bot.process_commands(message)
|
|
|
|
|
2025-03-30 18:53:57 +02:00
|
|
|
@bot.event
|
2025-07-05 20:15:54 +02:00
|
|
|
async def on_interaction(interaction: discord.Interaction) -> None:
|
2025-07-18 13:57:58 +02:00
|
|
|
name = None
|
|
|
|
if interaction.data.get('name') is None:
|
|
|
|
name = "Unknown"
|
|
|
|
else:
|
|
|
|
name = interaction.data['name']
|
|
|
|
logger.info(f"{(_('command_ran_s')).format(interaction=interaction)}{name}")
|
2025-03-30 21:01:20 +02:00
|
|
|
@bot.check
|
2025-07-05 20:15:54 +02:00
|
|
|
async def block_blacklisted(ctx: commands.Context) -> bool:
|
2025-03-30 21:01:20 +02:00
|
|
|
if str(ctx.author.id) in BLACKLISTED_USERS:
|
|
|
|
try:
|
|
|
|
if isinstance(ctx, discord.Interaction):
|
|
|
|
if not ctx.response.is_done():
|
2025-07-09 15:05:06 +02:00
|
|
|
await ctx.response.send_message(_('blacklisted'), ephemeral=True)
|
2025-03-30 21:01:20 +02:00
|
|
|
else:
|
2025-07-09 15:05:06 +02:00
|
|
|
await ctx.followup.send(_('blacklisted'), ephemeral=True)
|
2025-03-30 21:01:20 +02:00
|
|
|
else:
|
2025-07-09 15:05:06 +02:00
|
|
|
await ctx.send(_('blacklisted_user'), ephemeral=True)
|
2025-03-30 21:01:20 +02:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
return False
|
|
|
|
return True
|
2025-07-05 20:15:54 +02:00
|
|
|
@bot.hybrid_command(description=f"{(_('command_desc_ping'))}")
|
|
|
|
async def ping(ctx: commands.Context) -> None:
|
2025-01-05 21:03:49 +01:00
|
|
|
await ctx.defer()
|
2025-07-05 20:15:54 +02:00
|
|
|
latency: int = round(bot.latency * 1000)
|
2025-01-05 21:03:49 +01:00
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
LOLembed: discord.Embed = discord.Embed(
|
2025-01-05 21:03:49 +01:00
|
|
|
title="Pong!!",
|
|
|
|
description=(
|
|
|
|
f"{PING_LINE}\n"
|
2025-07-05 20:15:54 +02:00
|
|
|
f"`{(_('command_ping_embed_desc'))}: {latency}ms`\n"
|
2025-01-05 21:03:49 +01:00
|
|
|
),
|
2025-06-27 19:17:13 +02:00
|
|
|
color=Colour(0x000000)
|
2025-01-05 21:03:49 +01:00
|
|
|
)
|
2025-07-05 20:15:54 +02:00
|
|
|
LOLembed.set_footer(text=f"{(_('command_ping_footer'))} {ctx.author.name}", icon_url=ctx.author.avatar.url)
|
2025-01-05 21:03:49 +01:00
|
|
|
|
|
|
|
await ctx.send(embed=LOLembed)
|
2025-07-23 13:38:09 +02:00
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
@bot.hybrid_command(description=f"{(_('command_about_desc'))}")
|
|
|
|
async def about(ctx: commands.Context) -> None:
|
2025-07-23 13:38:09 +02:00
|
|
|
latest_version: str = check_for_update(slient=True)
|
2025-07-05 20:15:54 +02:00
|
|
|
embed: discord.Embed = discord.Embed(title=f"{(_('command_about_embed_title'))}", description="", color=Colour(0x000000))
|
|
|
|
embed.add_field(name=f"{(_('command_about_embed_field1'))}", value=f"{NAME}", inline=False)
|
|
|
|
embed.add_field(name=f"{(_('command_about_embed_field2name'))}", value=f"{(_('command_about_embed_field2value')).format(local_version=local_version, latest_version=latest_version)}", inline=False)
|
2025-07-18 01:36:16 +02:00
|
|
|
embed.add_field(name=f"Git", value=get_git_remote_url())
|
2025-07-18 01:31:46 +02:00
|
|
|
embed.add_field(name=f"OS", value=platform.platform())
|
2025-07-09 22:57:59 +02:00
|
|
|
|
2025-01-05 21:03:49 +01:00
|
|
|
await send_message(ctx, embed=embed)
|
|
|
|
|
|
|
|
@bot.hybrid_command(description="stats")
|
2025-07-05 20:15:54 +02:00
|
|
|
async def stats(ctx: commands.Context) -> None:
|
2025-01-05 21:03:49 +01:00
|
|
|
if ctx.author.id != ownerid:
|
|
|
|
return
|
2025-07-05 20:15:54 +02:00
|
|
|
latest_version: str = check_for_update()
|
|
|
|
memory_file: str = 'memory.json'
|
|
|
|
file_size: int = os.path.getsize(memory_file)
|
2025-01-05 21:03:49 +01:00
|
|
|
|
|
|
|
with open(memory_file, 'r') as file:
|
2025-07-05 20:15:54 +02:00
|
|
|
line_count: int = sum(1 for _ in file)
|
|
|
|
|
|
|
|
embed: discord.Embed = discord.Embed(title=f"{(_('command_stats_embed_title'))}", description=f"{(_('command_stats_embed_desc'))}", color=Colour(0x000000))
|
|
|
|
embed.add_field(name=f"{(_('command_stats_embed_field1name'))}", value=f"{(_('command_stats_embed_field1value')).format(file_size=file_size, line_count=line_count)}", inline=False)
|
|
|
|
embed.add_field(name=f"{(_('command_stats_embed_field2name'))}", value=f"{(_('command_stats_embed_field2value')).format(local_version=local_version, latest_version=latest_version)}", inline=False)
|
2025-07-07 20:41:24 +02:00
|
|
|
embed.add_field(name=f"{(_('command_stats_embed_field3name'))}", value=f"{(_('command_stats_embed_field3value')).format(NAME=NAME, PREFIX=PREFIX, ownerid=ownerid, PING_LINE=PING_LINE, showmemenabled=showmemenabled, USERTRAIN_ENABLED=USERTRAIN_ENABLED, song=song, splashtext=splashtext)}", inline=False)
|
2025-07-18 01:33:01 +02:00
|
|
|
embed.add_field(name=f"OS", value=platform.platform())
|
|
|
|
embed.add_field(name="Python Version", value=platform.python_version())
|
2025-01-05 21:03:49 +01:00
|
|
|
await send_message(ctx, embed=embed)
|
|
|
|
|
|
|
|
@bot.hybrid_command()
|
2025-07-05 20:15:54 +02:00
|
|
|
async def mem(ctx: commands.Context) -> None:
|
2025-01-05 21:03:49 +01:00
|
|
|
if showmemenabled != "true":
|
|
|
|
return
|
|
|
|
|
2025-07-23 13:38:09 +02:00
|
|
|
with open("memory.json", "rb") as file:
|
|
|
|
files = {
|
|
|
|
"fileToUpload": file
|
|
|
|
}
|
|
|
|
data = {
|
|
|
|
"reqtype": "fileupload",
|
|
|
|
"time": "1h"
|
|
|
|
}
|
|
|
|
|
|
|
|
try:
|
|
|
|
response = requests.post("https://litterbox.catbox.moe/resources/internals/api.php", files=files, data=data)
|
|
|
|
response.raise_for_status()
|
|
|
|
await send_message(ctx, response.text.strip())
|
|
|
|
except requests.RequestException as e:
|
|
|
|
logger.error(f"Upload failed: {e}")
|
|
|
|
await send_message(ctx, "Upload failed.")
|
|
|
|
|
2025-07-05 20:15:54 +02:00
|
|
|
def improve_sentence_coherence(sentence: str) -> str:
|
2025-01-05 21:03:49 +01:00
|
|
|
return sentence
|
|
|
|
|
2025-06-22 19:07:41 +02:00
|
|
|
# Start the bot
|
2025-07-05 20:15:54 +02:00
|
|
|
bot.run(TOKEN)
|