Esempio n. 1
0
    def channel_message(self, event):
        if event["target"].get_setting("auto-title", False):
            event.eat()
            url = utils.http.url_sanitise(event["match"].group(0))
            code, title = self._get_title(event["server"], event["target"], url)

            if code == 200 and title:
                message = title
                if event["target"].get_setting("auto-title-first", False):
                    setting = "url-last-%s" % self._url_hash(url)
                    first_details = event["target"].get_setting(setting, None)

                    if first_details:
                        first_nickname, first_timestamp, _ = first_details
                        timestamp_parsed = utils.iso8601_parse(first_timestamp)
                        timestamp_human = utils.datetime_human(timestamp_parsed)
                        message = "%s (first posted by %s at %s)" % (title,
                            first_nickname, timestamp_human)
                    else:
                        event["target"].set_setting(setting,
                            [event["user"].nickname, utils.iso8601_format_now(),
                            url])
                event["stdout"].write(message)
            if code == -2:
                self.log.debug("Not showing title for %s, too similar", [url])
Esempio n. 2
0
    def channel_message(self, event):
        """
        :command: title
        :pattern-url: 1
        """
        if event["target"].get_setting("auto-title", False):
            event.eat()
            url = event["match"].group(0)
            title = self._get_title(event["target"], event["match"].group(0))

            if title:
                message = title
                if event["target"].get_setting("auto-title-first", False):
                    setting = "url-last-%s" % self._url_hash(url)
                    first_details = event["target"].get_setting(setting, None)

                    if first_details:
                        first_nickname, first_timestamp, _ = first_details
                        timestamp_parsed = utils.iso8601_parse(first_timestamp)
                        timestamp_human = utils.datetime_human(
                            timestamp_parsed)
                        message = "%s (first posted by %s at %s)" % (
                            title, first_nickname, timestamp_human)
                    else:
                        event["target"].set_setting(setting, [
                            event["user"].nickname,
                            utils.iso8601_format_now(), url
                        ])
                event["stdout"].write(message)
Esempio n. 3
0
    def time(self, event):
        type, name, timezone = self._find_setting(event)

        if not timezone == None:
            dt = datetime.datetime.now(tz=pytz.timezone(timezone))
            gmt_offset = (dt.utcoffset().total_seconds()/60)/60
            tz = "GMT"
            if not gmt_offset == 0.0:
                if gmt_offset > 0:
                    tz += "+"
                tz += "%g" % gmt_offset
            human = utils.datetime_human(dt)

            out = None
            if type == LocationType.USER:
                out = "Time for %s: %s %s" % (name, human, tz)
            else:
                out = "It is %s in %s %s" % (human, name, tz)
            event["stdout"].write(out)
        else:
            out = None
            if type == LocationType.USER:
                out = NOLOCATION_USER
            else:
                out = NOLOCATION_NAME

            event["stderr"].write(out % name)
Esempio n. 4
0
    def time(self, event):
        """
        :help: Get the time for you or someone else
        :usage: [nickname]
        """
        target_user = event["user"]
        if event["args"]:
            target_user = event["server"].get_user(event["args_split"][0])

        location = target_user.get_setting("location", None)

        if not location == None:
            page = utils.http.request(API % location["timezone"], json=True)

            if page and page.data and not page.data.get("error", None):
                dt = utils.iso8601_parse(page.data["datetime"],
                    microseconds=True)
                human = utils.datetime_human(dt)
                event["stdout"].write("Time for %s: %s" % (target_user.nickname,
                    human))
            else:
                raise utils.EventsResultsError()
        else:
            event["stderr"].write("%s doesn't have a location set" %
                target_user.nickname)
