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 random
from weatherapi import *
from GetLocation import *
from discord.ext import commands
client = commands.Bot(command_prefix = ".")
TOKEN = 'NTA4NjM1MTMyMzIwODA4OTg1.DsJXIw.8ZQR25yaiOi1CEYuikv2SPWElmA'
#######################################################################################################################
class Lists:
Accept = ['Yes', 'Yesh', 'Yup']
Greetings = ['Hello', 'Hi!', "Top o' the morning t'ya", 'Well met']
flagGreet = 0
Farewell = ['So long', 'Goodbye', 'Goodbye', 'See you later', 'Farewell']
flagFarewell = 0
Taboo_words = ['flummery', 'arse', 'bullocks', 'doodle', 'tarnation', 'gee golly', 'garyloo', 'pillion']
flagTaboo = 0
Apologie = ['Sorry', 'sorry', 'forgive']
flagApologie = 0
Weather = ['Weather', 'weather']
flagWeather = 0
WeatherQ = ['In what City?']
flagWeatherQ = 0
flagWeatherC = 0
Location = ['Location', 'location']
flaglocation = 0
Places = ['Places', 'near']
PlacesList2 = ['restaurant', 'cafe', 'night_club', 'park', 'pharmacy', 'bus_station', 'museum', 'movie_theater', 'gym', 'spa', 'hospital']
PlacesList1 = ['Restaurants', 'restaurants', 'restaurant', 'Restaurants',
'Cafe', 'Cafes', 'cafe', 'cafes',
'Night Clubs', 'Night Club', 'NightClubs', 'NightClub', 'night clubs', 'night club', 'nightclubs', 'nightclub',
'Parks', 'Park', 'parks', 'park',
'Pharmacy', 'Pharmacies', 'pharmacy', 'pharmacies',
'Bus Stations', 'BusStations', 'bus stations', 'busstations', 'Bus Station', 'BusStation', 'bus station', 'busstation',
'Museums', 'Museum', 'museums', 'museum',
'Movie Theaters', 'MovieTheaters', 'movie theaters', 'movietheaters', 'Movie Theater', 'Movie Theater', 'movie theater', 'movietheater',
'Gyms', 'Gym', 'gyms', 'gym',
'Spas', 'Spa', 'spas', 'spa',
'Hospitals', 'Hospital', 'hospitals', 'hospital']
RestaurantList = ['Restaurants', 'restaurants', 'restaurant', 'Restaurants']
CafeList = ['Cafe', 'Cafes', 'cafe', 'cafes']
NightClubList = ['Night Clubs', 'Night Club', 'NightClubs', 'NightClub', 'night clubs', 'night club', 'nightclubs', 'nightclub']
ParkList = ['Parks', 'Park', 'parks', 'park']
PharmacyList = ['Pharmacy', 'Pharmacies', 'pharmacy', 'pharmacies']
BusStationList = ['Bus Stations', 'BusStations', 'bus stations', 'busstations', 'Bus Station', 'BusStation', 'bus station', 'busstation']
MuseumList = ['Museums', 'Museum', 'museums', 'museum']
MovieTheaterList = ['Movie Theaters', 'MovieTheaters', 'movie theaters', 'movietheaters', 'Movie Theater', 'Movie Theater', 'movie theater', 'movietheater']
GymList = ['Gyms', 'Gym', 'gyms', 'gym']
SpaList = ['Spas', 'Spa', 'spas', 'spa']
HospitalList = ['Hospitals', 'Hospital', 'hospitals', 'hospital']
Advice = ['Recommendations', 'recommendation', 'recommendations']
flagplaces = 0
flagplacesadvice = 0
flagradius = 0
flagsearchterm = 0
flagtype = 0
flagplaceshelp = 0
flagplacesoutput = 0
radius = ""
type = ""
searchterm = ""
#######################################################################################################################
#necessary in order to create pause and resume commands, also
#from tutorial video: https://www.youtube.com/watch?v=hFVby_Vet7E&t=5s
players = {}
@client.event
async def on_ready():
"""Function that prints 'Bot is ready' on the console, when the Bot becomes online on Discord"""
print("Bot Ready!")
###Bit of code from tutorial video: https://www.youtube.com/watch?v=hFVby_Vet7E&t=5s
@client.command(pass_context=True)
async def join(ctx):
"""Function that makes the bot join the voice channel"""
#author = ctx.message.author
#channel = author.voice_channel
channel = ctx.message.author.voice.voice_channel
await client.join_voice_channel(channel)
print("Bot joined the voice channel!")
@client.command(pass_context=True)
async def leave(ctx):
"""Function that makes the bot leave the voice channel"""
server = ctx.message.server
voice_client = client.voice_client_in(server)
await voice_client.disconnect()
print("Bot left the voice channel")
###End of code from tutorial video: https://www.youtube.com/watch?v=hFVby_Vet7E&t=5s
###Bit of code obtained from the tutorial video: https://www.youtube.com/watch?v=MbhXIddT2YY
@client.command(pass_context=True)
async def clear(ctx, amount = 100):
"""Function to clear messages in the channel"""
channel = ctx.message.channel
messages = []
async for message in client.logs_from(channel, limit=int(amount)):
messages.append(message)
await client.delete_messages(messages)
await client.say('Messages deleted')
###End of code from tutorial video: https://www.youtube.com/watch?v=MbhXIddT2YY
###Bit of code from tutorial video: https://www.youtube.com/watch?v=MbhXIddT2YY
@client.command(pass_context=True)
async def play(ctx, url):
"""Function to play a Youtube video"""
#get server from message
server = ctx.message.server
#access the voice client of said server
voice_client = client.voice_client_in(server)
#create youtube player of the url passed in the function
player = await voice_client.create_ytdl_player(url)
#saving player as the current server specific player
players[server.id] = player
#starts player
player.start()
###End of code from tutorial video: https://www.youtube.com/watch?v=MbhXIddT2YY#
@client.event
async def on_message(message):
"""Function responsible for 90% of the bot code, where every message and output is processed"""
messages = message.content
channel = message.channel
if message.author == client.user:
return
else:
try:
# Setting up the flags
###Greetings setup###################################
if any(word in messages for word in Lists.Greetings):
Lists.flagGreet = 1
###Farewell setup####################################
if any(word in messages for word in Lists.Farewell):
Lists.flagFarewell = 1
###Taboo setup#########################################
if any(word in messages for word in Lists.Taboo_words):
Lists.flagTaboo = 1
###Apologies setup##################################
if any(word in messages for word in Lists.Apologie):
Lists.flagApologie = 1
###Weather setup###################################
if any(word in messages for word in Lists.Weather):
Lists.flagWeatherQ = 1
###Location setup########################################################
if any(word in messages for word in Lists.Location) and 'my' in messages:
Lists.flaglocation = 1
###Places setup##########################################################
if any(word in messages for word in Lists.Places):
Lists.flagplaces = 1
###Places help part######################################################
if any(word in messages for word in Lists.Places) and 'what' in messages:
Lists.flagplaceshelp = 1
###Places advice#########################################################
if any(word in messages for word in Lists.Advice):
Lists.flagplacesadvice = 1
###League api setup######################################################
if any(word in messages for word in Lists.League):
Lists.flagLeagueR = 1
# Making the flags work
###Greetings Part#########################
if Lists.flagGreet == 1:
output = random.choice(Lists.Greetings)
Lists.flagGreet = 0
###Farewell Part##########################
elif Lists.flagFarewell == 1:
output = random.choice(Lists.Farewell)
###Curse word Part#############################
elif Lists.flagTaboo == 1:
output = "Please don't use that language!"
Lists.flagTaboo = 0
###Apologies Part#####################
elif Lists.flagApologie == 1:
output = "Alright, I forgive you."
Lists.flagApologie = 0
###Weather Output Part############
elif Lists.flagWeatherC == 1:
Lists.flagWeatherC = 0
Lists.flagWeatherQ = 0
output = weatherAPI(messages)
###Weather Confirmation part###
elif Lists.flagWeatherQ == 1:
Lists.flagWeatherQ = 0
Lists.flagWeatherC = 1
output = 'In what City?'
###Location Start##################
elif Lists.flaglocation == 1:
Lists.flagLocation = 0
output = GetLocation()
###Places advice######################################
elif Lists.flagplacesadvice == 1:
Lists.flagplacesadvice = 0
output = "Well, I would recommend only going for {0} above 3,5 rating.".format(Lists.searchterm)
###Places Radius confirmation#############
elif Lists.flagradius == 1:
Lists.flagradius = 0
#Lists.flagtype = 1
Lists.radius = messages
output = "{0}: \n".format(Lists.searchterm) + SearchPlaces(Lists.radius, Lists.type)
#output = 'Give me a sec...'
###Search Term Start############################
elif Lists.flagsearchterm == 1:
Lists.flagsearchterm = 0
Lists.flagradius = 1
Lists.searchterm = messages
if any(word in messages for word in Lists.PlacesList1):
if any(word in messages for word in Lists.RestaurantList):
Lists.type = Lists.PlacesList2[0]
if any(word in messages for word in Lists.CafeList):
Lists.type = Lists.PlacesList2[1]
if any(word in messages for word in Lists.NightClubList):
Lists.type = Lists.PlacesList2[2]
if any(word in messages for word in Lists.ParkList):
Lists.type = Lists.PlacesList2[3]
if any(word in messages for word in Lists.PharmacyList):
Lists.type = Lists.PlacesList2[4]
if any(word in messages for word in Lists.BusStationList):
Lists.type = Lists.PlacesList2[5]
if any(word in messages for word in Lists.MuseumList):
Lists.type = Lists.PlacesList2[6]
if any(word in messages for word in Lists.MovieTheaterList):
Lists.type = Lists.PlacesList2[7]
if any(word in messages for word in Lists.GymList):
Lists.type = Lists.PlacesList2[8]
if any(word in messages for word in Lists.SpaList):
Lists.type = Lists.PlacesList2[9]
if any(word in messages for word in Lists.HospitalList):
Lists.type = Lists.PlacesList2[10]
output = 'Under what radius?'
else:
output = 'Sorry, that search term goes beyond my abilities!'
Lists.flagradius = 0
###Places Start#####################
elif Lists.flagplaces == 1:
Lists.flagplaces = 0
Lists.flagsearchterm = 1
output = 'Sure there are, currently, you can search for these \n' \
'places: \n' \
'Restaurants, Cafes, Night Clubs, Parks, Pharmacies, Bus Stations, \n' \
'Museums, Movie Theaters, Gyms, Spas and Hospitals.\n' \
'Which one would you like to search?'
else:
output = "Sorry, I didn't understand that last part."
except:
output = 'An error has occurred'
raise
if messages[0] == '.':
await client.process_commands(message)
else:
await client.send_message(channel, output)
client.run(TOKEN)