async def open(self, ctx, name: str = None): if name and len(name) > 20: raise ArgumentFormatException( 'Session name length exceeds 20 characters limit') # Auto-generated name if not name: name = str(len(sessions().sessions)) content = parse_template(settings().get('terminal.template'), name=name, state='OPENING', content='Waiting for tty..') message = await ctx.send(content) # Prepare terminal sh_path = settings().get('terminal.shell_path') terminal = Terminal(name, sh_path=sh_path, on_change=sessions().update_message) sessions().add(message, terminal) terminal.open() # Run macro on terminal startup startup_macro = settings().get('terminal.startup_macro') if startup_macro: await execute_macro(ctx, startup_macro)
async def on_ready(self): self.logger.info(f'Logged in as {self.user.name} ({self.user.id})') self.logger.info( f'You can add bot to your server via {oauth_url(self.user.id)}') presence = parse_template(settings().get("discord.presence"), prefix=self.command_prefix) await self.change_presence(status=discord.Status.online, activity=discord.Game(presence))
def update_message(self, terminal: Terminal, content: str): message = self.get_message(terminal) content = parse_template(settings().get('terminal.template'), name=terminal.name, state=terminal.state.name, content=block_escape(content)) execute_async(message.edit, content=content)