Skip to content
Permalink
a5256e7a02
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
172 lines (137 sloc) 6.69 KB
import discord
import random
from imdbrating import movieRating
from riotSummonerRank import *
from riotMatches import *
client = discord.Client()
class List:
# Global keywords
consentWords = ['yes', 'yeah', 'sure', 'why not', 'yup', 'yap']
greetings = ['hello', 'hey', 'hi', 'greetings', 'yo!', 'howdy!']
# Keywords for movies
rating = ['rating', 'movie rating', 'rating movie', 'movie rated']
# Keywords for League of Legends
leagueOfLegends = ['league of legends', 'lol stats', 'lol game']
regionList1 = ['na', 'br', 'eun', 'euw', 'jp', 'la', 'oc', 'tr']
regionList2 = ['eune', 'lan', 'oce']
regionList3 = ['kr', 'ru']
class Flag:
# Global flag
greetings = 0
# Flags for movies
rating = 0
searchRating = 0
# Flags for League of Legends
class LoL:
primary = 0
secondary = 0
summonerRank = 0
matchList = 0
matchDetails = 0
summonerNameMatchList = 0
summonerNameCurrentRank = 0
regionCurrentRank = 0
regionMatchList = 0
class String:
# Strings used for League of Legends
summonerName = ""
region = ""
@client.event
async def on_ready():
"""On run the line below will be printed in Python terminal to notify that the bot is ready. Takes no input."""
print('Bot is ready!')
@client.event
async def on_message(message):
"""Main function that gives the output. Takes user message in Discord as input."""
inputMessage = message.content
keyWords = inputMessage.lower()
if message.author == client.user: # Prevents the client reply to himself.
return
else:
try:
if any(word in keyWords for word in List.greetings):
Flag.greetings = 1
if any(word in keyWords for word in List.rating):
Flag.rating = 1
if any(word in keyWords for word in List.leagueOfLegends):
Flag.LoL.primary = 1
if Flag.greetings == 1:
Flag.greetings = 0 # This line is responsible to reset the flag above.
randomGreeting = random.choice(List.greetings)
outputMessage = randomGreeting.title()
elif Flag.rating == 1:
Flag.rating = 0
Flag.searchRating = 1
outputMessage = "What movie to be more precise?"
elif Flag.searchRating == 1:
Flag.searchRating = 0
outputMessage = movieRating(inputMessage)
elif Flag.LoL.primary == 1:
Flag.LoL.primary = 0
Flag.LoL.secondary = 1
outputMessage = "What exactly you want to know?\n1 - Summoners current rank.\n2 - Get match list and check match details."
elif Flag.LoL.secondary == 1:
Flag.LoL.secondary = 0
if inputMessage == "1":
Flag.LoL.summonerRank = 1
outputMessage = "What summoners name?"
elif inputMessage == "2":
Flag.LoL.matchList = 1
outputMessage = "What summoners name?"
else:
outputMessage = "Try again."
elif Flag.LoL.summonerRank == 1:
Flag.LoL.summonerRank = 0
Flag.LoL.regionCurrentRank = 1
String.summonerName = inputMessage
outputMessage = "In what region?"
elif Flag.LoL.regionCurrentRank == 1:
Flag.LoL.regionCurrentRank = 0
String.region = inputMessage.lower()
# The if statements bellow allows user write the region without the need to add extra letters/numbers.
# For example, instead of EUW1 user can just input EUW.
if any(word in String.region for word in
List.regionList1 or List.regionList2 or List.regionList3 or "las" or "LAS"):
if any(word in String.region for word in List.regionList1):
String.region = String.region + "1"
if any(word in String.region for word in List.regionList2):
String.region = String.region[:-1] + "1"
if any(word in String.region for word in List.regionList3):
String.region = String.region
if String.region == "las" or String.region == "LAS":
String.region = "la2"
outputMessage = summonerRank(String.region, String.summonerName)
else:
outputMessage = "There is no such region."
elif Flag.LoL.matchList == 1:
Flag.LoL.matchList = 0
Flag.LoL.regionMatchList = 1
String.summonerName = inputMessage
outputMessage = "In what region?"
elif Flag.LoL.regionMatchList == 1:
Flag.LoL.regionMatchList = 0
Flag.LoL.matchDetails = 1
String.region = inputMessage.lower()
# The if statements bellow allows user write the region without the need to add extra letters/numbers.
# For example, instead of EUW1 user can just input EUW.
if any(word in String.region for word in
List.regionList1 or List.regionList2 or List.regionList3 or "las" or "LAS"):
if any(word in String.region for word in List.regionList1):
String.region = String.region + "1"
if any(word in String.region for word in List.regionList2):
String.region = String.region[:-1] + "1"
if any(word in String.region for word in List.regionList3):
String.region = String.region
if String.region == "las" or String.region == "LAS":
String.region = "la2"
outputMessage = "From which game do you want to see the details?\n" + matchList(String.region, String.summonerName)
elif Flag.LoL.matchDetails == 1:
Flag.LoL.matchDetails = 0
positionInList = inputMessage
outputMessage = matchDetails(String.region, String.summonerName, int(positionInList))
else:
outputMessage = "Sorry, I cannot understand you."
except:
outputMessage = "Something went wrong."
await client.send_message(message.channel, outputMessage) # Line of code responsible to give the output.
client.run("NTA2NzM3MDg1MjE1MTQ1OTk1.DsJkfg.CuIqeTKQkbztdeWkFARDFjfmybE")