Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
ampikainay committed Nov 28, 2020
1 parent 5ef9b9d commit 767ee1dd59a5321865d29119fbf09bcc4846bcd2
Showing 1 changed file with 32 additions and 42 deletions.
@@ -1,11 +1,11 @@
from discord import *
import discord #This is the discord.py library used to access discord
from discord.ext import commands

client = commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
print("Bot Ready.") #check if the bot is ready
print("Bot Ready.") #check if the bot is ready

QuestionCount = 0
PhoneBudget = ''
@@ -21,30 +21,34 @@ PhoneCameraPositive = ['yes','always','often']
PhoneCameraNegative = ['no', 'not really','sometimes','nope']
PhoneBrandResponse = ['apple','samsung','google','oneplus','any']


#phone name and specification details are stored in seperate list
#the index number matches the name of the phones with their specifications from the other lists
PhoneNameList = ['pixel 3a','s20','iphone 8','oneplus nord']
PhonePriceList = ['200', '700' , '250' , '380']
PhoneSizeList = ['small', 'large' , 'small', 'large']
PhoneCameraList = ['regular','pro','pro','regular']
PhonePriceList = ['200', '700' , '250' , '380']
PhoneSizeList = ['small', 'large' , 'small', 'large']
PhoneCameraList = ['regular','pro','pro','regular'] #eligibility of professional camera features
PhoneBatteryList = ['small','large','small','large']
PhoneBrandList = ['google' , 'samsung','apple','oneplus']
#the index of the phone names corrospond to Amazon links list
PhoneAmzonLinkList = ['''https://www.amazon.co.uk/Google-Pixel-Just-Black-64GB/dp/B07RL859ZT/ref=sr_1_3?dchild=1&keywords=pixel+3a&qid=1606492712&sr=8-3''','''https://www.amazon.co.uk/Samsung-Galaxy-Mobile-Phone-Smartphone-Cosmic-Grey/dp/B084GQ3KYM/ref=sr_1_4?dchild=1&keywords=s20&qid=1606492681&sr=8-4''','''https://www.amazon.co.uk/Apple-iPhone-Sim-Free-Smartphone-Refurbished-Gold/dp/B0784GTZJS/ref=sr_1_4?dchild=1&keywords=iphone+8&qid=1606491722&sr=8-4''','''https://www.amazon.co.uk/OnePlus-SIM-Free-Smartphone-Camera-Warranty/dp/B08BPJRK8Z/ref=sr_1_3?dchild=1&keywords=oneplus+nord&qid=1606492267&sr=8-3''']

@client.event
async def on_message(message):
async def on_message(message): #trigerred when bot receives an message

global QuestionCount #current question number

#global variables used to store the answers from the user
global PhoneBudget
global PhoneSize
global PhoneCamera
global PhoneBattery
global PhoneBrand

if message.author == client.user:
if message.author == client.user: #make sure that the bot doesn't respond to itself
return
if QuestionCount==0:
await message.channel.send('Welcome! I am Mr SmartBOT here. You have come to the right place to choose your next ideal smartphone! Shall we begin?')
QuestionCount = QuestionCount + 1
QuestionCount = QuestionCount + 1


elif QuestionCount == 1:
@@ -58,7 +62,7 @@ async def on_message(message):

elif QuestionCount == 2:
try:
if int(message.content)>350:
if int(message.content)>300:
await message.channel.send('Do you prefer a large phone or do you prefer something compact?')
PhoneBudget = message.content
QuestionCount = 3
@@ -97,9 +101,8 @@ async def on_message(message):

elif QuestionCount == 5:
try:
if int(message.content)<10:
#get the preferred brand
await message.channel.send('Which of the following brands do you prefer Apple, Samsung, Google, OnePlus or any?')
if int(message.content)<10:
await message.channel.send('Which of the following brand do you prefer Apple,Samsung, Google,OnePlus or do you prefer any brand?')
PhoneBattery = message.content
QuestionCount = 6
else:
@@ -129,18 +132,18 @@ async def on_message(message):

elif QuestionCount == 7:
HighestVote = 0
# the phone with most votes in the end is the best for the user
for i in range(0,3):
for i in range(0,4): #cycle through the user answer and compare it with phone specification from the lists

Phone = PhoneNameList[i]
vars()[Phone] = 0
if int(PhoneBudget) < int(PhonePriceList[i]):
vars()[Phone] = 0 #var() dictionary is used to convert string to a variable name
#while cycling through phone lists, whenever the user's aswers is matched with the spec, a point is given to that phone name
if int(PhoneBudget) > int(PhonePriceList[i]):
vars()[Phone] = vars()[Phone] + 1
if PhoneSize in SizeLargeResponses and PhoneSizeList[i] == 'large':
vars()[Phone] = vars()[Phone] + 1
if PhoneSize in SizeLargeResponses and PhoneSizeList[i] == 'small':
vars()[Phone] = vars()[Phone] + 1
if int(PhoneBattery) <= 4 :
if 'small' == PhoneBatteryList[i]:
vars()[Phone] = vars()[Phone] + 1
if int(PhoneBattery) >= 4 :
if 'large' == PhoneBatteryList[i]:
@@ -153,30 +156,17 @@ async def on_message(message):
if PhoneBrand == 'any':
vars()[Phone] = vars()[Phone] + 1
elif PhoneBrandList[i] == PhoneBrand:
vars()[Phone] = vars()[Phone] + 1
if i != 0:
if vars()[Phone] >= vars()[PhoneNameList[i-1]]:
HighestVote = vars()[Phone]
FinalPhoneIndex = i
vars()[Phone] = vars()[Phone] + 10

for x in range(0,3):
FinalPhoneIndex = 0
#compare the scores given and output the phone with the highest score
if vars()[PhoneNameList[x]] > vars()[PhoneNameList[x + 1]]:
FinalPhoneIndex = x
else:
FinalPhoneIndex = x + 1
await message.channel.send("Here is the recommended phone for you!")
await message.channel.send(PhoneAmzonLinkList[FinalPhoneIndex])
QuestionCount = 0



















client.run('NzgwODc2MDg2NzExNTUwMDEz.X71dhw.opqQ5muiGjKydgThgPthqXyq1Ss')
client.run('NzgwODc2MDg2NzExNTUwMDEz.X71dhw.opqQ5muiGjKydgThgPthqXyq1Ss')#discord bot token - used to access the discrod API

0 comments on commit 767ee1d

Please sign in to comment.