#!/usr/bin/env python

import importlib
import logging

from Legobot.Lego import Lego
from Legobot.Utilities import Utilities

__author__ = "Nitrax <nitrax@lokisec.fr>"
__copyright__ = "Copyright 2017, Legobot"

logger = logging.getLogger(__name__)


class LegoNettools(Lego):
    """LegoNettols provides support for any networking tools.

    Args:
        Lego: Lego
    """

    @staticmethod
    def listening_for(message):
        """Check if the message contains a command that LegoNettools support.

        Args:
            message: The message send by the Legobot framework

        Returns:
            Bool: Return True if the command is supported
        """

        if Utilities.isNotEmpty(message['text']):
            cmds = ['!whois', '!geoloc', '!ping']
            return message['text'].split()[0] in cmds

    def handle(self, message):
        """Generate and execute the class corresponding to the asked command.

        Args:
            self: self
            message: The message send by the Legobot framework
        """

        tokens = message['text'].split()
        _class = self._factory(tokens[0])

        if ' ' in message['text']:
            if len(tokens) >= 2:
                self.reply(message,  _class(tokens[1:len(tokens)]).run(),
                           self._handle_opts(message))
        else:
            self.reply(message, 'Usage :' + _class(None).getHelp(),
                       self._handle_opts(message))

    def _factory(self, cmd):
        cmd = cmd.replace('!', '')
        _class = str.capitalize(cmd)

        logger.debug('Nettools try to instantiate the ' + _class + ' class')
        return getattr(importlib.import_module('legos.tools.' + _class),
                       _class)

    def _handle_opts(self, message):
        """Identify and set the message sourche channel.

        Args:
            self: self
            message: The message send by the Legobot framework

        Returns:
            Array: Options needed to send back the response to the
                Legobot framework
        """

        try:
            target = message['metadata']['source_channel']
            opts = {'target': target}
        except IndexError:
            opts = None
            logger.error('''Could not identify message source in message:
                                    {}'''.format(str(message)))

        return opts

    @staticmethod
    def get_name():
        """Get the class name.

        Args:
            self: self

        Returns:
            str: Class name
        """

        return 'nettools'

    @staticmethod
    def get_help():
        """Get helper

        Args:
            self: self

        Returns:
            str: Helper
        """

        help_text = '[!whois, !geoloc, !ping] for further information'

        return help_text

93ba31350da55a08c313f6c730cfd6f0e425675d
<mask token>


class LegoNettools(Lego):
    <mask token>
    <mask token>

    def handle(self, message):
        """Generate and execute the class corresponding to the asked command.

        Args:
            self: self
            message: The message send by the Legobot framework
        """
        tokens = message['text'].split()
        _class = self._factory(tokens[0])
        if ' ' in message['text']:
            if len(tokens) >= 2:
                self.reply(message, _class(tokens[1:len(tokens)]).run(),
                    self._handle_opts(message))
        else:
            self.reply(message, 'Usage :' + _class(None).getHelp(), self.
                _handle_opts(message))
    <mask token>

    def _handle_opts(self, message):
        """Identify and set the message sourche channel.

        Args:
            self: self
            message: The message send by the Legobot framework

        Returns:
            Array: Options needed to send back the response to the
                Legobot framework
        """
        try:
            target = message['metadata']['source_channel']
            opts = {'target': target}
        except IndexError:
            opts = None
            logger.error(
                """Could not identify message source in message:
                                    {}"""
                .format(str(message)))
        return opts

    @staticmethod
    def get_name():
        """Get the class name.

        Args:
            self: self

        Returns:
            str: Class name
        """
        return 'nettools'

    @staticmethod
    def get_help():
        """Get helper

        Args:
            self: self

        Returns:
            str: Helper
        """
        help_text = '[!whois, !geoloc, !ping] for further information'
        return help_text

<mask token>


