Convert not to care how long its messages are.

This commit is contained in:
Jeremy Fincher 2003-09-07 06:01:25 +00:00
parent 757154313e
commit b68908ed00
8 changed files with 13 additions and 39 deletions

View File

@ -178,14 +178,7 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
for result in cursor.fetchall(): for result in cursor.fetchall():
factoids.append('(#%s) %s' % (counter, result[0])) factoids.append('(#%s) %s' % (counter, result[0]))
counter += 1 counter += 1
totalResults = len(factoids) irc.reply(msg, '%r could be %s' % (key, ', or '.join(factoids)))
if ircutils.shrinkList(factoids, ', or ', 400):
s = '%s could be %s (%s shown out of %s)' % \
(key, ', or '.join(factoids),
utils.nItems(len(factoids), 'result'), totalResults)
else:
s = '%s could be %s' % (key, ', or '.join(factoids))
irc.reply(msg, s)
def lock(self, irc, msg, args): def lock(self, irc, msg, args):
"""[<channel>] <key> """[<channel>] <key>
@ -289,14 +282,14 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
cursor = db.cursor() cursor = db.cursor()
cursor.execute("""SELECT fact, key_id FROM factoids cursor.execute("""SELECT fact, key_id FROM factoids
ORDER BY random() ORDER BY random()
LIMIT 10""") LIMIT 3""")
if cursor.rowcount != 0: if cursor.rowcount != 0:
L = [] L = []
for (factoid, id) in cursor.fetchall(): for (factoid, id) in cursor.fetchall():
cursor.execute("""SELECT key FROM keys WHERE id=%s""", id) cursor.execute("""SELECT key FROM keys WHERE id=%s""", id)
(key,) = cursor.fetchone() (key,) = cursor.fetchone()
L.append('"%s": %s' % (ircutils.bold(key), factoid)) L.append('"%s": %s' % (ircutils.bold(key), factoid))
irc.reply(msg, ircutils.privmsgPayload(L, '; ', 400)) irc.reply(msg, '; '.join(L))
else: else:
irc.error(msg, 'I couldn\'t find a factoid.') irc.error(msg, 'I couldn\'t find a factoid.')

View File

@ -180,7 +180,7 @@ class FunDB(callbacks.Privmsg):
lenSoFar += len(s) lenSoFar += len(s)
counter -= 1 counter -= 1
L.append(s) L.append(s)
irc.reply(msg, ircutils.privmsgPayload(L, '; ')) irc.reply(msg, '; '.join(L))
def insult(self, irc, msg, args): def insult(self, irc, msg, args):
"""<nick> """<nick>
@ -551,11 +551,7 @@ class FunDB(callbacks.Privmsg):
irc.reply(msg, str(cursor.fetchone()[0])) irc.reply(msg, str(cursor.fetchone()[0]))
else: else:
zipcodes = [str(t[0]) for t in cursor.fetchall()] zipcodes = [str(t[0]) for t in cursor.fetchall()]
ircutils.shrinkList(zipcodes, ', ', 400) irc.reply(msg, utils.commaAndify(zipcodes))
if len(zipcodes) < cursor.rowcount:
random.shuffle(zipcodes)
irc.reply(msg, '(%s shown of %s): %s' % \
(len(zipcodes), cursor.rowcount, ', '.join(zipcodes)))
Class = FunDB Class = FunDB

View File

@ -372,7 +372,7 @@ class Http(callbacks.Privmsg):
if len(defs) == 0: if len(defs) == 0:
irc.reply(msg, 'No definitions found.') irc.reply(msg, 'No definitions found.')
else: else:
s = ircutils.privmsgPayload(defs, ', or ') s = ', or '.join(defs)
irc.reply(msg, '%s could be %s' % (acronym, s)) irc.reply(msg, '%s could be %s' % (acronym, s))
_netcraftre = re.compile(r'whatos text -->(.*?)<a href="/up/acc', re.S) _netcraftre = re.compile(r'whatos text -->(.*?)<a href="/up/acc', re.S)

