Skip to content

Update discordInterface.py #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 60 additions & 16 deletions RecipeBot.py/discordInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -27,14 +29,18 @@ 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 "]
welcomesAfternoon = ["Good Afternoon"]
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():
Expand All @@ -50,17 +56,17 @@ async def on_message(message):

def output(word):
return message.channel.send(word)

if message.author == client.user:
return

if messages in welcomes1 and Flag.Greet == 0:
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:
Expand Down Expand Up @@ -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")

Expand All @@ -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()

Expand All @@ -151,3 +193,5 @@ def output(word):
await output("Try asking me about " + random.choice(convoStarters))

client.run(Token)