class LegoNettools(Lego):
    <mask token>
    <mask token>

    def handle(self, message):
        """Generate and execute the class corresponding to the asked command.

        Args:
            self: self
            message: The message send by the Legobot framework
        """
        tokens = message['text'].split()
        _class = self._factory(tokens[0])
        if ' ' in message['text']:
            if len(tokens) >= 2:
                self.reply(message, _class(tokens[1:len(tokens)]).run(),
                    self._handle_opts(message))
        else:
            self.reply(message, 'Usage :' + _class(None).getHelp(), self.
                _handle_opts(message))

    def _factory(self, cmd):
        cmd = cmd.replace('!', '')
        _class = str.capitalize(cmd)
        logger.debug('Nettools try to instantiate the ' + _class + ' class')
        return getattr(importlib.import_module('legos.tools.' + _class), _class
            )

    def _handle_opts(self, message):
        """Identify and set the message sourche channel.

        Args:
            self: self
            message: The message send by the Legobot framework

        Returns:
            Array: Options needed to send back the response to the
                Legobot framework
        """
        try:
            target = message['metadata']['source_channel']
            opts = {'target': target}
        except IndexError:
            opts = None
            logger.error(
                """Could not identify message source in message:
                                    {}"""
                .format(str(message)))
        return opts

    @staticmethod
    def get_name():
        """Get the class name.

        Args:
            self: self

        Returns:
            str: Class name
        """
        return 'nettools'

    @staticmethod
    def get_help():
        """Get helper

        Args:
            self: self

        Returns:
            str: Helper
        """
        help_text = '[!whois, !geoloc, !ping] for further information'
        return help_text

<mask token>


class LegoNettools(Lego):
    <mask token>

    @staticmethod
    def listening_for(message):
        """Check if the message contains a command that LegoNettools support.

        Args:
            message: The message send by the Legobot framework

        Returns:
            Bool: Return True if the command is supported
        """
        if Utilities.isNotEmpty(message['text']):
            cmds = ['!whois', '!geoloc', '!ping']
            return message['text'].split()[0] in cmds

    def handle(self, message):
        """Generate and execute the class corresponding to the asked command.

        Args:
            self: self
            message: The message send by the Legobot framework
        """
        tokens = message['text'].split()
        _class = self._factory(tokens[0])
        if ' ' in message['text']:
            if len(tokens) >= 2:
                self.reply(message, _class(tokens[1:len(tokens)]).run(),
                    self._handle_opts(message))
        else:
            self.reply(message, 'Usage :' + _class(None).getHelp(), self.
                _handle_opts(message))

    def _factory(self, cmd):
        cmd = cmd.replace('!', '')
        _class = str.capitalize(cmd)
        logger.debug('Nettools try to instantiate the ' + _class + ' class')
        return getattr(importlib.import_module('legos.tools.' + _class), _class
            )

    def _handle_opts(self, message):
        """Identify and set the message sourche channel.

        Args:
            self: self
            message: The message send by the Legobot framework

        Returns:
            Array: Options needed to send back the response to the
                Legobot framework
        """
        try:
            target = message['metadata']['source_channel']
            opts = {'target': target}
        except IndexError:
            opts = None
            logger.error(
                """Could not identify message source in message:
                                    {}"""
                .format(str(message)))
        return opts

    @staticmethod
    def get_name():
        """Get the class name.

        Args:
            self: self

        Returns:
            str: Class name
        """
        return 'nettools'

    @staticmethod
    def get_help():
        """Get helper

        Args:
            self: self

        Returns:
            str: Helper
        """
        help_text = '[!whois, !geoloc, !ping] for further information'
        return help_text

<mask token>
__author__ = 'Nitrax <nitrax@lokisec.fr>'
__copyright__ = 'Copyright 2017, Legobot'
logger = logging.getLogger(__name__)


