class Plugin(BasePlugin):
    __name__ = "reddit"
    __version__ = "2015-08-02r05"
    __author__ = "Mutnick"
    __desc__ = """Displays topics and links for a requested subreddit."""
    settings = {'reddit_links': 3}
    metasettings = {
        'reddit_links': {
            "description": 'Maximum number of links to provide',
            'type': 'integer'
        }
    }

    def init(self):
        self.plugin_command = "!reddit"
        self.responder = ResponseThrottle(self.frame, self.__name__)

    def IncomingPublicChatEvent(self, room, nick, line):
        line = line.lower().strip()
        if line.startswith(self.plugin_command) and (" " in line):
            subreddit = line.split(" ")[1].strip("/")
            if self.responder.ok_to_respond(room, nick, subreddit):
                posts = feedparser.parse('https://www.reddit.com/r/' +
                                         subreddit + '/.rss')
                if posts.entries:
                    self.responder.responded()
                    for post in posts.entries[0:self.settings['reddit_links']]:
                        self.saypublic(
                            room, u"/me {}: {}".format(post.title, post.link))
예제 #2
0
class Plugin(BasePlugin):
    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        self.settings = {'reddit_links': 3}
        self.metasettings = {
            'reddit_links': {
                'description': 'Maximum number of links to provide',
                'type': 'integer'
            }
        }

        self.plugin_command = "!reddit"
        self.responder = ResponseThrottle(self.core, self.human_name)

    def incoming_public_chat_notification(self, room, user, line):
        line = line.lower().strip()

        if not line.startswith(self.plugin_command) or " " not in line:
            return

        subreddit = line.split(" ")[1].strip("/")

        if not self.responder.ok_to_respond(room, user, subreddit):
            return

        try:
            response = http_request(
                'https',
                'www.reddit.com',
                '/r/' + subreddit + '/.json',
                headers={"User-Agent": self.config.application_name})

        except Exception as error:
            self.log("Could not connect to Reddit: %(error)s",
                     {"error": error})
            return

        try:
            response = json.loads(response)

            for post in islice(response['data']['children'],
                               self.settings['reddit_links']):
                post_data = post['data']
                self.send_public(
                    room, "/me {}: {}".format(post_data['title'],
                                              post_data['url']))

        except Exception as error:
            self.log("Failed to parse response from Reddit: %(error)s",
                     {"error": error})
            return

        self.responder.responded()
예제 #3
0
    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        self.settings = {'replies': ['Test failed.']}
        self.metasettings = {
            'replies': {
                'description': 'Replies:',
                'type': 'list string'
            }
        }

        self.throttle = ResponseThrottle(self.core, self.human_name)
예제 #4
0
    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        self.settings = {'reddit_links': 3}
        self.metasettings = {
            'reddit_links': {
                'description': 'Maximum number of links to provide',
                'type': 'integer'
            }
        }

        self.plugin_command = "!reddit"
        self.responder = ResponseThrottle(self.core, self.human_name)
예제 #5
0
class Plugin(BasePlugin):

    __name__ = "Reddit"
    settings = {'reddit_links': 3}
    metasettings = {
        'reddit_links': {
            "description": 'Maximum number of links to provide',
            'type': 'integer'
        }
    }

    def init(self):
        self.plugin_command = "!reddit"
        self.responder = ResponseThrottle(self.core, self.__name__)

    @staticmethod
    def get_feed(domain, path):
        import http.client
        import json

        conn = http.client.HTTPSConnection(domain)
        conn.request("GET", path, headers={"User-Agent": "Nicotine+"})
        response = json.loads(conn.getresponse().read().decode("utf-8"))
        conn.close()

        return response

    def incoming_public_chat_event(self, room, user, line):
        line = line.lower().strip()

        if line.startswith(self.plugin_command) and (" " in line):
            subreddit = line.split(" ")[1].strip("/")

            if self.responder.ok_to_respond(room, user, subreddit):
                response = self.get_feed('www.reddit.com',
                                         '/r/' + subreddit + '/.json')

                if response:
                    self.responder.responded()

                    for post in islice(response['data']['children'],
                                       self.settings['reddit_links']):
                        post_data = post['data']
                        self.send_public(
                            room, "/me {}: {}".format(post_data['title'],
                                                      post_data['url']))
예제 #6
0
class Plugin(BasePlugin):
    __name__ = "Test Replier"
    settings = {'replies': ['Test failed.']}
    metasettings = {
        'replies': {
            'description': 'Replies:',
            'type': 'list string'
        }
    }

    def init(self):
        self.throttle = ResponseThrottle(self.frame, self.__name__)

    def IncomingPublicChatEvent(self, room, nick, line):  # noqa
        if line.lower() == 'test':
            if self.throttle.ok_to_respond(room, nick, line, 10):
                self.throttle.responded()
                self.saypublic(room, choice(self.settings['replies']))
