FIX: Added a force sync to at least my testing server for now
FEAT: Added better control over the notes and strikes.
This commit is contained in:
parent
bc4b0a916e
commit
19b48dd67d
46
commands.py
46
commands.py
@ -11,30 +11,33 @@ class ModCommands(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@app_commands.command(name="addnote", description="Add a note to a user")
|
||||
@app_commands.command(name="addnote",
|
||||
description="Add a note to a user and/or add strikes") # noqa: E501
|
||||
async def add_note(self, interaction: discord.Interaction,
|
||||
user: discord.User, note: str):
|
||||
user: discord.User, note: str, strikes: int = 0):
|
||||
async with aiosqlite.connect("ariella.db") as db:
|
||||
cursor = await db.execute(
|
||||
"SELECT notes FROM user_notes WHERE user_id = ?",
|
||||
"SELECT notes, strikes FROM user_notes WHERE user_id = ?",
|
||||
(user.id,)
|
||||
)
|
||||
row = await cursor.fetchone()
|
||||
if row:
|
||||
notes = row[0] + "\n" + note
|
||||
current_strikes = row[1] + strikes
|
||||
await db.execute(
|
||||
"UPDATE user_notes SET notes = ? WHERE user_id = ?",
|
||||
(notes, user.id)
|
||||
"UPDATE user_notes SET notes = ?,"
|
||||
"strikes = ? WHERE user_id = ?",
|
||||
(notes, current_strikes, user.id)
|
||||
)
|
||||
else:
|
||||
await db.execute(
|
||||
"INSERT INTO user_notes (user_id, notes, strikes) "
|
||||
"VALUES (?, ?, ?)",
|
||||
(user.id, note, 0)
|
||||
(user.id, note, strikes)
|
||||
)
|
||||
await db.commit()
|
||||
await interaction.response.send_message(
|
||||
f"Note added for {user.name}: {note}"
|
||||
f"Note added for {user.name}: {note}. Strikes: {strikes}"
|
||||
)
|
||||
|
||||
@app_commands.command(name="warn", description="Warn a user")
|
||||
@ -69,6 +72,32 @@ class ModCommands(commands.Cog):
|
||||
f"You now have {strikes} strikes."
|
||||
)
|
||||
|
||||
@app_commands.command(name="removestrikes",
|
||||
description="Remove strikes from a user")
|
||||
async def remove_strikes(self, interaction: discord.Interaction,
|
||||
user: discord.User, strikes: int):
|
||||
async with aiosqlite.connect("ariella.db") as db:
|
||||
cursor = await db.execute(
|
||||
"SELECT strikes FROM user_notes WHERE user_id = ?",
|
||||
(user.id,)
|
||||
)
|
||||
row = await cursor.fetchone()
|
||||
if row:
|
||||
current_strikes = max(row[0] - strikes, 0)
|
||||
await db.execute(
|
||||
"UPDATE user_notes SET strikes = ? WHERE user_id = ?",
|
||||
(current_strikes, user.id)
|
||||
)
|
||||
await db.commit()
|
||||
await interaction.response.send_message(
|
||||
f"Removed {strikes} strikes from {user.name}. "
|
||||
f"They now have {current_strikes} strikes."
|
||||
)
|
||||
else:
|
||||
await interaction.response.send_message(
|
||||
f"No strikes found for {user.name}."
|
||||
)
|
||||
|
||||
@app_commands.command(name="checknotes",
|
||||
description="Check notes and strikes of a user")
|
||||
async def check_notes(self, interaction: discord.Interaction,
|
||||
@ -95,7 +124,8 @@ class ModCommands(commands.Cog):
|
||||
async def update(self, interaction: discord.Interaction):
|
||||
await interaction.response.send_message("Updating the bot...")
|
||||
# Pull latest changes from the repository
|
||||
subprocess.run(["git", "pull"])
|
||||
repo_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
subprocess.run(["git", "-C", repo_dir, "pull"])
|
||||
# Restart the bot
|
||||
await interaction.followup.send("Restarting the bot...")
|
||||
os.execv(sys.executable, ['python'] + sys.argv)
|
||||
|
4
main.py
4
main.py
@ -10,6 +10,7 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv('DISCORD_TOKEN')
|
||||
GUILD_ID = int(os.getenv('GUILD_ID'))
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
@ -22,7 +23,8 @@ class Ariella(commands.Bot):
|
||||
|
||||
async def setup_hook(self):
|
||||
await self.load_extension('commands')
|
||||
await self.tree.sync()
|
||||
self.tree.copy_global_to(guild=discord.Object(id=GUILD_ID))
|
||||
await self.tree.sync(guild=discord.Object(id=GUILD_ID))
|
||||
|
||||
|
||||
bot = Ariella()
|
||||
|
Loading…
x
Reference in New Issue
Block a user