Esempio n. 5
0
    def channel_message(self, event):
        match = re.search(utils.http.REGEX_URL, event["message"])
        if match and event["channel"].get_setting("auto-title", False):
            is_ignored_f = short_url = self.exports.get_one("is-ignored",
                lambda _1, _2: False)
            if is_ignored_f(event["user"], "title"):
                return

            url = match.group(0)
            title = self._get_title(event["channel"], match.group(0))

            if title:
                message = title
                if event["channel"].get_setting("auto-title-first", False):
                    setting = "url-last-%s" % self._url_hash(url)
                    first_details = event["channel"].get_setting(setting, None)

                    if first_details:
                        first_nickname, first_timestamp, _ = first_details
                        timestamp_parsed = utils.iso8601_parse(first_timestamp)
                        timestamp_human = utils.datetime_human(timestamp_parsed)
                        message = "%s (first posted by %s at %s)" % (title,
                            first_nickname, timestamp_human)
                    else:
                        event["channel"].set_setting(setting,
                            [event["user"].nickname, utils.iso8601_format_now(),
                            url])


                self.events.on("send.stdout").call(target=event["channel"],
                    message=message, module_name="Title",
                    server=event["server"])
Esempio n. 6
0
    def channel_message(self, event):
        match = re.search(utils.http.REGEX_URL, event["message"])
        if match and event["channel"].get_setting("auto-title", False):
            is_ignored_f = short_url = self.exports.get_one(
                "is-ignored", lambda _1, _2: False)
            if is_ignored_f(event["user"], "title"):
                return

            url = match.group(0)
            title = self._get_title(event["channel"], match.group(0))

            if title:
                message = title
                if event["channel"].get_setting("auto-title-first", False):
                    setting = "url-last-%s" % self._url_hash(url)
                    first_details = event["channel"].get_setting(setting, None)

                    if first_details:
                        first_nickname, first_timestamp, _ = first_details
                        timestamp_parsed = utils.iso8601_parse(first_timestamp)
                        timestamp_human = utils.datetime_human(
                            timestamp_parsed)
                        message = "%s (first posted by %s at %s)" % (
                            title, first_nickname, timestamp_human)
                    else:
                        event["channel"].set_setting(setting, [
                            event["user"].nickname,
                            utils.iso8601_format_now(), url
                        ])

                self.events.on("send.stdout").call(target=event["channel"],
                                                   message=message,
                                                   module_name="Title",
                                                   server=event["server"])
Esempio n. 7
0
File: to.py Progetto: jesopo/bitbot
 def channel_message(self, event):
     messages = event["channel"].get_user_setting(event["user"].get_id(),
         "to", [])
     for nickname, message, timestamp in messages:
         timestamp_parsed = utils.iso8601_parse(timestamp)
         timestamp_human = utils.datetime_human(timestamp_parsed)
         event["channel"].send_message("%s: <%s> %s (at %s UTC)" % (
             event["user"].nickname, nickname, message, timestamp_human))
     if messages:
         event["channel"].del_user_setting(event["user"].get_id(), "to")
Esempio n. 8
0
 def channel_message(self, event):
     messages = event["channel"].get_user_setting(event["user"].get_id(),
         "to", [])
     for nickname, message, timestamp in messages:
         timestamp_parsed = utils.iso8601_parse(timestamp)
         timestamp_human = utils.datetime_human(timestamp_parsed)
         event["channel"].send_message("%s: <%s> %s (at %s UTC)" % (
             event["user"].nickname, nickname, message, timestamp_human))
     if messages:
         event["channel"].del_user_setting(event["user"].get_id(), "to")
Esempio n. 9
0
    def time(self, event):
        target_user, location = self._find_setting(event)
        if not location == None:
            page = utils.http.request(API % location["timezone"], json=True)

            if page and page.data and not page.data.get("error", None):
                dt = utils.iso8601_parse(page.data["datetime"],
                                         microseconds=True)
                human = utils.datetime_human(dt)
                event["stdout"].write("Time for %s: %s" %
                                      (target_user.nickname, human))
            else:
                raise utils.EventsResultsError()
        else:
            event["stderr"].write(NOLOCATION % target_user.nickname)
Esempio n. 10
0
    def time(self, event):
        type, name, timezone = self._find_setting(event)

        if not timezone == None:
            dt = datetime.datetime.now(tz=pytz.timezone(timezone))
            human = utils.datetime_human(dt)

            out = None
            if type == LocationType.USER:
                out = "Time for %s: %s" % (name, human)
            else:
                out = "It is %s in %s" % (human, name)
            event["stdout"].write(out)
        else:
            out = None
            if type == LocationType.USER:
                out = NOLOCATION_USER
            else:
                out = NOLOCATION_NAME

            event["stderr"].write(out % name)