From b5704ff8a41b2c90d292f92a011807b388a45737 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 12 Aug 2017 10:17:33 -0700 Subject: [PATCH] adding my 8ball code to dragon bot, see #13 --- app/define_word.py | 6 +++--- app/dragon-bot.py | 7 +++++++ app/eight_ball.py | 47 +++++++++++++++++++++++++++++++++++++++++++++ app/help_methods.py | 12 ++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 app/eight_ball.py diff --git a/app/define_word.py b/app/define_word.py index 2f0842d5..067c5efc 100644 --- a/app/define_word.py +++ b/app/define_word.py @@ -7,7 +7,7 @@ def get_definition(content): grabs a definition from urban dictionary """ - if len(content.split()) > 1: + if len(content.split()) > 1: word = content.split()[1:] try: definition = requests.get( @@ -18,5 +18,5 @@ def get_definition(content): definition = 'No definition found' return "`{}`\n```{}```".format(' '.join(word), definition) - else: - return help_methods.get_help_message('define') + + return help_methods.get_help_message('define') diff --git a/app/dragon-bot.py b/app/dragon-bot.py index e9300396..02564d1a 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -3,6 +3,7 @@ import sys import requests import os +import eight_ball import define_word import help_methods import discord @@ -134,6 +135,12 @@ async def on_message(message): if client.user.mentioned_in(message): print('fuck u') + if message.content.startswith('!8ball'): + await client.send_message( + message.channel, + eight_ball.check_8ball(message.content) + ) + if message.content.startswith('!define'): await client.send_message( message.channel, diff --git a/app/eight_ball.py b/app/eight_ball.py new file mode 100644 index 00000000..ca489677 --- /dev/null +++ b/app/eight_ball.py @@ -0,0 +1,47 @@ +import random +import sys + +import help_methods + +def check_8ball(question): + """ + check_8ball(question) + + Takes in a question and returns a random answer from an 8ball. + To add more responses, simply add it to one of the lists below + """ + if len(question.split()) > 1: + question = question.split()[1:] + + positive_responses = [ + 'As I see it, yes', + 'It is certain', + 'It is decidedly so', + 'Most likely', + 'Oh for sure brother', + 'Outlook good', + 'Signs point to yes', + 'Without a doubt', + 'Yes, definitely', + 'Yes', + 'You can count on it', + ] + negative_responses = [ + 'Dont count on it', + 'My sources say no', + 'My thoughts are.....no', + 'Outlook not so good', + 'Very doubtful', + ] + noncommittal_responses = [ + 'Ask again later', + 'Better not tell you now', + 'Can\'t answer that right now', + 'Concentrate and ask again', + 'Reply hazy try again', + ] + + responses = positive_responses + negative_responses + noncommittal_responses + return random.choice(responses) + + return help_methods.get_help_message('8ball') \ No newline at end of file diff --git a/app/help_methods.py b/app/help_methods.py index 99ca526e..75a809c6 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -1,5 +1,17 @@ def get_help_message(method): + """ + get_help_message(method) + + Returns the information and usage of each of dragon bot's funtions. + When adding a new feature to dragon bot, please add some information about + it here + """ + supported_methods = { + '8ball': [ + 'Ask dragon bot a question and it will give you an 8ball response', + '\n\nUsage: !8ball Will I win the lottery tomorrow?' + ], 'decide': [ 'Dragon-bot will help make the tough decisions for you', '\n\n!decide option 1 or option 2.\n\nIf thre is only',