Example #1
0
    def on_msg(self, cardinal, user, channel, message):
        new_message = self.substitute(user, channel, message)
        if new_message is not None:
            old_message = self.history[channel][user.nick]
            if self.should_send_correction(old_message, new_message):
                self.history[channel][user.nick] = new_message

                # In the 11th hour, make sure that we correctly handle /me
                if is_action(new_message):
                    new_message = parse_action(new_message)

                cardinal.sendMsg(channel,
                                 '{} meant: {}'.format(user.nick, new_message))
        else:
            self.history[channel][user.nick] = message
Example #2
0
    def format_seen(self, nick):
        with self.db() as db:
            if nick.lower() not in db['users']:
                return "Sorry, I haven't seen {}.".format(nick)

            entry = db['users'][nick.lower()]

        dt_timestamp = datetime.fromtimestamp(
            entry['timestamp'],
            tz=timezone.utc,
        )
        t_seen = dt_timestamp.strftime("%Y-%m-%d %H:%M:%S")
        t_ago = self._pretty_seconds(
            (datetime.now(tz=timezone.utc).replace(microsecond=0) -
             dt_timestamp).total_seconds())

        message = "I last saw {} {} ago ({}). ".format(nick, t_ago, t_seen)

        action, params = entry['action'], entry['params']
        if action == PRIVMSG:
            last_msg = params[1]
            if is_action(last_msg):
                last_msg = parse_action(nick, last_msg)

            message += "{} sent \"{}\" to {}.".format(
                nick,
                strip_formatting(last_msg),
                params[0],
            )
        elif action == NOTICE:
            message += "{} sent notice \"{}\" to {}.".format(
                nick,
                strip_formatting(params[1]),
                params[0],
            )
        elif action == JOIN:
            message += "{} joined {}.".format(nick, params[0])
        elif action == PART:
            message += "{} left {}{}.".format(
                nick,
                params[0],
                (" ({})".format(strip_formatting(params[1]))
                 if params[1] else ""),
            )
        elif action == NICK:
            message += "{} renamed themselves {}.".format(nick, params[0])
        elif action == MODE:
            message += "{} set mode {} on channel {}.".format(
                nick,
                params[1],
                params[0],
            )
        elif action == TOPIC:
            message += "{} set {}'s topic to \"{}\".".format(
                nick,
                params[0],
                strip_formatting(params[1]),
            )
        elif action == QUIT:
            message += "{} quit{}.".format(
                nick,
                (" ({})".format(strip_formatting(params[0]))
                 if params[0] else ""),
            )

        return message
Example #3
0
def test_is_action(message, expected):
    assert util.is_action(message) == expected