def get_tunnels(self): try: return str(ngrok.get_tunnels()) except Exception as e: logger.exception(e) return self.error.format(e)
def _start_plugins(self): self.plugins.autoload() while True: line = self.lines.get() logger.debug("Plugin handle line: <{}>".format(len(self.plugins.plugins()))) for name,mod in self.plugins.plugins(): logger.debug("<{}> handle_line".format(name)) try: mod.handle_line(line) except: logger.exception("Plugin threw an exception!\n{}\n{}".format(name,line))
def start_tunnel(self, command): try: command = command.split() port = command[1] protocol = command[2] ngrok_tunnel = ngrok.connect(port, protocol) return ngrok_tunnel except Exception as e: logger.exception(e) return self.error.format(e)
def delete_tunnels(self): try: for tunnel in ngrok.get_tunnels(): ngrok.disconnect(tunnel.public_url) if not ngrok.get_tunnels(): return 'All active Ngrok tunnels delete successfully!' return 'Something went wrong deleting the Ngrok tunnels!' except Exception as e: logger.exception(e) return self.error.format(e)
def _start_plugins(self): self.plugins.autoload() while True: line = self.lines.get() logger.debug("Plugin handle line: <{}>".format( len(self.plugins.plugins()))) for name, mod in self.plugins.plugins(): logger.debug("<{}> handle_line".format(name)) try: mod.handle_line(line) except: logger.exception( "Plugin threw an exception!\n{}\n{}".format( name, line))
async def on_message(self, message): logger.info(f'[MESSAGE]: {message.content}') if message.author == self.user: return command = message.content if not command: return if command.startswith('bot help'): try: await message.channel.send(""" Commands: - Any linux command (Restricted to 2000 lines) - ngrok <port> <protocol> (Starts tunnel) - get ngrok (Shows all tunnels) - delete ngrok (Deletes all tunnels) """) return except Exception as e: await message.channel.send(error.format(e)) return if command.startswith('ngrok'): response = ngrok.start_tunnel(command) await message.channel.send(response) return if command.startswith('get ngrok'): response = ngrok.get_tunnels() await message.channel.send(response) return if command.startswith('delete ngrok'): response = ngrok.delete_tunnels() await message.channel.send(response) return try: output = subprocess.Popen( command.split(), stdout=subprocess.PIPE, cwd=os.getcwd(), bufsize=-1, encoding='utf-8' ) for line in iter(output.stdout.readline, b''): try: await message.channel.send(line) except: pass return except Exception as e: logger.exception(e) await message.channel.send(error.format(e)) return
def load(self,name): logger.debug("Loading <{}>".format(name)) try: self.loaded[name]=__import__(name) except: logger.exception("Failed to load <{}>".format(name))
def load(self, name): logger.debug("Loading <{}>".format(name)) try: self.loaded[name] = __import__(name) except: logger.exception("Failed to load <{}>".format(name))