예제 #7
0
class Plugin(BasePlugin):
    __name__ = "reddit"
    __version__ = "2015-08-02r05"
    __author__ = "Mutnick"
    __desc__ = """Displays topics and links for a requested subreddit."""
    settings = {'reddit_links': 3}
    metasettings = {'reddit_links': {"description": 'Maximum number of links to provide', 'type': 'integer'}}

    def init(self):
        self.plugin_command = "!reddit"
        self.responder = ResponseThrottle(self.frame, self.__name__)

    def IncomingPublicChatEvent(self, room, nick, line):
        line = line.lower().strip()
        if line.startswith(self.plugin_command) and (" " in line):
            subreddit = line.split(" ")[1].strip("/")
            if self.responder.ok_to_respond(room, nick, subreddit):
                    posts = feedparser.parse('https://www.reddit.com/r/' + subreddit + '/.rss')
                    if posts.entries:
                        self.responder.responded()
                        for post in posts.entries[0:self.settings['reddit_links']]:
                            self.saypublic(room, u"/me {}: {}".format(post.title, post.link))
예제 #8
0
class Plugin(BasePlugin):
    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        self.settings = {'replies': ['Test failed.']}
        self.metasettings = {
            'replies': {
                'description': 'Replies:',
                'type': 'list string'
            }
        }

        self.throttle = ResponseThrottle(self.core, self.human_name)

    def incoming_public_chat_event(self, room, user, line):

        if line.lower() != 'test':
            return

        if self.throttle.ok_to_respond(room, user, line, 10):
            self.throttle.responded()
            self.send_public(room, choice(self.settings['replies']))
예제 #9
0
    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        self.settings = {
            'keyword_enabled': False,
            'socket_timeout': 10
        }
        self.metasettings = {
            'keyword_enabled': {
                'description': 'Enable "portscan" keyword trigger',
                'type': 'bool'
            },
            'socket_timeout': {
                'description': 'Socket timeout (in seconds)',
                'type': 'int'
            }
        }
        self.__publiccommands__ = self.__privatecommands__ = [('port', self.port_checker_command)]

        self.throttle = ResponseThrottle(self.core, self.human_name)
        self.checkroom = "nicotine"
        self.pending_user = ""
예제 #10
0
class Plugin(BasePlugin):

    __name__ = "Test Replier"
    settings = {
        'replies': ['Test failed.']
    }
    metasettings = {
        'replies': {
            'description': 'Replies:',
            'type': 'list string'}
    }

    def init(self):
        self.throttle = ResponseThrottle(self.core, self.__name__)

    def incoming_public_chat_event(self, room, user, line):

        if line.lower() != 'test':
            return

        if self.throttle.ok_to_respond(room, user, line, 10):
            self.throttle.responded()
            self.send_public(room, choice(self.settings['replies']))
예제 #11
0
 def init(self):
     self.plugin_command = "!reddit"
     self.responder = ResponseThrottle(self.frame, self.__name__)
예제 #12
0
class Plugin(BasePlugin):

    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        self.settings = {
            'keyword_enabled': False,
            'socket_timeout': 10
        }
        self.metasettings = {
            'keyword_enabled': {
                'description': 'Enable "portscan" keyword trigger',
                'type': 'bool'
            },
            'socket_timeout': {
                'description': 'Socket timeout (in seconds)',
                'type': 'int'
            }
        }
        self.__publiccommands__ = self.__privatecommands__ = [('port', self.port_checker_command)]

        self.throttle = ResponseThrottle(self.core, self.human_name)
        self.checkroom = "nicotine"
        self.pending_user = ""

    def incoming_public_chat_notification(self, room, user, line):

        if room != self.checkroom or not self.settings['keyword_enabled'] or self.core.login_username == user:
            return

        if not self.throttle.ok_to_respond(room, user, line, 10):
            return

        if 'portscan' in line.lower():
            self.log("%s requested a port scan", user)
            self.resolve(user, True)

    def user_resolve_notification(self, user, ip_address, port, _country):

        if not self.pending_user or user not in self.pending_user:
            return

        user, announce = self.pending_user
        self.pending_user = ()
        threading.Thread(target=self.check_port, args=(user, ip_address, port, announce)).start()

    def resolve(self, user, announce):

        user_address = self.core.protothread.user_addresses.get(user)

        if user_address is not None:
            ip_address, port = user_address
            threading.Thread(target=self.check_port, args=(user, ip_address, port, announce)).start()
        else:
            self.pending_user = user, announce
            self.core.queue.append(GetPeerAddress(user))

    def check_port(self, user, ip_address, port, announce):

        status = self._check_port(ip_address, port)

        if announce and status in ('open', 'closed'):
            self.throttle.responded()
            self.send_public(self.checkroom, '%s: Your port is %s' % (user, status))

        self.log("User %s on %s:%s port is %s.", (user, ip_address, port, status))

    def _check_port(self, ip_address, port):

        if ip_address in ('0.0.0.0',) or port in (0,):
            return 'unknown'

        timeout = self.settings['socket_timeout']
        self.log('Scanning %s:%d (socket timeout %d seconds)...', (ip_address, port, timeout))

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(timeout)

        result = sock.connect_ex((ip_address, port))
        sock.close()

        if result == 0:
            return 'open'

        return 'closed'

    def port_checker_command(self, _, user):

        if user:
            self.resolve(user, False)
        else:
            self.log("Provide a user name as parameter.")

        return returncode['zap']
예제 #13
0
 def init(self):
     self.throttle = ResponseThrottle(self.core, self.__name__)
예제 #14
0
 def init(self):
     self.plugin_command = "!reddit"
     self.responder = ResponseThrottle(self.frame, self.__name__)