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
import discord
import nltk
from nltk.stem import PorterStemmer
from dotenv import load_dotenv
import os
import random
from nltk.stem.wordnet import WordNetLemmatizer
import requests
import json
import InsertData
import searchData
import createTable
import string
from lxml import html
from googlesearch import search
from bs4 import BeautifulSoup
import speech_recognition as sr
import time
createTable.createMain()
lem = WordNetLemmatizer()
ps = PorterStemmer()
messageStem =[]
messageLower = []
load_dotenv()
token = os.getenv('DISCORD_TOKEN') #Gets token from env file for more security. Change to a token to work with your chatbot.
client = discord.Client()
async def akinator(message):
await message.channel.send("Is your character a male or a female? M/F")
def check(m):
return "" in m.content and m.channel == message.channel and m.author == message.author
q1 = await client.wait_for("message", check = check)
q1 = q1.content.upper()
if q1=="M":
await message.channel.send("Is he a main character? Y/N")
q2 = await client.wait_for("message", check = check)
q2 = q2.content.upper()
if q2 =="Y":
await message.channel.send("Does he wear a spider costume? Y/N")
q3 = await client.wait_for("message", check = check)
q3 = q3.content.upper()
if q3=="Y":
return("Spiderman")
else:
await message.channel.send("Does he wear an iron costume? Y/N")
q4 = await client.wait_for("message", check = check)
q4 = q4.content.upper()
if q4=="Y":
return("Ironman")
else:
await message.channel.send("Does he have a hammer? Y/N")
q5 = await client.wait_for("message", check = check)
q5 = q5.content.upper()
if q5=="Y":
return("Thor")
else:
await message.channel.send("Does he have a star on his shield? Y/N")
q6 = await client.wait_for("message", check = check)
q6 = q6.content.upper()
if q6 =="Y":
return("Captain America")
else:
await message.channel.send("Does he have green skin? Y/N")
q7 = await client.wait_for("message", check = check)
q7 = q7.content.upper()
if q7=="Y":
return("Hulk")
else:
await message.channel.send("Does he have the infinity glove? Y/N")
q8 = await client.wait_for("message", check = check)
q8 = q8.content.upper()
if q8=="Y":
return("Thanos")
else:
await message.channel.send("Does he have Iron claws? Y/N")
q9 = await client.wait_for("message", check = check)
q9 = q9.content.upper()
if q9=="Y":
return("Wolverine")
else:
await message.channel.send("Does he have an amazing ability to heal himself from anything? Y/N")
q10= await client.wait_for("message", check = check)
q10= q10.content.upper()
if q10=="Y":
return("Deadpool")
else:
await message.channel.send("Does he have a mistical cape? Y/N")
q11= await client.wait_for("message", check = check)
q11 = q11.content.upper()
if q11=="Y":
return("Doctor Strange")
else:
await message.channel.send("Is he the god of cheating? Y/N")
q12 = await client.wait_for("message", check = check)
q12 = q12.content.upper()
if q12=="Y":
return("Loki")
else:
await message.channel.send("Is he the protector of Wakanda? Y/N")
q13 = await client.wait_for("message", check = check)
q13 = q13.content.upper()
if q13=="Y":
return("Black Panther")
else:
await message.channel.send("Can he manipulate size and mass? Y/N")
q14 = await client.wait_for("message", check = check)
q14 = q14.content.upper()
if q14=="Y":
return("Hawkeye")
else:
await message.channel.send("Does he consume planets? Y/N")
q15 = await client.wait_for("message", check = check)
q15 = q15.content.upper()
if q15=="Y":
return("Galactus")
else:
await message.channel.send("Does he have an eye bandage like pirates do? Y/N")
q16 = await client.wait_for("message", check = check)
q16 = q16.content.upper()
if q16=="Y":
return("Nick Fury")
else:
await message.channel.send("Is he believed to be the reincarnation of someone after coming back from a supposed death? Y/N")
q17 = await client.wait_for("message", check = check)
q17 = q17.content.upper()
if q17=="Y":
return("Bucky Barnes")
else:
await message.channel.send("Does he have the power to generate and control magnetic fields? Y/N")
q18 = await client.wait_for("message", check = check)
q18 = q18.content.upper()
if q18=="Y":
return("Magneto")
else:
await message.channel.send("Can he shrink to the size of an insect? Y/N")
q19 = await client.wait_for("message", check = check)
q19 = q19.content.upper()
if q19=="Y":
return("Ant-Man")
else:
await message.channel.send("Does he have the symbiote's autonomous capabilities? Y/N")
q20= await client.wait_for("message", check = check)
q20= q20.content.upper()
if q20=="Y":
return("Carnage")
else:
await message.channel.send("Does he have an optic force blast? Y/N")
q21= await client.wait_for("message", check = check)
q21 = q21.content.upper()
if q21=="Y":
return("Cyclops")
else:
await message.channel.send("Is he blind? Y/N")
q22 = await client.wait_for("message", check = check)
q22 = q22.content.upper()
if q22=="Y":
return("Daredevil")
else:
await message.channel.send("Does he have energy absorption and projection, mind transference, and demonic summoning via dark mysticism and sorcery? Y/N")
q23 = await client.wait_for("message", check = check)
q23 = q23.content.upper()
if q23=="Y":
return("Doctor Doom")
else:
await message.channel.send("Does he have increased strength, speed, and endurance depending on the lunar cycle? Y/N")
q24 = await client.wait_for("message", check = check)
q24 = q24.content.upper()
if q24=="Y":
return("Moon Knight")
else:
await message.channel.send("Can he fly via tiny wings on his ankles? Y/N")
q25 = await client.wait_for("message", check = check)
q25 = q25.content.upper()
if q25=="Y":
return("Namor the Sub-Mariner")
else:
await message.channel.send("Does he have density control and solar energy projection? Y/N")
q26 = await client.wait_for("message", check = check)
q26 = q26.content.upper()
if q26=="Y":
return("Vision")
else:
await message.channel.send("Does he have a demonic motorcycle? Y/N")
q27 = await client.wait_for("message", check = check)
q27 = q27.content.upper()
if q27=="Y":
return("Ghost Rider")
else:
await message.channel.send("Does he utilize dual elemental guns, and helmet providing survivability in space, and formerly used a universal translator implant in his neck? Y/N")
q28 = await client.wait_for("message", check = check)
q28 = q28.content.upper()
if q28=="Y":
return("Star-Lord")
else:
await message.channel.send("Does he have a genius-level intellect and special abilities via robotic body? Y/N")
q29 = await client.wait_for("message", check = check)
q29 = q29.content.upper()
if q29=="Y":
return("Ultron")
else:
await message.channel.send("Does he have telekinesis via X-headgear, being one of the most powerful psychics? Y/N")
q30 = await client.wait_for("message", check = check)
q30 = q30.content.upper()
if q30=="Y":
return("Professor X")
else:
await message.channel.send("Is he a talking intergalactic tree? Y/N")
q31 = await client.wait_for("message", check = check)
q31 = q31.content.upper()
if q31=="Y":
return("Groot")
else:
await message.channel.send("Does he have a fiery form that enables flight and serves as damage shield? Y/N")
q32 = await client.wait_for("message", check = check)
q32 = q32.content.upper()
if q32=="Y":
return("Human Torch")
else:
await message.channel.send("Can he travel through space with the aid of his surfboard-like craft? Y/N")
q33 = await client.wait_for("message", check = check)
q33 = q33.content.upper()
if q33=="Y":
return("Silver Surfer")
else:
await message.channel.send("Is he an animal-like physiology with enhanced physical attributes and sharp claws and teeth? Y/N")
q34 = await client.wait_for("message", check = check)
q34 = q34.content.upper()
if q34=="Y":
return("Beast")
else:
await message.channel.send("Does he inhabit a cloned body of Captain America? Y/N")
q35 = await client.wait_for("message", check = check)
q35 = q35.content.upper()
if q35=="Y":
return("Red Skull")
else:
await message.channel.send("Does he have limited shapeshifting and camouflage? Y/N")
q36 = await client.wait_for("message", check = check)
q36 = q36.content.upper()
if q36=="Y":
return("Venom")
else:
await message.channel.send("Does he use a laser gun-equipped cane and a hollow-on-the-inside ornamental diamond stick-pin filled with sleeping gas? Y/N")
q37 = await client.wait_for("message", check = check)
q37 = q37.content.upper()
if q37=="Y":
return("Kingpin")
else:
await message.channel.send("Does he have unbrakeable skin? Y/N")
q38 = await client.wait_for("message", check = check)
q38 = q38.content.upper()
if q38=="Y":
return("Luke Cage")
else:
await message.channel.send("Is he one of the X-Men, possessing the superhuman ability to move at great speeds? Y/N")
q39 = await client.wait_for("message", check = check)
q39 = q39.content.upper()
if q39=="Y":
return("Quicksilver")
else:
await message.channel.send("Does he have the ability to see through the eyes of nearby birds? Y/N")
q40 = await client.wait_for("message", check = check)
q40 = q40.content.upper()
if q40=="Y":
return("Falcon")
else:
await message.channel.send("Does he have extreme superhuman elasticity, malleability, and endurance? Y/N")
q41 = await client.wait_for("message", check = check)
q41 = q41.content.upper()
if q41=="Y":
return("Mister Fantastic")
else:
await message.channel.send("Is he a master of chi, having the ability of self-duplication? Y/N")
q42 = await client.wait_for("message", check = check)
q42 = q42.content.upper()
if q42=="Y":
return("Shang-Chi")
else:
await message.channel.send("Does he have organic webbing and is able to cling to most surfaces? Y/N")
q43 = await client.wait_for("message", check = check)
q43 = q43.content.upper()
if q43=="Y":
return("Eddie Brock")
else:
await message.channel.send("Does she have slowed aging and enhanced immune system? Y/N")
q44 = await client.wait_for("message", check = check)
q44 = q44.content.upper()
if q44=="Y":
return("Black Widow")
else:
await message.channel.send("Does she have scientifically enhanced magic that includes reality warping and time manipulation? Y/N")
q45 = await client.wait_for("message", check = check)
q45 = q45.content.upper()
if q45=="Y":
return("Scarlet Whitch")
else:
await message.channel.send("Does she have superhuman strength, speed, endurance and stamina along with energy projection and absorption and flight? Y/N")
q46 = await client.wait_for("message", check = check)
q46 = q46.content.upper()
if q46=="Y":
return("Carol Danvers")
else:
await message.channel.send("Does she have the ability to come reborn like a pheonix after she dies? Y/N")
q47 = await client.wait_for("message", check = check)
q47 = q47.content.upper()
if q47=="Y":
return("Dark Pheonix")
else:
await message.channel.send("Does she have green skin and hair? Y/N")
q48 = await client.wait_for("message", check = check)
q48 = q48.content.upper()
if q48=="Y":
return("She-Hulk")
else:
await message.channel.send("Does she have the ability of shapeshifting? Y/N")
q49 = await client.wait_for("message", check = check)
q49 = q49.content.upper()
if q49=="Y":
return("Ms. Marvel")
else:
await message.channel.send("Can she fly via wasp wings? Y/N")
q50 = await client.wait_for("message", check = check)
q50 = q50.content.upper()
if q50=="Y":
return("The Wasp")
else:
await message.channel.send("Can she become invisible? Y/N")
q51 = await client.wait_for("message", check = check)
q51 = q51.content.upper()
if q51=="Y":
return("Invisible Woman")
else:
await message.channel.send("Does she have an all white costume? Y/N")
q52 = await client.wait_for("message", check = check)
q52 = q52.content.upper()
if q52=="Y":
return("Emma Frost")
else:
await message.channel.send("Does she have green skin? Y/N")
q53 = await client.wait_for("message", check = check)
q53 = q53.content.upper()
if q53=="Y":
return("Gamora")
else:
return("This are all the characters I know.")
async def voice_command(message):
#obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
await message.channel.send("Speak into the microphone")
audio = r.listen(source)
await message.channel.send("done send to google")
try:
await message.channel.send("Transcription: " + r.recognize_google(audio))
except sr.UnknownValueError:
await message.channel.send("Audio unintelligible")
except sr.RequestError as e:
await message.channel.send("Connot obtain results; {0}".format(e))
return r.recognize_google(audio)
def chatbot_query(query, index=0):
fallback = 'Sorry, I cannot think of a reply for that.'
result = ''
try:
search_result_list = list(search(query, tld="co.in", num=10, stop=3, pause=1))
page = requests.get(search_result_list[index])
tree = html.fromstring(page.content)
soup = BeautifulSoup(page.content, features="lxml")
article_text = ''
article = soup.findAll('p')
for element in article:
article_text += '\n' + ''.join(element.findAll(text = True))
article_text = article_text.replace('\n', '')
first_sentence = article_text.split('.')
first_sentence = first_sentence[0].split('?')[0]
chars_without_whitespace = first_sentence.translate(
{ ord(c): None for c in string.whitespace }
)
if len(chars_without_whitespace) > 0:
result = first_sentence
else:
result = fallback
return result
except:
if len(result) == 0: result = fallback
return result
async def getWeather(city, message):
getInfo = requests.get('https://api.openweathermap.org/data/2.5/weather?q=' + city + ',uk' + '&appid=bd9b2518321605c17d1b7fc13d1a4034')
if getInfo.status_code != 200:
await message.channel.send("are u kidding me? did you really think i wouldnt know the name of the cities in uk?!")
return
weather = getInfo.json()["weather"]
temp = getInfo.json()["main"]
tempKelvin = temp["temp"]
tempCelsius = round(tempKelvin - 273.15, 2)
for i in weather:
weatherMain = i["main"]
await message.channel.send("The weather is " + weatherMain + "y" + " with a temperature of " + str(tempCelsius))
if random.choice(range(9)) == 0:
await message.channel.send("Good merning, nice day fer fishing, ain't it? huh huh")
async def getMarvel(characterName, characterNameURL, message):
response = requests.get("http://gateway.marvel.com/v1/public/characters?name="+ characterName + "&ts=1&apikey=7c60178bd6e1196ab697f86dc654aa96&hash=37c7befca5d244893ffe8bcd8890cb5d")
Hfile = open("heroList.txt", "r")
Hlist = Hfile.read()
Hlist = Hlist.lower()
comics = ""
if response.json()["etag"] == "79ef3436d0dc139b17693635b99776556e29f495":
if characterName in Hlist:
desc = await searchDesc(characterName)
if desc == None:
userExist = await searchUser(message.author)
if userExist == None:
await add_user(message.author, characterName, comics)
else:
if "comics" not in newMessage:
await updateUser(message.author, userExist, comics)
await message.channel.send("I don't know about this character yet")
await message.channel.send("Tell me anything about the character please")
def check(m):
return characterName + " is" in m.content and m.channel == message.channel and m.author == message.author
newMessage = await client.wait_for("message", check = check)
print(newMessage)
newMessage = nltk.word_tokenize(newMessage.content)
print(newMessage)
name = characterName
desc = ""
if "comics" in newMessage:
for i in range(len(newMessage)):
if newMessage[i] == "comics":
newMessage.append("")
if newMessage[i + 1] == "":
comics = ""
else:
comics = newMessage[i + 1]
await updateUser(message.author, userExist, comics)
await add_character(name, desc, comics)
await message.channel.send("saving data " + "name: " + characterName + " description: " + desc + " comics: " + comics + " saved")
return
else:
for i in newMessage:
if i == "is":
continue
if i == characterName:
continue
desc = desc + i
comics = ""
await add_character(name, desc, comics)
await message.channel.send("saving data " + "name: " + characterName + " description: " + desc + " comics: " + comics + " saved")
return
else:
await message.channel.send("A brief description of " + characterName + " is: " + desc)
else:
await message.channel.send("Dont think thats a character...")
return
response = response.json()["data"]["results"]
userExist = await searchUser(message.author)
if userExist == None:
await add_user(message.author, characterName, comics)
else:
await updateUser(message.author, characterName, comics)
for i in response:
description = i["description"]
if description != "":
await message.channel.send("A brief description of " + characterName + " is: " + description)
await add_character(characterName, description, comics)
else:
await message.channel.send("Im sorry but i dont know enough about this character. Could you please inform me of him?")
async def add_character(name, desc, comics):
database = r"C:\Users\fgust\OneDrive\Documents\chatbot/marvelDatabase.db"
# create a database connection
conn = InsertData.create_connection(database)
with conn:
# create a new character data
marvel = (name, desc, comics)
marvel_id = InsertData.create_marvel(conn, marvel)
async def add_user(name, character, comic):
database = r"C:\Users\fgust\OneDrive\Documents\chatbot/marvelDatabase.db"
# create a database connection
conn = InsertData.create_connection(database)
with conn:
# create a new character data
user = (str(name), character, comic)
user_id = InsertData.create_user(conn, user)
async def add_comics(name, characters):
database = r"C:\Users\fgust\OneDrive\Documents\chatbot/marvelDatabase.db"
# create a database connection
conn = InsertData.create_connection(database)
with conn:
# create a new character data
comics = (name, characters)
comics_id = create_comics(conn, comics)
async def searchDesc(name):
database = r"C:\Users\fgust\OneDrive\Documents\chatbot/marvelDatabase.db"
# create a database connection
conn = InsertData.create_connection(database)
with conn:
searchData.select_desc(conn, name)
async def searchUser(name):
database = r"C:\Users\fgust\OneDrive\Documents\chatbot/marvelDatabase.db"
# create a database connection
conn = InsertData.create_connection(database)
with conn:
searchData.select_user(conn, name)
async def updateUser(name, character, comic):
database = r"C:\Users\fgust\OneDrive\Documents\chatbot/marvelDatabase.db"
# create a database connection
conn = InsertData.create_connection(database)
with conn:
user = (character, comic, str(name))
InsertData.update_user(conn, user)
async def recommendUser():
database = r"C:\Users\fgust\OneDrive\Documents\chatbot/marvelDatabase.db"
# create a database connection
conn = InsertData.create_connection(database)
with conn:
searchData.select_reco(conn)
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
@client.event
async def on_member_join(member):
await member.create_dm()
await member.dm_channel.send(
f'Hi {member.name}, welcome to my Discord server!'
)
@client.event
async def on_message(message):
if message.author == client.user:
return
greetingsIN = [
'hello',
'hey',
'yo',
'greet',
'hi',
'sup',
]
greetingsOUT = [
'Hello!',
'Hey!',
'Yo!',
'Greetings!',
'Hi!',
'Hiya!',
"'Sup!",
]
if "voice command" in message.content:
message.content = await voice_command(message)
messageStem =[]
messageLower = []
messageToken = nltk.word_tokenize(message.content)
for w in messageToken:
messageLower.append(w.lower())
print(messageLower)
for w in messageLower:
messageStem.append(ps.stem(w))
print(messageStem)
if 'bitch' in messageStem:
await message.channel.send("Hey, let's not use foul language on the server. Okay?")
messageStem.clear()
messageLower.clear()
return
if 'shit' in messageStem:
await message.channel.send("Language.")
messageStem.clear()
messageLower.clear()
return
if 'fuck' in messageStem:
await message.channel.send("Come on, watch your langauge.")
return
for i in greetingsIN:
if i in messageStem:
response = random.choice(greetingsOUT)
await message.channel.send(response)
if 'how' in messageStem:
if 'you' in messageStem:
await message.channel.send("I'm good and you?")
if 'what' in messageStem:
if 'name' in messageStem:
await message.channel.send("My name's Totum. What's yours?")
if 'weather' in messageStem:
if 'is' in messageStem:
if 'in' in messageStem:
for i in range(len(messageLower)):
if messageLower[i] == "in":
messageLower.append("")
if messageLower[i + 1] == "":
await message.channel.send("Enter a city name, please.")
return
else:
city = messageLower[i + 1]
print(city)
await getWeather(city, message)
if "googl" in messageStem:
if "search" in messageStem:
simpleQuery = ""
for i in messageStem:
if i == "google" or i == "search":
continue
simpleQuery = simpleQuery + " " + i
await message.channel.send("Searching...")
answerResult = chatbot_query(simpleQuery)
if answerResult == 'Sorry, I cannot think of a reply for that.' or answerResult == "Can’t find what you’re looking for":
await message.channel.send(answerResult)
return
if answerResult == "Loading":
await message.channel.send("Can’t find what you’re looking for")
return
await message.channel.send("I found this for you.")
await message.channel.send(answerResult)
if "who" in messageStem:
if "is" in messageStem:
for i in range(len(messageLower)):
if messageLower[i] == "is":
messageLower.append("")
if messageLower[i + 1] == "":
await message.channel.send("I only know fictional characters, most of which are from the Marvel universe. Ask about one of those charcters and I'll see what I can tell you about them.")
return
elif messageLower[i + 2] != "":
characterName = messageLower[i + 1] + " " + messageLower[i + 2]
characterNameURL = messageLower[i + 1] + "%20" + messageLower[i + 2]
else:
characterName = messageLower[i + 1]
characterNameURL = characterName
print(characterName)
await getMarvel(characterName, characterNameURL, message)
if "recommend" in messageStem:
if "me" in messageStem:
recommendation = await recommendUser()
if recommendation == None:
await message.channel.send("Sorry but I don't have any recommendations for you yet")
else:
await message.channel.send("I recommend this comics to you: " + recommendation)
if 'comic' in messageStem:
if 'store' in messageStem:
await message.channel.send("What's your postcode?")
messageLower.clear()
messageStem.clear()
await postcode(message)
if "akinator" in messageToken:
answerAki = await akinator(message)
if answerAki == None:
await message.channel.send("Sorry, but I couldn't find what you were thinking of")
await message.channel.send("You were thinking of " + answerAki)
async def postcode(message):
def check(m):
return "cv" in m.content.lower() and m.channel == message.channel and m.author == message.author
newMessage = await client.wait_for("message", check=check)
newMessage = newMessage.content
postcode1 = newMessage
await google(message, postcode1)
def longitude(message, postcode1):
postcodem = postcode1
getInfo = requests.get('http://api.postcodes.io/postcodes/' + postcodem)
longitude = getInfo.json()["result"]["longitude"]
print(longitude)
return longitude
def latitude(message, postcode1):
postcodem = postcode1
getInfo = requests.get('http://api.postcodes.io/postcodes/' + postcodem)
latitude = getInfo.json()["result"]["latitude"]
print(latitude)
return latitude
async def google(message, postcode1):
long = str(longitude(message, postcode1))
lat = str(latitude(message, postcode1))
getInfo = requests.get('https://maps.googleapis.com/maps/api/place/textsearch/json?query=comic+book+stores&location=' + long + ',' + lat + '&radius=10000&key=AIzaSyB6frkOwZL20nQAzj0nCRHFUkEFVJ0XzC8')
find = getInfo.json()["results"]
name = []
openHour = []
for i in find:
name.append(i["name"])
for i in find:
openHour.append(i["opening_hours"])
if len(openHour) >= 9:
break
if openHour[0]["open_now"] == True:
await message.channel.send("A) " + name[0] + " is nearby and it's open, right now.")
else:
await message.channel.send("A) " + name[0] + " is closed, at the moment.")
if openHour[1]["open_now"] == True:
await message.channel.send("B) " + name[1] + " is close too. And it's open.")
else:
await message.channel.send("B) " + name[1] + " is closed.")
if openHour[1]["open_now"] == True:
await message.channel.send("C) " + name[2] + " is open and it's not too far away.")
else:
await message.channel.send("C) " + name[2] + " is fairly close by but it's closed, right now.")
def check(m):
return "" in m.content.lower() and m.channel == message.channel and m.author == message.author
await message.channel.send("Would you like the directions to one of the stores?")
newMessage = await client.wait_for("message", check=check)
newMessage = newMessage.content
newMessage = newMessage.lower()
if newMessage == "yes":
def check(m):
return "" in m.content.lower() and m.channel == message.channel and m.author == message.author
await message.channel.send("Which one?")
await message.channel.send("Option A, B or C?")
newMessage = await client.wait_for("message", check=check)
newMessage = newMessage.content
newMessage = newMessage.lower()
if newMessage == "a":
def check(m):
return "" in m.content.lower() and m.channel == message.channel and m.author == message.author
await message.channel.send("How would you like to get there?")
await message.channel.send("Driving, cycling, walking or transit?")
newMessage = await client.wait_for("message", check=check)
newMessage = newMessage.content
newMessage = newMessage.lower()
await comicStores(postcode1,name[0], newMessage, message)
elif newMessage == "b":
def check(m):
return "" in m.content.lower() and m.channel == message.channel and m.author == message.author
await message.channel.send("How would you like to get there?")
await message.channel.send("Driving, cycling, walking or transit?")
newMessage = await client.wait_for("message", check=check)
newMessage = newMessage.content
newMessage = newMessage.lower()
await comicStores(postcode1, name[1], newMessage, message)
elif newMessage == "c":
def check(m):
return "" in m.content.lower() and m.channel == message.channel and m.author == message.author
await message.channel.send("How would you like to get there?")
await message.channel.send("Driving, cycling, walking or transit?")
newMessage = await client.wait_for("message", check=check)
newMessage = newMessage.content
newMessage = newMessage.lower()
await comicStores(postcode1, name[2], newMessage, message)
else:
await message.channel.send("Not an option.")
elif newMessage == "no":
await message.channel.send("Okay, have a good day.")
else:
await message.channel.send("Not an option.")
async def comicStores(postcode1, destination, mode, message):
directionsMain = requests.get("https://maps.googleapis.com/maps/api/directions/json?origin=" + postcode1 + "&destination=" + destination + "&mode=" + mode + "&key=AIzaSyB6frkOwZL20nQAzj0nCRHFUkEFVJ0XzC8")
print(json.dumps(directionsMain.json(), sort_keys=True, indent=4))
directionsRoutes = directionsMain.json()["routes"]
for i in directionsRoutes:
directionsLegs = i["legs"]
for i in directionsLegs:
directionSteps = i["steps"]
direc = []
for i in directionSteps:
direc.append(i["html_instructions"])
fullDirection = ""
for i in direc:
fullDirection = fullDirection + "\n" + i
await message.channel.send(fullDirection)
await message.channel.send("You have arrived at your destination.")
client.run(token)