def getserverdir(self, dirname: str): """Get the directory of the given server.""" main_dir = self.server_data['meta']['directories']['main'] if dirname == 'main': return os.path.join(common.getbotdir(), "data", "servers", main_dir) else: server_dir = self.server_data['meta']['directories']['main'][ dirname] return os.path.join(common.getbotdir(), "data", "servers", main_dir, server_dir)
async def link(self, ctx, user: discord.User, github_profile): """Link a Discord user to a Github Profile for use with other commands.""" data = await common.loadjson( os.path.join(common.getbotdir(), "data", "data.json")) data['contributors'][user.id] = {} data['contributors'][user.id]['github'] = github_profile await common.dumpjson( data, os.path.join(common.getbotdir(), "data", "data.json")) embed = discord.Embed(color=ebed.randomrgb()) embed.description = "{} has been linked to the Github Profile '{}'".format( user.mention, github_profile) await ctx.send(embed=embed)
async def add(self, ctx, user: discord.User): """Add an admin.""" data = await common.loadjson("data/data.json") if user.id not in data['admins']: data['admins'].append(user.id) await common.dumpjson( data, os.path.join(common.getbotdir(), "data/data.json")) await ctx.send("{} is now a bot admin.".format(user.mention)) else: await ctx.send("{} is already a bot admin.".format(user.mention))
async def download(self, server_data: dict): """Initiates download functions for the given server.""" print("Running download") server_dir = common.makedir(self.getserverdir('main')) os.chdir(server_dir) file_dir = server_data['download']['file'] link = server_data['download']['link'] await common.download_file(link, file_dir) await self.run_command("setup") os.chdir(common.getbotdir())
async def getbotdir(self, ctx): """Get bot directory information.""" embed = discord.Embed(color=ebed.randomrgb()) embed.add_field(name="Bot Dir", value=common.getbotdir()) embed.add_field(name="Arg 0", value="name: {}".format(str(sys.argv[0]))) embed.add_field(name="Folder", value="name: {}".format( str(os.path.dirname(sys.argv[0])))) embed.add_field(name="Full Path", value=os.path.realpath(os.path.dirname(sys.argv[0]))) await ctx.send(embed=embed)
async def remove(self, ctx, user: discord.User): """Revoke admin permissions.""" data = await common.loadjson("data/data.json") embed = discord.Embed(color=ebed.randomrgb()) if user.id in data['admins']: data['admins'].pop(data['admins'].index(user.id)) await common.dumpjson( data, os.path.join(common.getbotdir(), "data/data.json")) embed.description = "{} is no longer a bot admin.".format( user.mention) else: embed.description = "{} is not a bot admin.".format(user.mention) await ctx.send(embed=embed)
async def server_cleanup(self): """Resets server-specific values after a server has terminated for any reason.""" if self.current_process is not None: if self.current_process.returncode is not None and hasattr( self.console_read, "finished"): self.server_data = None self.current_process = None self.current_console = None await self.bot.change_presence(activity=None) os.chdir(common.getbotdir()) print( "The running server has been terminated, resetting values." )
async def list(self, ctx): """List all servers available to launch.""" color = ebed.randomrgb() embed = discord.Embed(title="Servers Listed", color=color) count = 0 msg = "" for file in os.listdir(os.path.join(common.getbotdir(), "data", "json")): count += 1 msg += "\n**-** {}".format(os.path.splitext(file)[0]) embed.add_field(name="{} available".format(count), value=msg, inline=False) embed.set_footer(text=ebed.rgb_to_hex(color.to_rgb())) await ctx.send(embed=embed)
def __init__(self, bot): self.bot = bot self.sys_status = {} self.sys_monitor.start() self.platform = sys.platform self.data_path = common.getbotdir()
async def is_admin(ctx): program_dir = common.getbotdir() datafile = os.path.join(program_dir, "data/data.json") data = await common.loadjson(datafile) if ctx.author.id in data['admins']: return True
def getserverjson(server: str): path = os.path.join(common.getbotdir(), "data", "json", "{}.json".format(server)) return path