Beispiel #1
0
    async def close(self, client, message, parameters):
        session = SessionManager.get_session(message.channel)

        if session:
            await client.delete_message(session.message)
            SessionManager.delete_session(session)
        else:
            await client.send_message(
                message.channel,
                ":no_entry_sign: You are trying to close non-existing session")
Beispiel #2
0
    async def killall(self, client, message, parameters):
        if has_permission("session.killall", message.author, message.channel):
            for session in SessionManager.sessions:
                SessionManager.delete_session(session)

            await client.send_message(message.channel, "Killed all sessions")
        else:
            await client.send_message(
                message.channel,
                ":lock: You don't have permission to use this command")
Beispiel #3
0
    async def on_message(message):
        if message.author.bot:
            return

        session = SessionManager.get_session(message.channel)

        if is_command(message):
            success = await commands_manager.execute(client, message)
            if not success and session and session.status != "frozen":
                session.send_input(message.content)

            await cleanup(message)

        elif session and session.status != "frozen":
            if message.content.endswith(settings.get("redirect_tag")):
                session.send_input(
                    message.content[:-len(settings.get("redirect_tag"))])

                await cleanup(message)

            else:
                short_tag = settings.get("short_tag").split("*")

                if short_tag[0] in message.content:
                    command = message.content[message.content.
                                              index(short_tag[0]) +
                                              len(short_tag[0]):]
                    command = command[:command.index(short_tag[1])]
                    session.send_input(command)

                    await cleanup(message)

        if not has_permission("chat.write", message.author, message.channel):
            await cleanup(message)
Beispiel #4
0
    async def remove(self, client, message, parameters):
        session = SessionManager.get_session(message.channel)

        if session:
            remove_control(parameters["emoji_id"], session)
        else:
            await client.send_message(
                message.channel,
                ":no_entry_sign: You are trying to remove controls from non-existing session"
            )
Beispiel #5
0
    async def add(self, client, message, parameters):
        session = SessionManager.get_session(message.channel)

        if session:
            add_control(parameters["emoji_id"], parameters["content"], session)
        else:
            await client.send_message(
                message.channel,
                ":no_entry_sign: You are trying to add controls to non-existing session"
            )
Beispiel #6
0
    async def kill(self, client, message, parameters):
        if has_permission("session.kill", message.author, message.channel):
            session = SessionManager.get(parameters["name"])

            if session:
                session.status = "killed"
                session.send_output(asyncio.get_event_loop())
                SessionManager.delete_session(session)

                await client.send_message(message.channel, "Session killed")
            else:
                await client.send_message(
                    message.channel,
                    ":no_entry_sign: You are trying to close non-existing session"
                )
        else:
            await client.send_message(
                message.channel,
                ":lock: You don't have permission to use this command")
Beispiel #7
0
    async def repeat(self, client, message, parameters):
        session = SessionManager.get_session(message.channel)

        if session:
            session.send_input(parameters['text'] * int(parameters['times']))
        else:
            await client.send_message(
                message.channel,
                ":no_entry_sign: You are trying to send input to non-existing session"
            )
Beispiel #8
0
    async def rename(self, client, message, parameters):
        session = SessionManager.get_session(message.channel)

        if session:
            if not len(parameters["new_name"]) > 20:
                session.name = parameters["new_name"]
            else:
                await client.send_message(message.channel, ":no_entry_sign: Maximum length of session name is 20. Your is: %s" % len(parameters["name"]))
                return

            session.send_output(asyncio.get_event_loop())
        else:
            await client.send_message(message.channel, ":no_entry_sign: You are trying to freeze non-existing session")
Beispiel #9
0
    async def show(self, client, message, parameters):
        session = SessionManager.get_session(message.channel)
        controls = ""

        if session:
            for key, value in list(session.controls.items()):
                controls += "%s = %s\n" % (key, value)

            await client.send_message(message.channel, controls)
        else:
            await client.send_message(
                message.channel,
                ":no_entry_sign: You are trying to show controls of non-existing session"
            )
Beispiel #10
0
    async def freeze(self, client, message, parameters):
        session = SessionManager.get_session(message.channel)

        if session:
            if session.status == "frozen":
                session.status = "working"
            else:
                session.status = "frozen"

            session.send_output(asyncio.get_event_loop())
        else:
            await client.send_message(
                message.channel,
                ":no_entry_sign: You are trying to freeze non-existing session"
            )
Beispiel #11
0
def on_reaction_click(reaction, user):
    if user == bot.client.user:
        return

    session = SessionManager.get_by_message(reaction.message)

    if not session or not session.controls:
        return

    if reaction.emoji in session.controls:
        data = session.controls[reaction.emoji]
        session.send_input(data)

        print("%s @ %s[%s] [REACTION]: %s" % (user.name, reaction.message.channel.name,
                                   (reaction.message.channel.server.name if hasattr(reaction.message.channel, "server") else "PM"),
                                   data.encode("utf-8")))
Beispiel #12
0
    async def open(self, client, message, parameters):
        loop = asyncio.get_event_loop()
        session_name = None

        if "name" in list(parameters.keys()):
            if not len(parameters["name"]) > 20:
                session_name = parameters["name"]
            else:
                await client.send_message(
                    message.channel,
                    ":no_entry_sign: Maximum length of session name is 20. Your is: %s"
                    % len(parameters["name"]))
                return

        session = SessionManager.create_session(client, message, session_name)

        session.message = await client.send_message(
            message.channel,
            bot.settings.get("terminal_template") %
            (session.name, "Opening", "Waiting for tty..\n" +
             ((" " * 80) + "\n") * 23))

        session.open(loop)
Beispiel #13
0
 async def select(self, client, message, parameters):
     SessionManager.select(parameters["name"], message.channel)