diff --git a/RecipeBot.py/discordInterface.py b/RecipeBot.py/discordInterface.py index 3c4ab4a..2aa443f 100644 --- a/RecipeBot.py/discordInterface.py +++ b/RecipeBot.py/discordInterface.py @@ -4,9 +4,11 @@ import re import Logic as API, random import datetime +from discord.ext import commands # Discord Token -Token = 'NzczMTg4Njk1MTk2MDQxMjM3.X6FmFg.UOOJjO2NfKa9fotyZLXymbj118A' +#Token = 'NzczMTg4Njk1MTk2MDQxMjM3.X6FmFg.UOOJjO2NfKa9fotyZLXymbj118A' +Token = 'NzgxNzI1NzgwOTk5NjY3NzIy.X8B03Q.UyLS1H4WDnR96pYEr2sfcvQ2Cck' # Creating log file logger = logging.getLogger('discord') @@ -27,6 +29,10 @@ class Flag: Greet = 0 Recipe = 0 Chat = 0 + Game = 0 + gameNumber = 0 + setAlarm = 0 + textToVoice = 0 # Lists welcomesDay = ["Good morning ", "Rise and shine ", "Top of the morning to you ", "Wakey, wakey, eggs and bakey ", "Morning "] @@ -34,7 +40,7 @@ class Flag: welcomesNight = ["Good evening ", "Still awake "] welcomes1 = ["hello", "hi", "hey", "hiya", "heya", "good morning!", "how you doing", "how're you doing", "howre you doing", "good morning", "good afternoon", "good evening"] -convoStarters = ["recipes", "food", "how I'm doing"] +convoStarters = ["recipes", "food", "how you're doing"] @client.event async def on_ready(): @@ -50,7 +56,7 @@ async def on_message(message): def output(word): return message.channel.send(word) - + if message.author == client.user: return @@ -58,9 +64,9 @@ def output(word): Flag.Greet = 1 author = str(message.author) lettersAuthor = " ".join(re.findall("[a-zA-Z]+", author)) - if hours < 13: + if hours <= 13: await output(random.choice(welcomesDay) + str(lettersAuthor) + "!") - elif hours >= 13: + elif hours > 13: await output(random.choice(welcomesNight) + str(lettersAuthor) + "!") elif len(re.findall(r'\w* you doing', messages)) != 0: @@ -109,21 +115,20 @@ def output(word): for i in range(int(messages)): await message.author.send(API.Recipes(hits[i]).print()) - Flag.Recipe = 4 await output("Are there any other recipes you want to see?") + Flag.Recipe = 4 + + if len(re.findall(r'\Ay', messages)) != 0 and Flag.Recipe == 4: + Flag.Recipe = 2 + await output("What new ingredients do you want to include?") + else: + Flag.Recipe = 0 + await output("Okay!") else: await output("Sorry, but that's out of my range!") await output("I've got " + str(len(API.Recipes.hit)) + " recipes for you to see! How many do you want?") - elif len(re.findall(r'\Ay', messages)) != 0 and Flag.Recipe == 4: - Flag.Recipe = 2 - await output("What new ingredients do you want to include?") - - elif len(re.findall(r'\An', messages)) != 0 and Flag.Recipe == 4: - Flag.Recipe = 0 - await output("Okay! Hope I helped") - elif "help" in messages: await output("I can give you recipes based in the ingredients you enter! Just ask about what recipes I have") @@ -141,8 +146,45 @@ def output(word): elif "winner winner" in messages: await output("chicken dinner") - - elif "quit" in messages or "goodbye" in messages: + + elif "game" in messages and Flag.Game == 0: + await output("Would you like to play a number game?") + Flag.Game = 1 + + elif (len(re.findall(r'\Ay', messages)) != 0 or "sure" in messages) and Flag.Game == 1: + Flag.gameNumber = random.randint(0, 100) + Flag.Game = 2 + await output("Please enter an integer from 0 to 100, input 'e' to exit") + + elif Flag.Game == 2 and 'e' != messages: + if int(messages) > Flag.gameNumber : + await output("Guess number is larger than target number, please try again, input 'e' to exit") + elif int(messages) < Flag.gameNumber : + await output("Guess number is smaller than target number, please try again, input 'e' to exit") + elif int(messages) == Flag.gameNumber : + Flag.Game = 0 + await output("Congratulations! You're right") + + elif "e" == messages : + if Flag.Game != 0: + Flag.Game = 0 + await output("Looking forward to playing again") + if Flag.setAlarm != 0: + Flag.setAlarm = 0 + await output("The alarm has been cancelled for you") + + elif 'clock' in messages or 'noti' in messages or 'alarm' in messages and Flag.setAlarm == 0: + Flag.setAlarm = 1 + await output("How long do you want to set the alarm clock? Please input 10 minutes, input 'e' to exit") + + elif Flag.setAlarm == 1: + if '10' in messages: + await output("The alarm clock after 10 minutes has been set for you") + + elif "text" in messages or "voice" in messages : + await output("Please prefix the text with '/tts'") + + elif "quit" in messages: await output("It was lovely talking to you, goodbye!") exit() @@ -151,3 +193,5 @@ def output(word): await output("Try asking me about " + random.choice(convoStarters)) client.run(Token) + +