From b55f31e89f86595b74b4e50897ab7eb17e478404 Mon Sep 17 00:00:00 2001 From: bodlah Date: Wed, 25 Nov 2020 21:50:21 +0000 Subject: [PATCH] shifted code from api.py to chatbot.py --- chatbot.py | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 chatbot.py diff --git a/chatbot.py b/chatbot.py new file mode 100644 index 0000000..d6c8c56 --- /dev/null +++ b/chatbot.py @@ -0,0 +1,104 @@ +import discord + +client = discord.Client() + +token = 'Nzc2ODIzNzU0MDA0NDk2NDQ1.X66ffw.XOxA0IHsRdEBjkyvThwCo-DTCCM' + + +class Flag: + counter = 0 + + +# Lists +user1 = ['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? ' + +user2 = ['yeah','yeah sure','yes','sure','why not','yup','yeah go on','yeap'] +discord2 = "Great! so which continent you\'d like to go to?" + +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 = ['Fiji','Tahiti','Palau'] + +@client.event +async def on_ready(): + print('logged in as {0.user}'.format(client)) + + +@client.event +async def on_message(message): + 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: + return + + if messages in user1 and Flag.counter == 0: # initial greetings + Flag.counter = 1 + await response(discord1) + + + elif messages in user2 and Flag.counter == 1: # first response + Flag.counter = 2 + await response(discord2) + + elif 'asia' in messages and Flag.counter == 2: # asia + await response(discord3.format(messages)) + for i in range(len(asia)): + name = str(asia[i]) + await response(name) + + + elif 'europe' in messages and Flag.counter == 2: # europe + await response(discord3.format(messages)) + for i in range(len(europe)): + name = str(europe[i]) + await response(name) + + + elif 'africa' in messages and Flag.counter == 2: # africa + await response(discord3.format(messages)) + for i in range(len(africa)): + name = str(africa[i]) + await response(name) + + + elif 'north' in messages and Flag.counter == 2: # north america + await response(discord3.format(messages)) + for i in range(len(north_america)): + name = str(north_america[i]) + await response(name) + + + elif 'south' in messages and Flag.counter == 2: # south america + await response(discord3.format(messages)) + for i in range(len(south_america)): + name = str(south_america[i]) + await response(name) + + elif 'antarctica' in messages and Flag.counter == 2: # antarctica + await response(discord3.format(messages)) + for i in range(len(antarctica)): + name = str(antarctica[i]) + await response(name) + + + elif 'oceania' in messages and Flag.counter == 2: # oceania + await response(discord3.format(messages)) + for i in range(len(oceania)): + name = str(oceania[i]) + await response(name) + + + else: + await response('sorry i didn\'t understand, can you type again? make sure you dont use numbers') + + +client.run(token)