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..83374e68 --- /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 + + return help_methods.get_help_message('message')