commit before utter laptop death
This commit is contained in:
parent
4e111b410d
commit
d6b51c787a
11 changed files with 163 additions and 221 deletions
|
@ -1,20 +1,17 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from modules.globalvars import ownerid
|
||||
from modules.permission import requires_admin
|
||||
class FileSync(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.mode = None
|
||||
self.peer_id = None
|
||||
self.awaiting_file = False
|
||||
|
||||
@requires_admin()
|
||||
@commands.command()
|
||||
async def syncfile(self, ctx, mode: str, peer: discord.User):
|
||||
self.mode = mode.lower()
|
||||
self.peer_id = peer.id
|
||||
if ctx.author.id != ownerid:
|
||||
await ctx.send("You don't have permission to execute this command.")
|
||||
return
|
||||
if self.mode == "s":
|
||||
await ctx.send(f"<@{self.peer_id}> FILE_TRANSFER_REQUEST")
|
||||
await ctx.send(file=discord.File("memory.json"))
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
from typing import Dict, List
|
||||
import discord
|
||||
from discord import Colour
|
||||
from discord.ext import commands
|
||||
import discord.ext
|
||||
import discord.ext.commands
|
||||
from modules.globalvars import local_version
|
||||
from modules.volta.main import _ , set_language
|
||||
from modules.permission import requires_admin
|
||||
from modules.sentenceprocessing import send_message
|
||||
from modules.settings import instance as settings_manager
|
||||
from modules.version import check_for_update
|
||||
|
||||
import requests
|
||||
|
||||
settings = settings_manager.settings
|
||||
|
@ -21,13 +26,21 @@ def get_git_origin_raw():
|
|||
)
|
||||
return result.stdout.strip()
|
||||
except Exception:
|
||||
return "http://forgejo.expect.ovh/gooberinc/goober"
|
||||
return "Failed to get git origin"
|
||||
|
||||
class BaseCommands(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot: discord.ext.commands.Bot = bot
|
||||
|
||||
|
||||
def get_git_origin_raw():
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["git", "config", "--get", "remote.origin.url"],
|
||||
capture_output=True, text=True, check=True
|
||||
)
|
||||
return result.stdout.strip()
|
||||
except Exception:
|
||||
return "https://forgejo.expect.ovh/gooberinc/goober" # fallback if git fails
|
||||
|
||||
@commands.command()
|
||||
async def help(self, ctx: commands.Context) -> None:
|
||||
|
@ -111,19 +124,13 @@ class BaseCommands(commands.Cog):
|
|||
|
||||
@commands.command()
|
||||
async def about(self, ctx: commands.Context) -> None:
|
||||
embed: discord.Embed = discord.Embed(
|
||||
title=f"{_('command_about_embed_title')}",
|
||||
description="",
|
||||
color=discord.Colour(0x000000),
|
||||
)
|
||||
|
||||
embed.add_field(
|
||||
name=_('command_about_embed_field1'),
|
||||
value=settings['name'],
|
||||
inline=False,
|
||||
)
|
||||
|
||||
embed.add_field(name="Git", value=get_git_origin_raw())
|
||||
latest_version: str = check_for_update(slient=True)
|
||||
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"{settings['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)
|
||||
embed.add_field(name=f"Git", value=get_git_origin_raw())
|
||||
embed.add_field(name=f"OS", value=platform.platform())
|
||||
|
||||
await send_message(ctx, embed=embed)
|
||||
|
||||
@commands.command()
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from modules.globalvars import ownerid
|
||||
from modules.permission import requires_admin
|
||||
|
||||
COG_PREFIX = "assets.cogs."
|
||||
|
||||
class CogManager(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@requires_admin()
|
||||
@commands.command()
|
||||
async def load(self, ctx, cog_name: str = None):
|
||||
if ctx.author.id != ownerid:
|
||||
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 load.")
|
||||
return
|
||||
|
@ -21,12 +18,9 @@ class CogManager(commands.Cog):
|
|||
await ctx.send(f"Loaded cog `{cog_name}` successfully.")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error loading cog `{cog_name}`: {e}")
|
||||
|
||||
@requires_admin()
|
||||
@commands.command()
|
||||
async def unload(self, ctx, cog_name: str = None):
|
||||
if ctx.author.id != ownerid:
|
||||
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 unload.")
|
||||
return
|
||||
|
@ -35,12 +29,9 @@ class CogManager(commands.Cog):
|
|||
await ctx.send(f"Unloaded cog `{cog_name}` successfully.")
|
||||
except Exception as e:
|
||||
await ctx.send(f"Error unloading cog `{cog_name}`: {e}")
|
||||
|
||||
@requires_admin()
|
||||
@commands.command()
|
||||
async def reload(self, ctx, cog_name: str = None):
|
||||
if ctx.author.id != ownerid:
|
||||
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
|
|
@ -32,11 +32,12 @@ settings = settings_manager.settings
|
|||
class Markov(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot: discord.ext.commands.Bot = bot
|
||||
self.model: markovify.NewlineText
|
||||
|
||||
|
||||
@requires_admin()
|
||||
@commands.command()
|
||||
async def retrain(self, ctx: discord.ext.commands.Context):
|
||||
markov_model: Optional[markovify.Text] = load_markov_model()
|
||||
message_ref: discord.Message | None = await send_message(
|
||||
ctx, f"{_('command_markov_retrain')}"
|
||||
)
|
||||
|
@ -71,8 +72,8 @@ class Markov(commands.Cog):
|
|||
await ctx.send("Failed to retrain!")
|
||||
return False
|
||||
|
||||
self.model = model
|
||||
save_markov_model(self.model)
|
||||
markov_model = model
|
||||
save_markov_model(markov_model)
|
||||
|
||||
logger.debug(f"Completed retraining in {round(time.time() - start_time,3)}s")
|
||||
|
||||
|
@ -86,33 +87,25 @@ class Markov(commands.Cog):
|
|||
|
||||
@commands.command()
|
||||
async def talk(self, ctx: commands.Context, sentence_size: int = 5) -> None:
|
||||
if not self.model:
|
||||
await send_message(ctx, f"{_('command_markovcommand_talk_insufficent_text')}")
|
||||
markov_model: Optional[markovify.Text] = load_markov_model()
|
||||
if markov_model is None:
|
||||
await send_message(ctx, _("command_markovcommand_talk_insufficent_text"))
|
||||
return
|
||||
|
||||
response: str = ""
|
||||
raw_sentence = None
|
||||
if sentence_size == 1:
|
||||
response = (
|
||||
self.model.make_short_sentence(max_chars=100, tries=100)
|
||||
or _('command_markovcommand_talk_generation_fail')
|
||||
)
|
||||
|
||||
raw_sentence = markov_model.make_short_sentence(max_chars=100, tries=100)
|
||||
else:
|
||||
response = improve_sentence_coherence(
|
||||
self.model.make_sentence(tries=100, max_words=sentence_size)
|
||||
or _('command_talk_generation_fail')
|
||||
)
|
||||
raw_sentence = markov_model.make_sentence(tries=100, max_words=sentence_size)
|
||||
print(raw_sentence)
|
||||
|
||||
cleaned_response: str = re.sub(r"[^\w\s]", "", response).lower()
|
||||
coherent_response: str = rephrase_for_coherence(cleaned_response)
|
||||
if random.random() < 0.9 and is_positive(raw_sentence):
|
||||
gif_url = random.choice(settings["bot"]["misc"]["positive_gifs"])
|
||||
raw_sentence = f"{raw_sentence}\n[jif]({gif_url})"
|
||||
|
||||
if random.random() < 0.9 and is_positive(coherent_response):
|
||||
gif_url: str = random.choice(settings["bot"]["misc"]["positive_gifs"])
|
||||
os.environ["gooberlatestgen"] = raw_sentence
|
||||
await send_message(ctx, raw_sentence)
|
||||
|
||||
coherent_response = f"{coherent_response}\n[jif]({gif_url})"
|
||||
|
||||
os.environ["gooberlatestgen"] = coherent_response
|
||||
await send_message(ctx, coherent_response)
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
|
|
|
@ -15,18 +15,7 @@ class PermissionManager(commands.Cog):
|
|||
@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",
|
||||
|
@ -40,15 +29,6 @@ class PermissionManager(commands.Cog):
|
|||
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!")
|
||||
|
@ -90,15 +70,6 @@ class PermissionManager(commands.Cog):
|
|||
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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue