Permalink
Cannot retrieve contributors at this time
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?
Vacation-chatbot/chatbot.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
131 lines (90 sloc)
4.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
import time | |
client = discord.Client() | |
token = 'Nzc2ODIzNzU0MDA0NDk2NDQ1.X66ffw.XOxA0IHsRdEBjkyvThwCo-DTCCM' | |
class Flag: # copied the concept from 'Recipe chatbot' project | |
counter = 0 | |
# Lists | |
greets = ['hi','hello','hey','heyy','heyyy','hey there','what\'s up','good morning','good afternoon','good evening','whatup','yo whatup'] | |
discord1 = 'hey! hope you\'re having a good day, i\'m your vacation chatbot, i\'ll help you choose a holiday destination, let\'s start? ' | |
affirm = ['sure thing','okay','ok','yeah','yeah sure','yes','sure','why not','yup','yeah go on','yeap','yes go on','yes sure','ok cool'] | |
discord2 = "Great! so which continent you\'d like to go to?" | |
negation = ['none','no','nope','not','not yet','later','maybe later','not interested','not really','never','no thanks','yeah no','yeah no thanks'] | |
discord3 = 'following are the top countries/places in {}:' | |
asia = ['Japan','Singapore','China','South Korea','India'] | |
europe = ['Spain','NetherLands','Italy','Belgium','Croatia'] | |
africa = ['Egypt','Kenya','South Africa','Morocco','Sychelles'] | |
north_america = ['USA','Mexico','Canada','Dominican Republic','Cuba'] | |
south_america = ['Ecuador','Colombia','Peru','Chile','Bolivia'] | |
antarctica = ['Antarctic Peninsula', 'South Shetland Islands','Drake Passage','Falkland Islands','South Georgia'] | |
oceania = ['Australia','New Zealand','Fiji','Tahiti','Palau'] | |
option = "let me know if you want to see top countries from any other continent as well" | |
@client.event | |
async def on_ready(): | |
print('logged in as {0.user}'.format(client)) | |
@client.event | |
async def on_message(message): | |
time.sleep(1) # 1 second delay for more natural responses | |
messages = message.content.lower() # to handle input from the user in discord | |
response = message.channel.send # required to invoke response from bot | |
if message.author == client.user: # copied from discord.py documentation | |
return | |
if messages in greets: # initial greetings | |
Flag.counter = 1 | |
await response(discord1) | |
elif messages in affirm and Flag.counter == 1: # first response | |
Flag.counter = 2 | |
await response(discord2) | |
elif ('asia' or 'Asia') in messages and Flag.counter == 2: # asia | |
await response(discord3.format('Asia')) | |
for i in range(len(asia)): | |
name = str(asia[i]) | |
await response(name) | |
await response(option) | |
elif ('europe' or 'Europe') in messages and Flag.counter == 2: # europe | |
await response(discord3.format('Europe')) | |
for i in range(len(europe)): | |
name = str(europe[i]) | |
await response(name) | |
await response(option) | |
elif ('africa' or 'Africa') in messages and Flag.counter == 2: # africa | |
await response(discord3.format('Africa')) | |
for i in range(len(africa)): | |
name = str(africa[i]) | |
await response(name) | |
await response(option) | |
elif ('north' or 'North') in messages and Flag.counter == 2: # north america | |
await response(discord3.format('North America')) | |
for i in range(len(north_america)): | |
name = str(north_america[i]) | |
await response(name) | |
await response(option) | |
elif ('south' or 'South') in messages and Flag.counter == 2: # south america | |
await response(discord3.format('South America')) | |
for i in range(len(south_america)): | |
name = str(south_america[i]) | |
await response(name) | |
await response(option) | |
elif ('antarctica' or 'Antarctica') in messages and Flag.counter == 2: # antarctica | |
await response('following are the top places in Antarctica: ') | |
for i in range(len(antarctica)): | |
name = str(antarctica[i]) | |
await response(name) | |
await response(option) | |
elif ('oceania' or 'Oceania') in messages and Flag.counter == 2: # oceania | |
await response(discord3.format('Oceania')) | |
for i in range(len(oceania)): | |
name = str(oceania[i]) | |
await response(name) | |
await response(option) | |
elif messages in negation and Flag.counter != 0: | |
await response('okay no worries, see you later!') | |
elif ('bye' or 'Bye') in messages: | |
Flag.counter = 0 | |
await response('Take care bye!') | |
else: | |
await response('sorry i didn\'t understand, can you type again? make sure you dont use numbers') | |
Flag.counter = 1 | |
time.sleep(0.5) | |
await response('Wanna choose a holiday destination?') | |
client.run(token) |