Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- !detain list - see detain history
- !dierre - get a dierre picture and a quote :heart:
- !door \<location\> - ask to be let in
- !quote - get random cohort quote
- !quote add \<quote\> - add quote
- !party \<building\> \<room\> \<timewindow\> - Let the group know there's a party at your place
- !roseceremony - retrieve the list of current bachelor contestants
- !train [TODO] \<transitsystem\> \<station\> - Lets you know when the next train/bus for <transitsystem> at <station> is coming
Expand Down
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from modules.weather import weather_handler
from modules.penny import penny_pic_handler
from modules.tethics_dare import dare_handler

from modules.cohort_quotes.py import cohort_quote_handler
# Globs
app = Flask(__name__)

Expand All @@ -49,6 +49,7 @@ def call_handler(sender, message, bot_id, app_id):
'!weather': weather_handler,
'!penny': penny_pic_handler,
'!dare': dare_handler
'!quote': cohort_quote_handler
}

# Get the function from handlers dictionary, add message as argument, return None on KeyError
Expand Down
1 change: 1 addition & 0 deletions cohort_quotes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"BALLS" - short stop Dierre
34 changes: 34 additions & 0 deletions modules/cohort_quotes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import random

def cohort_quote_handler(sender, message, bot_id, app_id):
message = message.strip().split()
if len(message) == 1:
return rand_quote()
elif len(message) > 2 and message[1] == 'add':
return add_quote(' '.join(message[3:]))
else:
return "Get random cohort quote.\n usage: !quote\n"

def rand_quote():
quotes = []
with open('cohort_quotes.txt') as f:
for line in f:
quotes.append(line.strip())
return quotes[random.randrange(len(quotes))]

def add_quote(quote):
if '"' not in quote:
quote = '"' + quote
if '-' in quote:
quotes = quote.split('-')
quote = quotes[0]+'" - '+quotes[1]
else:
quote = quote+ '"'

with open('cohort_quotes.txt','a') as f:
f.write('\n'+quote)
return quote + ' added'

if __name__ == '__main__':
print(cohort_quote_handler('Dierre','!quote',' ',' '))
print(cohort_quote_handler('Dierre','!quote add This is a new quote - Joe',' ',' '))