async def reboot(ctx, device): """(p)reboot <device_name> - reboot device. Replace <device_name> with <all> to reboot all devices.""" name = str(device) if name == 'all': for d in devices: dname = devices[d] MyOut = subprocess.Popen( ['idevicediagnostics', '-u', dname, 'restart'], 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), 'restart'], 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.")
async def delete(ctx, device, app): """(p)delete <device_name> <app_alias> - Delete app from device using alias defined in config. Replace <device_name> with <all> to delete app from all devices.""" name = str(device) alias = app_alias[app] try: if name == 'all': for d in devices: dname = devices[d] print(dname) MyOut = subprocess.Popen([ 'ideviceinstaller', '-u', dname, '--uninstall', str(alias) ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = MyOut.communicate() await bot.send_message(discord.Object(id=bot_channel), stdout.decode("utf-8")) else: MyOut = subprocess.Popen([ 'ideviceinstaller', '-u', devices.get(name), '--uninstall', str(alias) ], 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), "Error in device name or app not found.")
async def sc(ctx, device): """(p)sc <device_name> - Get screen capture of device and upload to channel.""" name = str(device) if name == 'all': for k, v in devices.items(): MyOut = subprocess.Popen( ['idevicescreenshot', '-u', v, k + '.png'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout = MyOut.communicate() await bot.send_file(discord.Object(id=bot_channel), k + '.png') await bot.send_message(discord.Object(id=bot_channel), k) else: try: MyOut = subprocess.Popen([ 'idevicescreenshot', '-u', devices.get(name), device + '.png' ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout = MyOut.communicate() await bot.send_file(discord.Object(id=bot_channel), name + '.png') except: await bot.send_message(discord.Object(id=bot_channel), "No device named " + name + " found.")
async def listapps(ctx, device): name = str(device) try: MyOut = subprocess.Popen( ['ideviceinstaller', '-u', devices.get(name), '--list-apps'], 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.")