Пример #1
0
    def update_message(self, terminal: Terminal, content: str):
        message = self.find_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)
Пример #2
0
    async def on_ready(self):
        self.__check_for_updates()

        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=Status.online,
                                   activity=Game(presence))
Пример #3
0
    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')

        login_as_other_user = settings().get(
            'terminal.user.login_as_other_user')
        if login_as_other_user:
            su_path = settings().get('terminal.su_path')
            login = settings().get('terminal.user.username')
            password = settings().get('terminal.user.password')

            terminal = Terminal(name,
                                sh_path=sh_path,
                                on_change=sessions().update_message,
                                su_path=su_path,
                                login=login,
                                password=password)
        else:
            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)