Ejemplo n.º 1
0
 def _formatMemo(self, memo):
     user = plugins.getUserName(memo.by)
     L = [format('%s (added by %s at %t)', memo.text, user, memo.at)]
     for (at, by, text) in memo.appends:
         L.append(format('%s (appended by %s at %t)',
                         text, plugins.getUserName(by), at))
     sep = ircutils.bold(' :: ')
     return sep.join(L)
Ejemplo n.º 2
0
 def _formatNote(self, note, to):
     elapsed = utils.timeElapsed(time.time() - note.at)
     if note.to == to:
         author = plugins.getUserName(note.frm)
         return format("#%i: %s (Sent by %s %s ago)", note.id, note.text, author, elapsed)
     else:
         assert note.frm == to, "Odd, userid isn't frm either."
         recipient = plugins.getUserName(note.to)
         return format("#%i: %s (Sent to %s %s ago)", note.id, note.text, recipient, elapsed)
Ejemplo n.º 3
0
 def _formatMemo(self, memo):
     user = plugins.getUserName(memo.by)
     L = [format('%s (added by %s at %t)', memo.text, user, memo.at)]
     for (at, by, text) in memo.appends:
         L.append(
             format('%s (appended by %s at %t)', text,
                    plugins.getUserName(by), at))
     sep = ircutils.bold(' :: ')
     return sep.join(L)
Ejemplo n.º 4
0
 def _formatNoteId(self, msg, note, sent=False):
     if note.public or not ircutils.isChannel(msg.args[0]):
         if sent:
             sender = plugins.getUserName(note.to)
             return format('#%i to %s', note.id, sender)
         else:
             sender = plugins.getUserName(note.frm)
             return format('#%i from %s', note.id, sender)
     else:
         return format('#%i (private)', note.id)
Ejemplo n.º 5
0
 def _formatNoteId(self, msg, note, sent=False):
     if note.public or not ircutils.isChannel(msg.args[0]):
         if sent:
             sender = plugins.getUserName(note.to)
             return format('#%i to %s', note.id, sender)
         else:
             sender = plugins.getUserName(note.frm)
             return format('#%i from %s', note.id, sender)
     else:
         return format('#%i (private)', note.id)
Ejemplo n.º 6
0
 def _formatNote(self, note, to):
     elapsed = utils.timeElapsed(time.time() - note.at)
     if note.to == to:
         author = plugins.getUserName(note.frm)
         return format('#%i: %s (Sent by %s %s ago)',
                       note.id, note.text, author, elapsed)
     else:
         assert note.frm == to, 'Odd, userid isn\'t frm either.'
         recipient = plugins.getUserName(note.to)
         return format('#%i: %s (Sent to %s %s ago)',
                       note.id, note.text, recipient, elapsed)
Ejemplo n.º 7
0
 def __str__(self):
     grabber = plugins.getUserName(self.grabber)
     if self.at:
         return format(_('%s (Said by: %s; grabbed by %s at %t)'),
                       self.text, self.hostmask, grabber, self.at)
     else:
         return format('%s', self.text)
Ejemplo n.º 8
0
 def __str__(self):
     grabber = plugins.getUserName(self.grabber)
     if self.at:
         return format(_('%s (Said by: %s; grabbed by %s at %t)'),
                       self.text, self.hostmask, grabber, self.at)
     else:
         return format('%s', self.text)
Ejemplo n.º 9
0
    def factinfo(self, irc, msg, args, channel, key):
        """[<channel>] <factoid key>

        Returns the various bits of info on the factoid for the given key.
        <channel> is only necessary if the message isn't sent in the channel
        itself.
        """
        # Start building the response string
        s = key + ": "
        # Next, get all the info and build the response piece by piece
        info = self.db.getFactinfo(channel, key)
        if not info:
            irc.error(format(_("No such factoid: %q"), key))
            return
        (
            created_by,
            created_at,
            modified_by,
            modified_at,
            last_requested_by,
            last_requested_at,
            requested_count,
            locked_by,
            locked_at,
        ) = info
        # First, creation info.
        # Map the integer created_by to the username
        created_by = plugins.getUserName(created_by)
        created_at = time.strftime(conf.supybot.reply.format.time(), time.localtime(int(created_at)))
        s += format(_("Created by %s on %s."), created_by, created_at)
        # Next, modification info, if any.
        if modified_by is not None:
            modified_by = plugins.getUserName(modified_by)
            modified_at = time.strftime(conf.supybot.reply.format.time(), time.localtime(int(modified_at)))
            s += format(_(" Last modified by %s on %s."), modified_by, modified_at)
        # Next, last requested info, if any
        if last_requested_by is not None:
            last_by = last_requested_by  # not an int user id
            last_at = time.strftime(conf.supybot.reply.format.time(), time.localtime(int(last_requested_at)))
            req_count = requested_count
            s += format(_(" Last requested by %s on %s, requested %n."), last_by, last_at, (requested_count, "time"))
        # Last, locked info
        if locked_at is not None:
            lock_at = time.strftime(conf.supybot.reply.format.time(), time.localtime(int(locked_at)))
            lock_by = plugins.getUserName(locked_by)
            s += format(_(" Locked by %s on %s."), lock_by, lock_at)
        irc.reply(s)
Ejemplo n.º 10
0
    def factinfo(self, irc, msg, args, channel, key):
        """[<channel>] <factoid key>

        Returns the various bits of info on the factoid for the given key.
        <channel> is only necessary if the message isn't sent in the channel
        itself.
        """
        # Start building the response string
        s = key + ': '
        # Next, get all the info and build the response piece by piece
        info = self.db.getFactinfo(channel, key)
        if not info:
            irc.error(format(_('No such factoid: %q'), key))
            return
        (created_by, created_at, modified_by, modified_at, last_requested_by,
         last_requested_at, requested_count, locked_by, locked_at) = info
        # First, creation info.
        # Map the integer created_by to the username
        created_by = plugins.getUserName(created_by)
        created_at = time.strftime(conf.supybot.reply.format.time(),
                                   time.localtime(int(created_at)))
        s += format(_('Created by %s on %s.'), created_by, created_at)
        # Next, modification info, if any.
        if modified_by is not None:
            modified_by = plugins.getUserName(modified_by)
            modified_at = time.strftime(conf.supybot.reply.format.time(),
                                        time.localtime(int(modified_at)))
            s += format(_(' Last modified by %s on %s.'), modified_by,
                        modified_at)
        # Next, last requested info, if any
        if last_requested_by is not None:
            last_by = last_requested_by  # not an int user id
            last_at = time.strftime(conf.supybot.reply.format.time(),
                                    time.localtime(int(last_requested_at)))
            req_count = requested_count
            s += format(_(' Last requested by %s on %s, requested %n.'),
                        last_by, last_at, (requested_count, 'time'))
        # Last, locked info
        if locked_at is not None:
            lock_at = time.strftime(conf.supybot.reply.format.time(),
                                    time.localtime(int(locked_at)))
            lock_by = plugins.getUserName(locked_by)
            s += format(_(' Locked by %s on %s.'), lock_by, lock_at)
        irc.reply(s)
Ejemplo n.º 11
0
 def _mostAuthored(self, irc, channel, limit):
     results = self.db.mostAuthored(channel, limit)
     L = ["%s (%s)" % (plugins.getUserName(t[0]), int(t[1])) for t in results]
     if L:
         author = _("author")
         if len(L) != 1:
             author = _("authors")
         irc.reply(format(_("Most prolific %s: %L"), author, L))
     else:
         irc.error(_("There are no factoids in my database."))
Ejemplo n.º 12
0
 def _mostAuthored(self, irc, channel, limit):
     results = self.db.mostAuthored(channel, limit)
     L = ['%s (%s)' % (plugins.getUserName(t[0]), int(t[1]))
          for t in results]
     if L:
         author = _('author')
         if len(L) != 1:
             author = _('authors')
         irc.reply(format(_('Most prolific %s: %L'), author, L))
     else:
         irc.error(_('There are no factoids in my database.'))
Ejemplo n.º 13
0
 def _mostAuthored(self, irc, channel, limit):
     results = self.db.mostAuthored(channel, limit)
     L = ['%s (%s)' % (plugins.getUserName(t[0]), int(t[1]))
          for t in results]
     if L:
         author = 'author'
         if len(L) != 1:
             author = 'authors'
         irc.reply(format('Most prolific %s: %L', author, L))
     else:
         irc.error('There are no factoids in my database.')
Ejemplo n.º 14
0
 def __str__(self):
     user = plugins.getUserName(self.by)
     if self.options:
         options = format('Options: %s', '; '.join(map(str, self.options)))
     else:
         options = 'The poll has no options, yet'
     if self.status:
         status = 'open'
     else:
         status = 'closed'
     return format('Poll #%i: %q started by %s. %s.  Poll is %s.',
                   self.id, self.question, user, options, status)
Ejemplo n.º 15
0
 def __str__(self):
     user = plugins.getUserName(self.by)
     if self.options:
         options = format('Options: %s', '; '.join(map(str, self.options)))
     else:
         options = 'The poll has no options, yet'
     if self.status:
         status = 'open'
     else:
         status = 'closed'
     return format('Poll #%i: %q started by %s. %s.  Poll is %s.', self.id,
                   self.question, user, options, status)