class LegoNettools(Lego):
    """LegoNettols provides support for any networking tools.

    Args:
        Lego: Lego
    """

    @staticmethod
    def listening_for(message):
        """Check if the message contains a command that LegoNettools support.

        Args:
            message: The message send by the Legobot framework

        Returns:
            Bool: Return True if the command is supported
        """
        if Utilities.isNotEmpty(message['text']):
            cmds = ['!whois', '!geoloc', '!ping']
            return message['text'].split()[0] in cmds

    def handle(self, message):
        """Generate and execute the class corresponding to the asked command.

        Args:
            self: self
            message: The message send by the Legobot framework
        """
        tokens = message['text'].split()
        _class = self._factory(tokens[0])
        if ' ' in message['text']:
            if len(tokens) >= 2:
                self.reply(message, _class(tokens[1:len(tokens)]).run(),
                    self._handle_opts(message))
        else:
            self.reply(message, 'Usage :' + _class(None).getHelp(), self.
                _handle_opts(message))

    def _factory(self, cmd):
        cmd = cmd.replace('!', '')
        _class = str.capitalize(cmd)
        logger.debug('Nettools try to instantiate the ' + _class + ' class')
        return getattr(importlib.import_module('legos.tools.' + _class), _class
            )

    def _handle_opts(self, message):
        """Identify and set the message sourche channel.

        Args:
            self: self
            message: The message send by the Legobot framework

        Returns:
            Array: Options needed to send back the response to the
                Legobot framework
        """
        try:
            target = message['metadata']['source_channel']
            opts = {'target': target}
        except IndexError:
            opts = None
            logger.error(
                """Could not identify message source in message:
                                    {}"""
                .format(str(message)))
        return opts

    @staticmethod
    def get_name():
        """Get the class name.

        Args:
            self: self

        Returns:
            str: Class name
        """
        return 'nettools'

    @staticmethod
    def get_help():
        """Get helper

        Args:
            self: self

        Returns:
            str: Helper
        """
        help_text = '[!whois, !geoloc, !ping] for further information'
        return help_text

#!/usr/bin/env python

import importlib
import logging

from Legobot.Lego import Lego
from Legobot.Utilities import Utilities

__author__ = "Nitrax <nitrax@lokisec.fr>"
__copyright__ = "Copyright 2017, Legobot"

logger = logging.getLogger(__name__)


class LegoNettools(Lego):
    """LegoNettols provides support for any networking tools.

    Args:
        Lego: Lego
    """

    @staticmethod
    def listening_for(message):
        """Check if the message contains a command that LegoNettools support.

        Args:
            message: The message send by the Legobot framework

        Returns:
            Bool: Return True if the command is supported
        """

        if Utilities.isNotEmpty(message['text']):
            cmds = ['!whois', '!geoloc', '!ping']
            return message['text'].split()[0] in cmds

    def handle(self, message):
        """Generate and execute the class corresponding to the asked command.

        Args:
            self: self
            message: The message send by the Legobot framework
        """

        tokens = message['text'].split()
        _class = self._factory(tokens[0])

        if ' ' in message['text']:
            if len(tokens) >= 2:
                self.reply(message,  _class(tokens[1:len(tokens)]).run(),
                           self._handle_opts(message))
        else:
            self.reply(message, 'Usage :' + _class(None).getHelp(),
                       self._handle_opts(message))

    def _factory(self, cmd):
        cmd = cmd.replace('!', '')
        _class = str.capitalize(cmd)

        logger.debug('Nettools try to instantiate the ' + _class + ' class')
        return getattr(importlib.import_module('legos.tools.' + _class),
                       _class)

    def _handle_opts(self, message):
        """Identify and set the message sourche channel.

        Args:
            self: self
            message: The message send by the Legobot framework

        Returns:
            Array: Options needed to send back the response to the
                Legobot framework
        """

        try:
            target = message['metadata']['source_channel']
            opts = {'target': target}
        except IndexError:
            opts = None
            logger.error('''Could not identify message source in message:
                                    {}'''.format(str(message)))

        return opts

    @staticmethod
    def get_name():
        """Get the class name.

        Args:
            self: self

        Returns:
            str: Class name
        """

        return 'nettools'

    @staticmethod
    def get_help():
        """Get helper

        Args:
            self: self

        Returns:
            str: Helper
        """

        help_text = '[!whois, !geoloc, !ping] for further information'

        return help_text
