Skip to content

Commit

Permalink
Make the quote plugin work.
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed Jul 24, 2011
1 parent 66089ce commit c787992
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions hamper/plugins/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,41 @@
from hamper.interfaces import Command


SQLAlchemyBase = declarative_base()

class Quotes(Command):
'''Remember quotes, and recall on demand.'''

name = 'quotes'
priority = 0
regex = r'^quote(.*)$'

def __init__(self):
super(Quotes, self).__init__()
# TODO: make sure the tables we care about are in the db. how?
regex = r'^quotes?(?: +(.*))?$'

def setup(self, factory):
SQLAlchemyBase.metadata.create_all(factory.db_engine)

def command(self, bot, comm, groups):
args = groups[0].strip()
if groups[0]:
args = groups[0].strip()
else:
args = ''

if args.startswith('--add '):
if args.startswith('--add'):
# Add a quote
text = args.split(' ', 1)[1]
quote = Quote(text, opts['user'])
bot.db.add(quote)
print('trying to add quote: "{}".'.format(text))
quote = Quote(text, comm['user'])
bot.factory.db.add(quote)
bot.say('Succesfully added quote.')
else:
# Deliver a quote
print('trying to repeat a quote')
index = random.randrange(0, bot.db.query(Quote).count())
quote = bot.db.query(Quote)[rand]
bot.say(quote.text)


Base = declarative_base()
quote = bot.factory.db.query(Quote)[index]
# Lame twisted irc doesn't support unicode.
bot.say(str(quote.text))


class Quote(Base):
class Quote(SQLAlchemyBase):
'''The object that will get persisted by the database.'''

__tablename__ = 'quotes'
Expand Down

0 comments on commit c787992

Please sign in to comment.