Ejemplo n.º 16
0
 def __str__(self):
     user = plugins.getUserName(self.by)
     if self.expires == 0:
         s = format('%s (Subject: %q, added by %s on %s)',
                    self.text, self.subject, self.by,
                    utils.str.timestamp(self.at))
     else:
         s = format('%s (Subject: %q, added by %s on %s, '
                    'expires at %s)',
                    self.text, self.subject, user,
                    utils.str.timestamp(self.at),
                    utils.str.timestamp(self.expires))
     return s
Ejemplo n.º 17
0
 def __str__(self):
     user = plugins.getUserName(self.by)
     if self.expires == 0:
         s = format(_('%s (Subject: %q, added by %s on %s)'),
                    self.text, self.subject, self.by,
                    utils.str.timestamp(self.at))
     else:
         s = format(
             _('%s (Subject: %q, added by %s on %s, '
               'expires at %s)'), self.text, self.subject, user,
             utils.str.timestamp(self.at),
             utils.str.timestamp(self.expires))
     return s
Ejemplo n.º 18
0
 def results(self, channel, poll_id):
     db = self._getDb(channel)
     cursor = db.cursor()
     cursor.execute(
         """SELECT id, question, started_by, open
                       FROM polls WHERE id=%s""", poll_id)
     if cursor.rowcount == 0:
         raise dbi.NoRecordError
     (id, question, by, status) = cursor.fetchone()
     by = plugins.getUserName(by)
     cursor.execute(
         """SELECT count(user_id), option_id
                       FROM votes
                       WHERE poll_id=%s
                       GROUP BY option_id
                       UNION
                       SELECT 0, id AS option_id
                       FROM options
                       WHERE poll_id=%s
                       AND id NOT IN (
                             SELECT option_id FROM votes
                             WHERE poll_id=%s)
                       GROUP BY option_id
                       ORDER BY count(user_id) DESC""", poll_id, poll_id,
         poll_id)
     if cursor.rowcount == 0:
         raise PollError, 'This poll has no votes yet.'
     else:
         options = []
         for count, option_id in cursor.fetchall():
             cursor.execute(
                 """SELECT option FROM options
                               WHERE id=%s AND poll_id=%s""", option_id,
                 poll_id)
             option = cursor.fetchone()[0]
             options.append(
                 OptionRecord(option_id, votes=int(count), text=option))
     return PollRecord(poll_id,
                       question=question,
                       status=status,
                       by=by,
                       options=options)
Ejemplo n.º 19
0
 def results(self, channel, poll_id):
     db = self._getDb(channel)
     cursor = db.cursor()
     cursor.execute("""SELECT id, question, started_by, open
                       FROM polls WHERE id=%s""",
                       poll_id)
     if cursor.rowcount == 0:
         raise dbi.NoRecordError
     (id, question, by, status) = cursor.fetchone()
     by = plugins.getUserName(by)
     cursor.execute("""SELECT count(user_id), option_id
                       FROM votes
                       WHERE poll_id=%s
                       GROUP BY option_id
                       UNION
                       SELECT 0, id AS option_id
                       FROM options
                       WHERE poll_id=%s
                       AND id NOT IN (
                             SELECT option_id FROM votes
                             WHERE poll_id=%s)
                       GROUP BY option_id
                       ORDER BY count(user_id) DESC""",
                       poll_id, poll_id, poll_id)
     if cursor.rowcount == 0:
         raise PollError, 'This poll has no votes yet.'
     else:
         options = []
         for count, option_id in cursor.fetchall():
             cursor.execute("""SELECT option FROM options
                               WHERE id=%s AND poll_id=%s""",
                               option_id, poll_id)
             option = cursor.fetchone()[0]
             options.append(OptionRecord(option_id, votes=int(count),
                                         text=option))
     return PollRecord(poll_id, question=question, status=status, by=by,
                       options=options)
Ejemplo n.º 20
0
 def __str__(self):
     at = time.strftime(conf.supybot.reply.format.time(),
                        time.localtime(float(self.at)))
     grabber = plugins.getUserName(self.grabber)
     return '%s (Said by: %s; grabbed by %s at %s)' % \
               (self.text, self.hostmask, grabber, at)
Ejemplo n.º 21
0
 def __str__(self):
     at = time.strftime(conf.supybot.reply.format.time(),
                        time.localtime(float(self.at)))
     grabber = plugins.getUserName(self.grabber)
     return '%s (Said by: %s; grabbed by %s at %s)' % \
               (self.text, self.hostmask, grabber, at)
Ejemplo n.º 22
0
 def __str__(self):
     grabber = plugins.getUserName(self.grabber).split('!', 2)
     return format('%s grabbed: %s',
                   grabber[0], self.text)
Ejemplo n.º 23
0
 def __str__(self):
     grabber = plugins.getUserName(self.grabber)
     return format('%s (Said by: %s; grabbed by %s at %t)',
                   self.text, self.hostmask, grabber, float(self.at))