Fix quotes
This commit is contained in:
parent
9eccc4ae7b
commit
66fd50743f
2 changed files with 15 additions and 8 deletions
15
app/app.py
15
app/app.py
|
@ -126,6 +126,7 @@ def door(username):
|
||||||
command = tokens[0].lower()
|
command = tokens[0].lower()
|
||||||
return mattermost_response(slotmachien_request(username, command), ephemeral=True)
|
return mattermost_response(slotmachien_request(username, command), ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/cammiechat', methods=['POST'])
|
@app.route('/cammiechat', methods=['POST'])
|
||||||
@requires_token('cammiechat')
|
@requires_token('cammiechat')
|
||||||
@requires_regular
|
@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)
|
requests.post("https://kelder.zeus.ugent.be/messages/", data=request.values.get('text').strip(), headers=headers)
|
||||||
return mattermost_response("Message sent", ephemeral=True)
|
return mattermost_response("Message sent", ephemeral=True)
|
||||||
|
|
||||||
QUOTEE_REGEX = re.compile('\W*(\w+).*')
|
|
||||||
|
|
||||||
@app.route('/addquote', methods=['POST'])
|
@app.route('/addquote', methods=['POST'])
|
||||||
@requires_token('quote')
|
@requires_token('quote')
|
||||||
|
@ -149,13 +149,18 @@ def add_quote():
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return mattermost_response("{} added the quote \"{}\"".format(user, quote_text))
|
return mattermost_response("{} added the quote \"{}\"".format(user, quote_text))
|
||||||
|
|
||||||
@app.route('/quote', methods=['GET'])
|
|
||||||
|
@app.route('/quote', methods=['POST'])
|
||||||
def random_quote():
|
def random_quote():
|
||||||
text_contains = request.values['text']
|
text_contains = request.values['text']
|
||||||
matches = models.Quote.query.filter(models.Quote.quote.contains(text_contains))
|
matches = models.Quote.query.filter(models.Quote.quote.contains(text_contains)).all()
|
||||||
return mattermost_response(random.choice(matches))
|
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'])
|
@app.route('/', methods=['GET'])
|
||||||
def list_quotes():
|
def list_quotes():
|
||||||
return render_template('quotes.html', quotes = reversed(models.Quote.query.all()))
|
return render_template('quotes.html', quotes=reversed(models.Quote.query.all()))
|
||||||
|
|
|
@ -4,5 +4,7 @@ from app.app import db, models
|
||||||
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
db.session.add(models.User('admin', admin=True))
|
exists = models.User.query.filter_by(username='admin').first()
|
||||||
db.session.commit()
|
if not exists:
|
||||||
|
db.session.add(models.User('admin', admin=True))
|
||||||
|
db.session.commit()
|
||||||
|
|
Loading…
Reference in a new issue