From d6a4e39c0a0fbd0887a9e2d8bc59052f64b48c41 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 17 Aug 2017 10:21:29 -0700 Subject: [PATCH 1/2] Adding in wolfram alpha functionality --- Dockerfile | 2 +- Dockerfile-test-env | 5 ++--- app/dragon-bot.py | 9 ++++++++- app/help_methods.py | 5 +++++ app/wolfram.py | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 app/wolfram.py diff --git a/Dockerfile b/Dockerfile index 8aa63a52..cf47f1c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.6.2-alpine3.6 LABEL name="Dragon Bot" RUN apk update && apk add --no-cache docker -RUN pip install requests discord.py docker pybooru +RUN pip install requests discord.py docker pybooru wolframalpha ADD app /app CMD python app/dragon-bot.py \ No newline at end of file diff --git a/Dockerfile-test-env b/Dockerfile-test-env index 4613d3aa..4b34c49a 100644 --- a/Dockerfile-test-env +++ b/Dockerfile-test-env @@ -2,12 +2,11 @@ FROM python:3.6.2-alpine3.6 LABEL name="Dragon Bot Test environment" RUN apk update && apk add --no-cache vim docker -RUN pip install requests discord.py docker pybooru pylint +RUN pip install requests discord.py docker pybooru pylint wolframalpha ADD app /app RUN printf "\n\nTesting your python code for errors\n\n" && \ pylint -E /app/*.py -RUN printf "\n#########################\nRun dragon bot by typing \npython dragon-bot.py\n#########################\n\n" - WORKDIR /app +RUN printf "\n#########################\n Run dragon bot by typing \n python dragon-bot.py\n#########################\n\n" diff --git a/app/dragon-bot.py b/app/dragon-bot.py index d19450d1..d3ffc918 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -12,6 +12,7 @@ import excuse import help_methods import lewds import wallpaper +import wolfram # Client object client = discord.Client() @@ -50,7 +51,13 @@ async def on_message(message): ##### Looks like discord supports mentioning the bot. #### Need to think of something to do here if client.user.mentioned_in(message): - print('fuck u') + await client.send_message( + message.channel, + "{} ```{}```".format( + message.author.mention, + wolfram.answer_question(message.content) + ) + ) if message.content.startswith('!8ball'): await client.send_message( diff --git a/app/help_methods.py b/app/help_methods.py index 43d4403f..d1b8a720 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -44,6 +44,11 @@ def get_help_message(method): 'Returns the URL for a 4k wallpaper. You can enter', 'a search term as well, for example, !wallpaper, or', ', !wallpaper flowers. Supports multiple tags.' + ], + 'message': [ + 'You can ask me a question directly and I will do my best to answer it.', + '\nUsage:\n\n@dragon-bot what is the capital of France?\n@dragon-bot 94*37', + '\n@dragon-bot how many calories in a bottle of wine?' ] } diff --git a/app/wolfram.py b/app/wolfram.py new file mode 100644 index 00000000..9588537e --- /dev/null +++ b/app/wolfram.py @@ -0,0 +1,18 @@ +import wolframalpha + +import help_methods + +def answer_question(message): + """ + answer_question(question) + + submits a request to the wolfram API and returns the response + """ + + if len(message.split()) > 1: + client = wolframalpha.Client('2LU2Y7-YJQTA7TL8E') + question = ' '.join(message.split()[1:]) + res = client.query(question) + return next(res.results).text + else: + return help_methods.get_help_message('message') From b0d01bb697fa6187128fe282048f3be29444accb Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 17 Aug 2017 10:23:12 -0700 Subject: [PATCH 2/2] Removing this unnecessary else --- app/wolfram.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/wolfram.py b/app/wolfram.py index 9588537e..83374e68 100644 --- a/app/wolfram.py +++ b/app/wolfram.py @@ -14,5 +14,5 @@ def answer_question(message): question = ' '.join(message.split()[1:]) res = client.query(question) return next(res.results).text - else: - return help_methods.get_help_message('message') + + return help_methods.get_help_message('message')