diff options
author | Elis Axelsson <elis.axelsson@gmail.com> | 2012-08-18 18:54:04 +0200 |
---|---|---|
committer | Elis Axelsson <elis.axelsson@gmail.com> | 2012-08-18 18:54:04 +0200 |
commit | 2301f094ad3227e49d3def485448660301f60dac (patch) | |
tree | 8b3be5b90579ccead19cc7b813ea35736e326e88 | |
parent | 3bb5a68d7f081225fa6a77e2537fe62650c872fc (diff) | |
download | ponysay-2301f094ad3227e49d3def485448660301f60dac.tar.gz ponysay-2301f094ad3227e49d3def485448660301f60dac.tar.bz2 ponysay-2301f094ad3227e49d3def485448660301f60dac.zip |
Fallback quote for ponies without quotes
-rwxr-xr-x | ponysay.py | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -349,15 +349,19 @@ class ponysay(): alts.append(pair) pairs = alts - pair = pairs[random.randrange(0, len(pairs))] - qfile = None - try: - qfile = open(pair[1], 'r') - args.message = '\n'.join(qfile.readlines()).strip() - finally: - if qfile is not None: - qfile.close() - args.pony = [pair[0]] + if not len(pairs) == 0: + pair = pairs[random.randrange(0, len(pairs))] + qfile = None + try: + qfile = open(pair[1], 'r') + args.message = '\n'.join(qfile.readlines()).strip() + finally: + if qfile is not None: + qfile.close() + args.pony = [pair[0]] + else: + args.pony = args.quote + args.message = 'I got nuthin\' good to say :(' self.print_pony(args) |