Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
"""This is my main code. It is connected to discord and allows the user to get general advice from the chatbot when 'Hi' is inserted"""
# Some of the code below is based on this video https://www.youtube.com/watch?v=_0LXIvLDhBM
import discord
import asyncio
import time
#Not based on the video - based on python docs https://docs.python.org/3/library/sqlite3.html?highlight=sql#module-sqlite3:
import sqlite3
conn = sqlite3.connect('movies1.db')
c = conn.cursor()
conn.commit()
# based on video https://www.youtube.com/watch?v=_0LXIvLDhBM:
TOKEN = "NTEwODI4NDM2NTYyOTAzMDQw.Dsjl7Q.AWx3-OVldKI8RA27IcsZSrQqWCA"
client = discord.Client()
# Original code:
class Advice:
response = 0
class Films:
response1 = 0
class Weather:
response2 = 0
class Genre:
response3 = 0
class Advice2:
response4 = 0
# Films advice lists:
Old_Keywords = ['old', 'olden', 'old film', 'old films', 'olden films']
Recent_Keywords = ['recent', 'new', 'modern', 'recent films', 'new films', 'modern films']
# Weather advice lists:
RAINY_KEYWORDS = ['rainy', 'rain', 'wet', 'rainfall', 'precipitation', 'rainwater', 'stormy']
SUNNY_KEYWORDS = ['sunny', 'sunshine', 'bright', 'sun', 'cloudless']
STORMY_KEYWORDS = ['storm', 'stormy', 'blizzard', 'gale', 'gust', 'hurricane', 'cyclone', 'lightening', 'thunder',
'wind']
CLOUDY_KEYWORDS = ['cloudy', 'clouds', 'overcast', 'clouded', 'grey', 'bleak']
COLD_KEYWORDS = ['cold', 'icy', 'freezing', 'chilly', 'frosty', 'snowy']
# Topics of advice lists:
Weather1 = ['the weather', 'weather']
Movies = ['films', 'movies', 'Films', 'Movies']
MovieGenres = ['films (based on genre)', 'films(genre)', 'film(genres)', 'films(genre)', 'films(genres)', 'film genres', 'Genres', 'genres', 'movie genres']
Released = ['films (release date)', 'films release','When they were released', 'release', 'release date', 'release year', 'released']
# Replies lists:
Yes_Keywords = ['yes', 'why not', 'go ahead', 'sure', 'yep', 'yeah', 'alright', 'absolutely']
No_Keywords = ['no', 'nope', 'no thanks', 'nah', 'neither', 'No', 'Nope']
# Based on video mentioned at the top
@client.event
async def on_message(message):
# Original code:
if message.content == "cookie":
mymessage = ":cookie:"
if message.content == "Hi":
mymessage = "Hey! Would you like advice on anything?"
if message.content in Yes_Keywords or Advice2.response4 == 3:
Advice.response = 1
mymessage = "What would you like advice on? (Weather, films (release date), films (genre), or music?)"
elif message.content in Released and Advice.response == 1:
Films.response1 = 1
mymessage = "Shall I recommend some old films or recent ones? "
mymessage.lower()
elif message.content in Old_Keywords and Films.response1 == 1:
import webbrowser
new = 2
url = "https://www.google.co.uk/search?rlz=1C1CHBF_en-GBGB818GB818&ei=oI_bW4DSE8KGgQaen6TIDg&q=best+old+movies&oq=best+old+m&gs_l=psy-ab.3.0.0i20i263k1j0i67k1j0l8.11923.13416.0.15360.11.10.0.1.1.0.139.672.7j2.10.0....0...1c.1.64.psy-ab..0.11.746.6..35i39k1j0i131k1.74.9L7814dZ-2o"
webbrowser.open(url, new=new)
Advice2.response4 = 2
elif message.content in Recent_Keywords and Films.response1 == 1:
import webbrowser
new = 2
url = "https://www.google.co.uk/search?rlz=1C1CHBF_en-GBGB818GB818&ei=sI_bW5XBIqrAgAa6zI_gDQ&q=best+recent+movies&oq=best+recent+movies&gs_l=psy-ab.3..0i7i30k1l2j0j0i7i30k1l7.189510.191263.0.191580.11.11.0.0.0.0.110.841.8j3.11.0....0...1c.1.64.psy-ab..2.9.657...35i304i39k1j0i13k1j0i67k1.0.j7txHfr87Kc"
webbrowser.open(url, new=new)
Advice2.response4 = 2
elif message.content in MovieGenres and Advice.response == 1:
Genre.response3 = 1
mymessage = "What film genre would you like recommendations on? (Action, horror, comedy or romance) "
elif message.content == "Action" or message.content == "action" and Genre.response3 == 1:
mymessage = "Shall I recommend an old action movie or a recent action movie?"
Genre.response3 = 2
elif message.content in Old_Keywords and Genre.response3 == 2:
for row in c.execute("SELECT * FROM Action WHERE ReleaseYear < 2000"):
mymessage = row
Advice2.response4 = 2
elif message.content in Recent_Keywords and Genre.response3 == 2:
for row in c.execute("SELECT * FROM Action WHERE ReleaseYear > 2000"):
mymessage = row
Advice2.response4 = 2
elif message.content == "Comedy" or message.content == "comedy" and Genre.response3 == 1:
mymessage = "Shall I recommend an old comedy movie or a recent one?"
Genre.response3 = 3
elif message.content in Old_Keywords and Genre.response3 == 3:
for row in c.execute("SELECT * FROM Comedy WHERE ReleaseYear < 2000"):
mymessage = row
Advice2.response4 = 2
elif message.content in Recent_Keywords and Genre.response3 == 3:
for row in c.execute("SELECT * FROM Comedy WHERE ReleaseYear > 2000"):
mymessage = row
Advice2.response4 = 2
elif message.content == "Horror" or message.content == "horror" and Genre.response3 == 1:
mymessage = "Shall I recommend an old horror movie or a recent one?"
Genre.response3 = 4
elif message.content in Old_Keywords and Genre.response3 == 4:
for row in c.execute("SELECT * FROM Horror WHERE ReleaseYear < 2000"):
mymessage = row
Advice2.response4 = 2
elif message.content in Recent_Keywords and Genre.response3 == 4:
for row in c.execute("SELECT * FROM Horror WHERE ReleaseYear > 2000"):
mymessage = row
Advice2.response4 = 2
elif message.content == "Romance" or message.content == "romance" and Genre.response3 == 1:
mymessage = "Shall I recommend an old horror movie or a recent one?"
Genre.response3 = 5
elif message.content in Old_Keywords and Genre.response3 == 5:
for row in c.execute("SELECT * FROM Romance WHERE ReleaseYear < 2005"):
mymessage = row
Advice2.response4 = 2
elif message.content in Recent_Keywords and Genre.response3 == 5:
for row in c.execute("SELECT * FROM Romance WHERE ReleaseYear > 2005"):
mymessage = row
Advice2.response4 = 2
elif message.content in Weather1 and Advice.response == 1:
Weather.response2 = 1
mymessage = "Describe the weather to me in a sentence for advice..."
elif Weather.response2 == 1:
word = message.content.split(" ")
for item in word:
if item in RAINY_KEYWORDS:
mymessage = "Wear a raincoat and take an umbrella to avoid getting wet!"
break
Advice2.response4 = 2
elif item in SUNNY_KEYWORDS:
mymessage = "Make sure to wear sunscreen and try to avoid being exposed to the sun for a long time!"
break
Advice2.response4 = 2
elif item in STORMY_KEYWORDS:
mymessage ="Try to avoid leaving the house and if you do leave the house, dress warm and don't forget a raincoat!"
break
Advice2.response4 = 2
elif item in CLOUDY_KEYWORDS:
mymessage = "You should take an umbrella in case it rains!"
break
Advice2.response4 = 2
elif item in COLD_KEYWORDS:
mymessage = "Wear a coat to avoid the cold! Wearing gloves and a hat will also help to keep you warm!"
break
Advice2.response4 = 2
#if Advice2.response4 == 2:
# mymessage = "Would you like advice on anything else?"
# Advice2.response4 = 3
else:
pass
if Advice2.response4 == 2:
Advice2.response4 = 3
#elif Advice2.response4 == 2:
# mymessage = "Would you like advice/recommendations on anything else?"
# Advice2.response4 = 3
await client.send_message(message.channel, mymessage)
@client.event
async def on_ready():
print("Bot is ready")
client.run(TOKEN)