diff --git a/examples.py b/examples.py new file mode 100644 index 00000000..16fbefcd --- /dev/null +++ b/examples.py @@ -0,0 +1,49 @@ +EXAMPLE_ANIME = """ + - Death Note anime, + - Dragon ball super anime status, + - What is the anime rating of One Punch Man?""" + +EXAMPLE_BOOKS = """ + - book timeline + - harry potter book plot + - little women book rating""" + +EXAMPLE_CONVERSIONS = """ + - HKD to USD + - USD to EUR rate + - how much is 100 USD to INR""" + +EXAMPLE_DEFINITIONS = """ + - define comfort + - cloud definition + - what does an accolade mean?""" + +EXAMPLE_LYRICS = """ + - paradise lyrics + - lyrics of the song hall of fame + - What are the lyrics to see you again?""" + +EXAMPLE_MOVIES = """ + - batman movie + - iron man 2 movie plot + - What is the rating of happiness movie?""" + +EXAMPLE_TIME = """ + - time in new york + - india time + - time at paris""" + +EXAMPLE_VIDEOS = """ + - sia videos + - videos by eminem + - video coldplay""" + +EXAMPLE_WEATHER = """ + - tell me the weather in London + - weather Delhi + - What's the weather in Texas?""" + +EXAMPLE_WIKI = """ + - wikipedia barack + - html wiki + - who is sachin tendulkar""" \ No newline at end of file diff --git a/modules/src/anime.py b/modules/src/anime.py index 9962249f..7defba0e 100644 --- a/modules/src/anime.py +++ b/modules/src/anime.py @@ -2,6 +2,7 @@ import requests_cache from templates.button import * +from error_msg import QUERY_ERROR, EXAMPLE_ANIME def process(input, entities): @@ -33,11 +34,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any anime matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - Death Note anime' - error_message += '\n - Dragon ball super anime status' - error_message += '\n - What is the anime rating of One Punch Man?' + error_message = QUERY_ERROR.format('anime') + EXAMPLE_ANIME output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/book.py b/modules/src/book.py index c3174363..d8c85734 100644 --- a/modules/src/book.py +++ b/modules/src/book.py @@ -7,6 +7,7 @@ import config from templates.button import * +from error_msg import QUERY_ERROR, EXAMPLE_BOOKS GOODREADS_ACCESS_TOKEN = os.environ.get('GOODREADS_ACCESS_TOKEN', config.GOODREADS_ACCESS_TOKEN) @@ -41,11 +42,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any book matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - book timeline' - error_message += '\n - harry potter book plot' - error_message += '\n - little women book rating' + error_message = QUERY_ERROR.format('books') + EXAMPLE_BOOKS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/currency.py b/modules/src/currency.py index 4c5bbdde..8dde7cf8 100644 --- a/modules/src/currency.py +++ b/modules/src/currency.py @@ -1,6 +1,7 @@ import requests from templates.text import TextTemplate +from error_msg import CONVERT_ERROR, EXAMPLE_CONVERSIONS def process(input, entities): @@ -23,11 +24,7 @@ def process(input, entities): output['output'] = TextTemplate(conversion_details).get_message() output['success'] = True except: - error_message = 'I couldn\'t convert between those currencies.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - HKD to USD' - error_message += '\n - USD to EUR rate' - error_message += '\n - how much is 100 USD to INR' + error_message = CONVERT_ERROR.format('currencies') + EXAMPLE_CONVERSIONS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/dictionary.py b/modules/src/dictionary.py index cf722f5d..2bbb38b1 100644 --- a/modules/src/dictionary.py +++ b/modules/src/dictionary.py @@ -5,6 +5,7 @@ import config from templates.text import TextTemplate +from error_msg import QUERY_ERROR, EXAMPLE_DEFINITIONS WORDS_API_KEY = os.environ.get('WORDS_API_KEY', config.WORDS_API_KEY) @@ -23,11 +24,7 @@ def process(input, entities): 'Definition of ' + word + ':\n' + data['definitions'][0]['definition']).get_message() output['success'] = True except: - error_message = 'I couldn\'t find that definition.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - define comfort' - error_message += '\n - cloud definition' - error_message += '\n - what does an accolade mean?' + error_message = QUERY_ERROR.format('definition') + EXAMPLE_DEFINITIONS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/error_msg.py b/modules/src/error_msg.py new file mode 100644 index 00000000..dcf5144c --- /dev/null +++ b/modules/src/error_msg.py @@ -0,0 +1,55 @@ + +BASE_ERROR = "\nPlease ask me something else, like:" +QUERY_ERROR = "I couldn't find any {} matching your query." + BASE_ERROR +CONVERT_ERROR = "I couldn't convert between those {}." + BASE_ERROR +LOCATION_ERROR = "I couldn't get the {} at the location you specified." + BASE_ERROR + +EXAMPLE_ANIME = """ + - Death Note anime, + - Dragon ball super anime status, + - What is the anime rating of One Punch Man?""" + +EXAMPLE_BOOKS = """ + - book timeline + - harry potter book plot + - little women book rating""" + +EXAMPLE_CONVERSIONS = """ + - HKD to USD + - USD to EUR rate + - how much is 100 USD to INR""" + +EXAMPLE_DEFINITIONS = """ + - define comfort + - cloud definition + - what does an accolade mean?""" + +EXAMPLE_LYRICS = """ + - paradise lyrics + - lyrics of the song hall of fame + - What are the lyrics to see you again?""" + +EXAMPLE_MOVIES = """ + - batman movie + - iron man 2 movie plot + - What is the rating of happiness movie?""" + +EXAMPLE_TIME = """ + - time in new york + - india time + - time at paris""" + +EXAMPLE_VIDEOS = """ + - sia videos + - videos by eminem + - video coldplay""" + +EXAMPLE_WEATHER = """ + - tell me the weather in London + - weather Delhi + - What's the weather in Texas?""" + +EXAMPLE_WIKI = """ + - wikipedia barack + - html wiki + - who is sachin tendulkar""" \ No newline at end of file diff --git a/modules/src/help.py b/modules/src/help.py index 1b96b6b5..220cb906 100644 --- a/modules/src/help.py +++ b/modules/src/help.py @@ -2,35 +2,36 @@ def process(input, entities=None): - help = 'Hi there! I\'m Jarvis, your personal assistant.' - if entities is not None: + helper = 'Hi there! I\'m Jarvis, your personal assistant.\n' + if entities: if 'sender' in entities and 'first_name' in entities['sender']: - sender_name = entities['sender']['first_name'] - help = help.replace('there', sender_name) - help += '\n\nYou can tell me things like:' - help += '\n - define comfort' - help += '\n - iron man 2 movie plot' - help += '\n - tell me a joke/quote/fact' - help += '\n - wiki html' - help += '\n - anything you want book' - help += '\n - usd to eur rate' - help += '\n - death note anime' - help += '\n - time in seattle' - help += '\n - songs by linkin park' - help += '\n - shorten google.com' - help += '\n - weather in london' - help += '\n - videos of sia' - help += '\n - flip a coin' - help += '\n - roll a die' - help += '\n - show a random xkcd comic' - help += '\n - latest news' - help += '\n - paradise lyrics' - help += '\n\nI\'m always learning, so do come back and say hi from time to time!' - help += '\nHave a nice day. :)' + helper = helper.replace('there', entities['sender']['first_name']) + helper += """ + You can tell me things like: + - define comfort + - iron man 2 movie plot + - tell me a joke/quote/fact + - wiki html + - anything you want book + - usd to eur rate + - death note anime + - time in seattle + - songs by linkin park + - shorten google.com + - weather in london + - videos of sia + - flip a coin + - roll a die + - show a random xkcd comic + - latest news + - paradise lyrics + + I'm always learning, so do come back and say hi from time to time! + Have a nice day. :)""" output = { 'input': input, - 'output': TextTemplate(help).get_message(), + 'output': TextTemplate(helper).get_message(), 'success': True } return output diff --git a/modules/src/lyrics.py b/modules/src/lyrics.py index 7f78bd84..c1b56b03 100644 --- a/modules/src/lyrics.py +++ b/modules/src/lyrics.py @@ -4,6 +4,7 @@ import config from templates.button import * +from error_msg import QUERY_ERROR, EXAMPLE_LYRICS MUSIXMATCH_API_KEY = os.environ.get('MUSIXMATCH_API_KEY', config.MUSIXMATCH_API_KEY) @@ -54,11 +55,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any lyrics matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - paradise lyrics' - error_message += '\n - lyrics of the song hall of fame' - error_message += '\n - What are the lyrics to see you again?' + error_message = QUERY_ERROR.format('lyrics') + EXAMPLE_LYRICS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/movie.py b/modules/src/movie.py index f3fcf409..79834794 100644 --- a/modules/src/movie.py +++ b/modules/src/movie.py @@ -2,6 +2,7 @@ import requests_cache from templates.button import * +from error_msg import QUERY_ERROR, EXAMPLE_MOVIES def process(input, entities): @@ -20,11 +21,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find that movie.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - batman movie' - error_message += '\n - iron man 2 movie plot' - error_message += '\n - What is the rating of happyness movie?' + error_message = QUERY_ERROR.format('movie') + EXAMPLE_MOVIES output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/music.py b/modules/src/music.py index 17913a7e..4b8ad28d 100644 --- a/modules/src/music.py +++ b/modules/src/music.py @@ -34,11 +34,13 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any music matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - hymn for the weekend song' - error_message += '\n - linkin park songs' - error_message += '\n - play hotel california' + error_message = """\ + I couldn't find any music matching your query. + Please ask me something else, like: + - hymn for the weekend song + - linkin park songs + - play hotel california""" + output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/request.py b/modules/src/request.py index 09fb9204..5af30d4f 100644 --- a/modules/src/request.py +++ b/modules/src/request.py @@ -2,9 +2,9 @@ def process(input, entities=None): - request = 'Kindly use the following buttons to:' - request += '\n - Request a new feature, by including some sample queries and their expected results.' - request += '\n - Report a bug (I couldn\'t handle the query and/or gave unexpected results), by including your search query and the expected result.' + request = """Kindly use the following buttons to: + - Request a new feature, by including some sample queries and their expected results. + - Report a bug (I couldn't handle the query and/or gave unexpected results), by including your search query and the expected result.""" template = ButtonTemplate(request) template.add_web_url('File an Issue', 'https://github.com/swapagarwal/JARVIS-on-Messenger/issues/new') template.add_web_url('Chat with my Master', 'https://gitter.im/swapagarwal/JARVIS-on-Messenger') diff --git a/modules/src/time.py b/modules/src/time.py index ca572e33..5f5d5294 100644 --- a/modules/src/time.py +++ b/modules/src/time.py @@ -27,11 +27,7 @@ def process(input, entities): 'abbreviation']).get_message() output['success'] = True except: - error_message = 'I couldn\'t get the time at the location you specified.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - time in new york' - error_message += '\n - india time' - error_message += '\n - time at paris' + error_message = LOCATION_ERROR.format('time') + EXAMPLE_TIME output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/url.py b/modules/src/url.py index 5a17db65..3b632911 100644 --- a/modules/src/url.py +++ b/modules/src/url.py @@ -35,11 +35,12 @@ def process(input, entities): output['output'] = TextTemplate(response).get_message() output['success'] = True except: - error_message = 'I couldn\'t perform that action.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - shorten google.com' - error_message += '\n - give me a short version of bing.com' - error_message += '\n - expand http://goo.gl/7aqe' + error_message = """\ + I couldn't perform that action. + Please ask me something else, like: + - shorten google.com + - give me a short version of bing.com + - expand http://goo.gl/7aqe""" output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/video.py b/modules/src/video.py index 69f64762..3eb62a17 100644 --- a/modules/src/video.py +++ b/modules/src/video.py @@ -6,6 +6,7 @@ import config from templates.generic import * from templates.text import TextTemplate +from error_msg import QUERY_ERROR YOUTUBE_DATA_API_KEY = os.environ.get('YOUTUBE_DATA_API_KEY', config.YOUTUBE_DATA_API_KEY) @@ -33,11 +34,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any videos matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - sia videos' - error_message += '\n - videos by eminem' - error_message += '\n - video coldplay' + error_message = QUERY_ERROR.format('videos') + EXAMPLE_VIDEOS output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/weather.py b/modules/src/weather.py index c238ffd7..c767c7e5 100644 --- a/modules/src/weather.py +++ b/modules/src/weather.py @@ -4,6 +4,7 @@ import config from templates.text import TextTemplate +from error_msg import LOCATION_ERROR, EXAMPLE_WEATHER MAPQUEST_CONSUMER_KEY = os.environ.get('MAPQUEST_CONSUMER_KEY', config.MAPQUEST_CONSUMER_KEY) OPEN_WEATHER_MAP_ACCESS_TOKEN = os.environ.get('OPEN_WEATHER_MAP_ACCESS_TOKEN', config.OPEN_WEATHER_MAP_ACCESS_TOKEN) @@ -29,11 +30,7 @@ def process(input, entities): temperature_in_fahrenheit) + ' ' + degree_sign + 'F\n- Info provided by OpenWeatherMap').get_message() output['success'] = True except: - error_message = 'I couldn\'t get the weather info you asked for.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - tell me the weather in London' - error_message += '\n - weather Delhi' - error_message += '\n - What\'s the weather in Texas?' + error_message = LOCATION_ERROR.format('weather') + EXAMPLE_WEATHER output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output diff --git a/modules/src/wiki.py b/modules/src/wiki.py index 7ef7c61d..88d4dc2b 100644 --- a/modules/src/wiki.py +++ b/modules/src/wiki.py @@ -2,6 +2,7 @@ from templates.generic import * from templates.text import TextTemplate +from error_msg import QUERY_ERROR, EXAMPLE_WIKI def process(input, entities): @@ -47,11 +48,7 @@ def process(input, entities): output['output'] = template.get_message() output['success'] = True except: - error_message = 'I couldn\'t find any wikipedia results matching your query.' - error_message += '\nPlease ask me something else, like:' - error_message += '\n - wikipedia barack' - error_message += '\n - html wiki' - error_message += '\n - who is sachin tendulkar' + error_message = QUERY_ERROR.format('wikipedia results') + EXAMPLE_WIKI output['error_msg'] = TextTemplate(error_message).get_message() output['success'] = False return output