From 2e0e3cc2e45f35236a43afa5afb5122b9d033fb6 Mon Sep 17 00:00:00 2001 From: karenleewaddell Date: Mon, 1 Jun 2020 21:18:16 +1000 Subject: [PATCH] add shutdown command --- deviceM2.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/deviceM2.py b/deviceM2.py index 56e40cc..2cce50e 100755 --- a/deviceM2.py +++ b/deviceM2.py @@ -77,6 +77,24 @@ async def reboot(ctx, device): await bot.send_message(discord.Object(id=bot_channel), stdout.decode("utf-8") ) except: await bot.send_message(discord.Object(id=bot_channel), "No device named " + name + " found.") + +@bot.command(pass_context=True) +async def shutdown(ctx, device): + """(p)shutdown - shutdown device. Replace with to shutdown all devices.""" + name = str(device) + if name == 'all': + for d in devices: + dname = devices[d] + MyOut = subprocess.Popen(['idevicediagnostics', '-u', dname, 'shutdown'],stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + stdout,stderr = MyOut.communicate() + await bot.send_message(discord.Object(id=bot_channel), stdout.decode("utf-8") ) + else: + try: + MyOut = subprocess.Popen(['idevicediagnostics', '-u', devices.get(name), 'shutdown'],stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + stdout,stderr = MyOut.communicate() + await bot.send_message(discord.Object(id=bot_channel), stdout.decode("utf-8") ) + except: + await bot.send_message(discord.Object(id=bot_channel), "No device named " + name + " found.") @bot.command(pass_context=True) async def sc(ctx, device):