Browse Source

More cleanup.

main
Nichole Mattera 2 months ago
parent
commit
9cefe34255
2 changed files with 0 additions and 56 deletions
  1. +0
    -26
      cogs/admin.py
  2. +0
    -30
      cogs/common.py

+ 0
- 26
cogs/admin.py View File

@@ -27,32 +27,6 @@ class Admin(Cog):
await ctx.send(":wave: Goodbye!")
await self.bot.logout()

@commands.guild_only()
@commands.check(check_if_bot_manager)
@commands.command()
async def pull(self, ctx, auto=False):
"""Does a git pull, bot manager only."""
tmp = await ctx.send("Pulling...")
git_output = await self.bot.async_call_shell("git pull")
await tmp.edit(content=f"Pull complete. Output: ```{git_output}```")
if auto:
cogs_to_reload = re.findall(r"cogs/([a-z_]*).py[ ]*\|", git_output)
for cog in cogs_to_reload:
try:
self.bot.unload_extension("cogs." + cog)
self.bot.load_extension("cogs." + cog)
self.bot.log.info(f"Reloaded ext {cog}")
await ctx.send(
f":white_check_mark: `{cog}` " "successfully reloaded."
)
await self.cog_load_actions(cog)
except:
await ctx.send(
f":x: Cog reloading failed, traceback: "
f"```\n{traceback.format_exc()}\n```"
)
return

@commands.guild_only()
@commands.check(check_if_bot_manager)
@commands.command()


+ 0
- 30
cogs/common.py View File

@@ -6,7 +6,6 @@ class Common(Cog):
def __init__(self, bot):
self.bot = bot

self.bot.async_call_shell = self.async_call_shell
self.bot.escape_message = self.escape_message

def escape_message(self, text: str):
@@ -14,35 +13,6 @@ class Common(Cog):

return str(text).replace("@", "@ ").replace("<#", "# ")

async def async_call_shell(
self, shell_command: str, inc_stdout=True, inc_stderr=True
):
pipe = asyncio.subprocess.PIPE
proc = await asyncio.create_subprocess_shell(
str(shell_command), stdout=pipe, stderr=pipe
)

if not (inc_stdout or inc_stderr):
return "??? you set both stdout and stderr to False????"

proc_result = await proc.communicate()
stdout_str = proc_result[0].decode("utf-8").strip()
stderr_str = proc_result[1].decode("utf-8").strip()

if inc_stdout and not inc_stderr:
return stdout_str
elif inc_stderr and not inc_stdout:
return stderr_str

if stdout_str and stderr_str:
return f"stdout:\n\n{stdout_str}\n\n" f"======\n\nstderr:\n\n{stderr_str}"
elif stdout_str:
return f"stdout:\n\n{stdout_str}"
elif stderr_str:
return f"stderr:\n\n{stderr_str}"

return "No output."


def setup(bot):
bot.add_cog(Common(bot))

Loading…
Cancel
Save