Merged in wolfram (pull request #30)

Adding in wolfram alpha functionality, see #21
This commit is contained in:
Luke Robles 2017-08-17 18:57:14 +00:00
commit 50515caef5
5 changed files with 34 additions and 5 deletions

View File

@ -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

View File

@ -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"

View File

@ -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(

View File

@ -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?'
]
}

18
app/wolfram.py Normal file
View File

@ -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')