View File

@ -105,10 +105,7 @@ class IMDB(callbacks.Privmsg):
titles = ['%s (%s)' % \ titles = ['%s (%s)' % \
(utils.unCommaThe(movie.title()), movie.year()) (utils.unCommaThe(movie.title()), movie.year())
for movie in movies] for movie in movies]
if ircutils.shrinkList(titles, ', ', 425): irc.reply(msg, 'Matches: ' + utils.commaAndify(titles))
irc.reply(msg, '%s movies matched, please narrow your search')
else:
irc.reply(msg, 'Matches: ' + utils.commaAndify(titles))
Class = IMDB Class = IMDB

View File

@ -252,7 +252,6 @@ class Notes(callbacks.Privmsg):
count = cursor.rowcount count = cursor.rowcount
notes = cursor.fetchall() notes = cursor.fetchall()
L = [] L = []
more = False
if count == 0: if count == 0:
irc.reply(msg, 'You have no unread notes.') irc.reply(msg, 'You have no unread notes.')
else: else:
@ -263,12 +262,7 @@ class Notes(callbacks.Privmsg):
L.append(r'#%s from %s' % (id, sender)) L.append(r'#%s from %s' % (id, sender))
else: else:
L.append(r'#%s (private)' % id) L.append(r'#%s (private)' % id)
if more: irc.reply(msg, utils.commaAndify(L))
ircutils.shrinkList(L, ', ', 400)
L.append('and even more notes.')
else:
ircutils.shrinkList(L, ', ', 450)
irc.reply(msg, ', '.join(L))
def oldnotes(self, irc, msg, args): def oldnotes(self, irc, msg, args):
"""takes no arguments """takes no arguments
@ -290,9 +284,7 @@ class Notes(callbacks.Privmsg):
else: else:
ids = [str(t[0]) for t in cursor.fetchall()] ids = [str(t[0]) for t in cursor.fetchall()]
ids.reverse() ids.reverse()
ircutils.shrinkList(ids, ', ', 425) irc.reply(msg, utils.commaAndify(ids))
ids.reverse()
irc.reply(msg, ', '.join(ids))

View File

@ -108,7 +108,7 @@ class RSS(callbacks.Privmsg):
if not headlines: if not headlines:
irc.error(msg, 'Error grabbing RSS feed') irc.error(msg, 'Error grabbing RSS feed')
return return
irc.reply(msg, ' :: '.join(headlines) irc.reply(msg, ' :: '.join(headlines))
def rssinfo(self, irc, msg, args): def rssinfo(self, irc, msg, args):
"""<url> """<url>

View File

@ -267,7 +267,7 @@ class URLSnarfer(callbacks.Privmsg, ChannelDBHandler):
else: else:
if nolimit: if nolimit:
urls = ['<%s>' % t[0] for t in cursor.fetchall()] urls = ['<%s>' % t[0] for t in cursor.fetchall()]
s = ircutils.privmsgPayload(urls, ', ', 400) s = ', '.join(urls)
elif simple: elif simple:
s = cursor.fetchone()[0] s = cursor.fetchone()[0]
else: else:

View File

@ -204,12 +204,8 @@ class Unix(callbacks.Privmsg):
resp = 'Could not find an alternate spelling for "%s"' % word resp = 'Could not find an alternate spelling for "%s"' % word
elif line[0] == '&': elif line[0] == '&':
matches = line.split(':')[1].strip() matches = line.split(':')[1].strip()
match_list = matches.split(', ') resp = 'Possible spellings for %r: %s.' % \
total = len(match_list) (word, utils.commaAndify(matches.split(', ')))
ircutils.shrinkList(match_list, ', ', 350)
shown = len(match_list)
resp = 'Possible spellings for "%s" (%d found, %d shown): %s.' % \
(word, total, shown, ', '.join(match_list))
else: else:
resp = 'Something unexpected was seen in the [ai]spell output.' resp = 'Something unexpected was seen in the [ai]spell output.'
irc.reply(msg, resp) irc.reply(msg, resp)