Permalink
Browse files

Make the quote plugin work better.

  • Loading branch information...
1 parent c787992 commit ccabf81aec4ecf349a03a91242e2bbdb4b8d964b @mythmon mythmon committed Jul 24, 2011
Showing with 14 additions and 11 deletions.
  1. +14 −11 hamper/plugins/quote.py
View
25 hamper/plugins/quote.py
@@ -23,24 +23,27 @@ def setup(self, factory):
def command(self, bot, comm, groups):
if groups[0]:
- args = groups[0].strip()
+ args = groups[0].split(' ')
+ args = [a.strip() for a in args if a.strip()]
else:
- args = ''
+ args = []
- if args.startswith('--add'):
+ if len(args) == 0:
+ # Deliver a quote
+ index = random.randrange(0, bot.db.query(Quote).count() + 1)
+ quote = bot.factory.db.query(Quote)[index]
+ # Lame twisted irc doesn't support unicode.
+ bot.say(str(quote.text))
+ elif args[0] == '--args':
# Add a quote
- text = args.split(' ', 1)[1]
- print('trying to add quote: "{}".'.format(text))
+ text = ' '.join(args[1:])
quote = Quote(text, comm['user'])
bot.factory.db.add(quote)
bot.say('Succesfully added quote.')
+ elif args[0] == '--count':
+ bot.say('I know {0} quotes.'.format(bot.db.query(Quote).count()))
else:
- # Deliver a quote
- print('trying to repeat a quote')
- index = random.randrange(0, bot.db.query(Quote).count())
- quote = bot.factory.db.query(Quote)[index]
- # Lame twisted irc doesn't support unicode.
- bot.say(str(quote.text))
+ bot.say('Wait, what?')
class Quote(SQLAlchemyBase):

0 comments on commit ccabf81

Please sign in to comment.