turned it into a cog

made admin id a single list of ids now
This commit is contained in:
phixxy 2024-01-24 23:43:43 -08:00
parent 97dfc90d75
commit fd68dd1718

View file

@ -2,15 +2,13 @@
import os import os
import sys import sys
import subprocess import subprocess
import asyncssh
from discord.ext import commands from discord.ext import commands
async def upload_sftp(local_filename, server_folder, server_filename): class Admin(commands.Cog):
remotepath = server_folder + server_filename
async with asyncssh.connect(os.getenv('ftp_server'), username=os.getenv('ftp_username'), password=os.getenv('ftp_password')) as conn: def __init__(self, bot):
async with conn.start_sftp_client() as sftp: self.bot = bot
await sftp.put(local_filename, remotepath=remotepath) self.admin_ids = [242018983241318410]
@commands.command( @commands.command(
description="Kill", description="Kill",
@ -18,9 +16,9 @@ async def upload_sftp(local_filename, server_folder, server_filename):
brief="Kill the bot", brief="Kill the bot",
hidden=True hidden=True
) )
async def kill(ctx): async def kill(self, ctx):
"Kills the bot" "Kills the bot"
if ctx.author.id == 242018983241318410: if ctx.author.id in self.admin_ids:
exit() exit()
else: else:
await ctx.channel.send("You don't have permission to do that.") await ctx.channel.send("You don't have permission to do that.")
@ -31,8 +29,8 @@ async def kill(ctx):
brief="Reset the bot", brief="Reset the bot",
hidden=True hidden=True
) )
async def reset(ctx): async def reset(self, ctx):
if ctx.author.id == 242018983241318410: if ctx.author.id in self.admin_ids:
python = sys.executable python = sys.executable
os.execl(python, python, *sys.argv) os.execl(python, python, *sys.argv)
else: else:
@ -44,8 +42,8 @@ async def reset(ctx):
brief="Runs git pull", brief="Runs git pull",
hidden=True hidden=True
) )
async def update(ctx): async def update(self, ctx):
if ctx.author.id == 242018983241318410: if ctx.author.id in self.admin_ids:
output = subprocess.run(["git","pull"],capture_output=True) output = subprocess.run(["git","pull"],capture_output=True)
if output.stderr: if output.stderr:
await ctx.send("Update Attempted") await ctx.send("Update Attempted")
@ -56,6 +54,4 @@ async def update(ctx):
await ctx.send("You don't have permission to do this.") await ctx.send("You don't have permission to do this.")
async def setup(bot): async def setup(bot):
bot.add_command(update) await bot.add_cog(Admin(bot))
bot.add_command(reset)
bot.add_command(kill)