Fix quotes

This commit is contained in:
redfast00 2019-02-14 19:09:08 +01:00
parent 9eccc4ae7b
commit 66fd50743f
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
2 changed files with 15 additions and 8 deletions

View file

@ -126,6 +126,7 @@ def door(username):
command = tokens[0].lower()
return mattermost_response(slotmachien_request(username, command), ephemeral=True)
@app.route('/cammiechat', methods=['POST'])
@requires_token('cammiechat')
@requires_regular
@ -136,7 +137,6 @@ def cammiechat(username):
requests.post("https://kelder.zeus.ugent.be/messages/", data=request.values.get('text').strip(), headers=headers)
return mattermost_response("Message sent", ephemeral=True)
QUOTEE_REGEX = re.compile('\W*(\w+).*')
@app.route('/addquote', methods=['POST'])
@requires_token('quote')
@ -149,11 +149,16 @@ def add_quote():
db.session.commit()
return mattermost_response("{} added the quote \"{}\"".format(user, quote_text))
@app.route('/quote', methods=['GET'])
@app.route('/quote', methods=['POST'])
def random_quote():
text_contains = request.values['text']
matches = models.Quote.query.filter(models.Quote.quote.contains(text_contains))
return mattermost_response(random.choice(matches))
matches = models.Quote.query.filter(models.Quote.quote.contains(text_contains)).all()
if matches:
selected_quote = random.choice(matches)
response = f'{selected_quote.quote}'
return mattermost_response(response)
return mattermost_response(f'No quotes found matching "{text_contains}"', ephemeral=True)
@app.route('/', methods=['GET'])

View file

@ -4,5 +4,7 @@ from app.app import db, models
db.create_all()
exists = models.User.query.filter_by(username='admin').first()
if not exists:
db.session.add(models.User('admin', admin=True))
db.session.commit()