diff --git a/LocationWeather.py b/LocationWeather.py new file mode 100644 index 0000000..ab5f8ef --- /dev/null +++ b/LocationWeather.py @@ -0,0 +1,68 @@ +import discord +from discord.ext import commands +import geocoder +from predicthq import Client +import datetime + + +class LocationAndWeather: + def __init__(self, client): + self.client = client + + + @commands.command(name = "bot", + description="format: ?bot, gives bots hosting location", + brief="tells the user where the bot is currently being ran from", + pass_context=True) + async def botLocate(self, ctx): + g = geocoder.ip('me') + await self.client.say("```The bot is currently being hosted in: {}```".format(g.city)) + + + @commands.command(name = "locate", + description="format: ?locate [landmark name]', gives landmarks address", + brief="tells the user the location of a place they search for", + pass_context=True) + async def searchPlaceAddress(self, ctx, place): + g = geocoder.bing(place, key='Andk5NRaru9qQy_N3_NR4SsNB6JTfS1wp9MeD_4m1wJs2sYiIJsEGB7Ap97VrH4K') + await self.client.say("```The location is {}```".format(g.address)) + + + @commands.command(name = "coord", + description="format: ?coord [landmark name]', gives landmarks lat and lng", + brief="tells the user the latlng of a place they search for", + pass_context=True) + async def searchPlaceLatlng(self, ctx, place): + g = geocoder.bing(place, key='Andk5NRaru9qQy_N3_NR4SsNB6JTfS1wp9MeD_4m1wJs2sYiIJsEGB7Ap97VrH4K') + await self.client.say("```The location is {}```".format(g.latlng)) + + + @commands.command(name = "event", + description="format: ?event [city] [type of event]', gives landmarks address", + brief="tells the user events happening around the location they enter", + pass_context=True) + async def searchEvents(self, ctx, place, eventType): + output = [] + text = "" + phq = Client(access_token="Ds4t0V0Z71WuXvOyBsm2IFXDZaQxgh") + g = geocoder.bing(place, key='Andk5NRaru9qQy_N3_NR4SsNB6JTfS1wp9MeD_4m1wJs2sYiIJsEGB7Ap97VrH4K') + eventLocation = str('10km@' + str(g.lat) + ',' + str(g.lng)) + for event in phq.events.search(q=eventType, within=eventLocation): + if event.rank > 0: + now = datetime.datetime.now() + eventReverseLnglat = event.location + eventLng = eventReverseLnglat[1] + eventLat = eventReverseLnglat[0] + eventLnglat = str("[" + str(eventLng) + "," + str(eventLat) + "]") + h = geocoder.bing(eventLnglat, method='reverse', key='Andk5NRaru9qQy_N3_NR4SsNB6JTfS1wp9MeD_4m1wJs2sYiIJsEGB7Ap97VrH4K') + if int(now.day) < int(event.start.strftime('%d')): + output.append("Event details: {} - {} - {}".format(event.start.strftime('%d-%m-%Y'), event.title, event.category)) + output.append("Event address: {}".format(h.address)) + output.append("Event score : {}/ 100".format(event.rank)) + output.append("") + for eventdetails in output: + text = text + eventdetails + "\n" + await self.client.say("```{}```".format(text)) + +def setup(client): + client.add_cog(LocationAndWeather(client)) \ No newline at end of file diff --git a/Random.py b/Random.py new file mode 100644 index 0000000..09bab55 --- /dev/null +++ b/Random.py @@ -0,0 +1,115 @@ +import random +import discord +from discord.ext import commands +import requests +from lxml import html + +class Random: + def __init__(self, client): + self.client = client + + # ahmed's + @commands.command(name="guesscountry", + description="has a list of all countries that have been web scrapped", + brief="randomly says a country", + pass_context=True) + async def guess_country(self, ctx): + page = requests.get('https://en.wikipedia.org/wiki/List_of_countries_by_intentional_homicide_rate') + tree = html.fromstring(page.content) + guesscountry = tree.xpath('//*[@id="mw-content-text"]/div/table[2]/tbody/tr/td[2]/table/tbody/tr/td[1]/a/text()') + await self.client.say("{0} {1}".format(ctx.message.author.mention, random.choice(guesscountry))) + + + # seva's + @commands.command(description="takes a random joke from a list", + brief="says a random joke", + pass_context=True) + async def joke(self, ctx): + """gives a random joke from the list below""" + jokes = ["Two men walk into a bar. The third one ducks!", + "Why was 6 afraid of 7? Because 7 ate 9!", + "I’m reading an antigravity book It’s impossible to put down!", + "What kind of cheese doesn’t belong to you? Nacho cheese!", + "You can’t trust atoms. They make up everything!", + "Why do mushrooms get invited to all the best parties? Because they are such fungis!"] + await self.client.say("{0} {1}".format(ctx.message.author.mention, random.choice(jokes))) + + + # ahmed's + @commands.command(description="takes a random fact from a list", + brief="says a random fact", + pass_context=True) + async def facts(self, ctx): + """gives a random fact from the list below""" + facts = ["Banging your head against a wall for one hour burns 150 calories.", + "In Switzerland it is illegal to own just one guinea pig.", + "Pteronophobia is the fear of being tickled by feathers.", + "Snakes can help predict earthquakes.", + "A flock of crows is known as a murder.", + "The oldest 'your mom' joke was discovered on a 3,500 year old Babylonian tablet.", + "So far, two diseases have successfully been eradicated: smallpox and rinderpest.", + "Cherophobia is an irrational fear of fun or happiness.", + "7% of American adults believe that chocolate milk comes from brown cows.", + "If you lift a kangaroo's tail off the ground it can't hop.", + "Bananas are curved because they grow towards the sun.", + "Billy goats urinate on their own heads to smell more attractive to females.", + "The inventor of the Frisbee was cremated and made into a Frisbee after he died.", + "During your lifetime, you will produce enough saliva to fill two swimming pools.", + "If Pinocchio says 'My Nose Will Grow Now', it would cause a paradox.", + "Polar bears could eat as many as 86 penguins in a single sitting...", + "Movie trailers were originally shown after the movie, which is why they were called 'trailers'.", + "An eagle can kill a young deer and fly away with it.", + "Heart attacks are more likely to happen on a Monday.", + "Tennis players are not allowed to swear when they are playing in Wimbledon.", + "In 2017 more people were killed from injuries caused by taking a selfie than by shark attacks.", + "The top six foods that make your fart are beans, corn, bell peppers, cauliflower, cabbage and milk.", + "There is a species of spider called the Hobo Spider.", + "A lion’s roar can be heard from 5 miles away.", + "Saint Lucia is the only country in the world named after a woman.", + "A baby spider is called a spiderling.", + "The United States Navy has started using Xbox controllers for their periscopes.", + "A baby octopus is about the size of a flea when it is born.", + "Scarecrows have been around longer than you might think – the first scarecrows known to history were made about three-thousand-years ago!.", + "The scientific name for brain freeze is sphenopalatine ganglioneuralgia." + "A New Jersey man flunked out of law school and subsequently sued the school for having accepted him in the first place.", + "Toni Morrison was the first African-American woman to receive a Nobel Prize. It was in recognition of her contributions to literature and poetry.", + "Laughing boosts the immune system, burns calories and reduces stress hormones, making it a very healthy activity.", + "Honey is a better cough suppressant than over-the-counter cough suppressants.", + "People are more likely to agree with a statement written in Baskerville than any other font.", + "3 out of 4 Americans use an emoji in text messaging every single day.", + "Due to a genetic defect, cats can’t taste sweet things.", + "According to the Centre for Retail Research, cheese is the most commonly shoplifted food in the world." + ] + await self.client.say("{0} {1}".format(ctx.message.author.mention, random.choice(facts))) + + + @commands.command(description="rolls a dice of d4,d6,d8,d10,d12,d20,d100", + brief="rolls a dice of specified sides", + pass_context=True) + async def roll(self, ctx, dice): + """rolls a dice of sides var dice when specified""" + dicedict={"d4":random.randint(1,4), + "d6":random.randint(1,6), + "d8":random.randint(1,8), + "d10":random.randint(1,10), + "d12":random.randint(1,12), + "d20":random.randint(1,20), + "d100":random.randint(1,100) + } + await self.client.say("{0} you rolled a: {1}".format(ctx.message.author.mention, dicedict[dice])) + + + @commands.command(description="randomly picks a winner from the user list", + brief="randomly picks a winner from the user list", + pass_context=True) + async def giveaway(self, ctx): + memberlist=[] + for member in ctx.message.server.members: + for role in member.roles: + if str(member.status) == "online" and role.name == "User": + memberlist.append(member) + await self.client.say("{} has won the giveaway".format(random.choice(memberlist).mention)) + + +def setup(client): + client.add_cog(Random(client)) diff --git a/User.py b/User.py new file mode 100644 index 0000000..8700710 --- /dev/null +++ b/User.py @@ -0,0 +1,20 @@ +import discord +from discord.ext import commands + +class User: + def __init__(self, client): + self.client = client + + # andrew's + @commands.command(description="shows the user info of the person mentioned @user", + brief="shows a users info", + pass_context=True) + async def info(self, ctx, user: discord.Member): + """shows the user information of the person mentioned""" + await self.client.say("The users name is: {}".format(user.name)) + await self.client.say("The users ID is: {}".format(user.id)) + await self.client.say("The users status is:{}".format(user.status)) + await self.client.say("The user joined at:{}".format(user.joined_at)) + +def setup(client): + client.add_cog(User(client)) \ No newline at end of file diff --git a/discordBot.py b/discordBot.py index 2ebde8e..2ccdbed 100644 --- a/discordBot.py +++ b/discordBot.py @@ -8,14 +8,15 @@ import random import requests from lxml import html from discord.utils import get +#from googlesearch.googlesearch import GoogleSearch BOT_PREFIX = ("?") # token would be where you put your bot's token to join as the client but it's going on github so nah -TOKEN = "" +TOKEN = "NTA1MTA1ODU0NjI2OTIyNTE2.DtAhPQ.r7Lhj6xGVkmTFHeIM0h5KNC3He0" client = commands.Bot(command_prefix=BOT_PREFIX) -extensions=["Fun","Music"] +extensions=["Fun","Music","Random","LocationWeather","User"] async def start(self): @@ -23,121 +24,7 @@ async def start(self): discord.opus.load_opus(self.opus_library) -# ahmed's -@client.command(name="guesscountry", - description="has a list of all countries that have been web scrapped", - brief="randomly says a country", - pass_context=True) -async def guess_country(ctx): - page = requests.get('https://en.wikipedia.org/wiki/List_of_countries_by_intentional_homicide_rate') - tree = html.fromstring(page.content) - guesscountry = tree.xpath('//*[@id="mw-content-text"]/div/table[2]/tbody/tr/td[2]/table/tbody/tr/td[1]/a/text()') - await client.say("{0} {1}".format(ctx.message.author.mention, random.choice(guesscountry))) - - -# seva's -@client.command(description="takes a random joke from a list", - brief="says a random joke", - pass_context=True) -async def joke(ctx): - """gives a random joke from the list below""" - jokes = ["Two men walk into a bar. The third one ducks!", - "Why was 6 afraid of 7? Because 7 ate 9!", - "I’m reading an antigravity book It’s impossible to put down!", - "What kind of cheese doesn’t belong to you? Nacho cheese!", - "You can’t trust atoms. They make up everything!", - "Why do mushrooms get invited to all the best parties? Because they are such fungis!"] - await client.say("{0} {1}".format(ctx.message.author.mention, random.choice(jokes))) - - -# ahmed's -@client.command(description="takes a random fact from a list", - brief="says a random fact", - pass_context=True) -async def facts(ctx): - """gives a random fact from the list below""" - facts = ["Banging your head against a wall for one hour burns 150 calories.", - "In Switzerland it is illegal to own just one guinea pig.", - "Pteronophobia is the fear of being tickled by feathers.", - "Snakes can help predict earthquakes.", - "A flock of crows is known as a murder.", - "The oldest 'your mom' joke was discovered on a 3,500 year old Babylonian tablet.", - "So far, two diseases have successfully been eradicated: smallpox and rinderpest.", - "Cherophobia is an irrational fear of fun or happiness.", - "7% of American adults believe that chocolate milk comes from brown cows.", - "If you lift a kangaroo's tail off the ground it can't hop.", - "Bananas are curved because they grow towards the sun.", - "Billy goats urinate on their own heads to smell more attractive to females.", - "The inventor of the Frisbee was cremated and made into a Frisbee after he died.", - "During your lifetime, you will produce enough saliva to fill two swimming pools.", - "If Pinocchio says 'My Nose Will Grow Now', it would cause a paradox.", - "Polar bears could eat as many as 86 penguins in a single sitting...", - "Movie trailers were originally shown after the movie, which is why they were called 'trailers'.", - "An eagle can kill a young deer and fly away with it.", - "Heart attacks are more likely to happen on a Monday.", - "Tennis players are not allowed to swear when they are playing in Wimbledon.", - "In 2017 more people were killed from injuries caused by taking a selfie than by shark attacks.", - "The top six foods that make your fart are beans, corn, bell peppers, cauliflower, cabbage and milk.", - "There is a species of spider called the Hobo Spider.", - "A lion’s roar can be heard from 5 miles away.", - "Saint Lucia is the only country in the world named after a woman.", - "A baby spider is called a spiderling.", - "The United States Navy has started using Xbox controllers for their periscopes.", - "A baby octopus is about the size of a flea when it is born.", - "Scarecrows have been around longer than you might think – the first scarecrows known to history were made about three-thousand-years ago!.", - "The scientific name for brain freeze is sphenopalatine ganglioneuralgia." - "A New Jersey man flunked out of law school and subsequently sued the school for having accepted him in the first place.", - "Toni Morrison was the first African-American woman to receive a Nobel Prize. It was in recognition of her contributions to literature and poetry.", - "Laughing boosts the immune system, burns calories and reduces stress hormones, making it a very healthy activity.", - "Honey is a better cough suppressant than over-the-counter cough suppressants.", - "People are more likely to agree with a statement written in Baskerville than any other font.", - "3 out of 4 Americans use an emoji in text messaging every single day.", - "Due to a genetic defect, cats can’t taste sweet things.", - "According to the Centre for Retail Research, cheese is the most commonly shoplifted food in the world." - ] - await client.say("{0} {1}".format(ctx.message.author.mention, random.choice(facts))) - - -# andrew's -@client.command(description="shows the user info of the person mentioned @user", - brief="shows a users info", - pass_context=True) -async def info(ctx, user: discord.Member): - """shows the user information of the person mentioned""" - await client.say("The users name is: {}".format(user.name)) - await client.say("The users ID is: {}".format(user.id)) - await client.say("The users status is:{}".format(user.status)) - await client.say("The user joined at:{}".format(user.joined_at)) - - -@client.command(description="rolls a dice of d4,d6,d8,d10,d12,d20,d100", - brief="rolls a dice of specified sides", - pass_context=True) -async def roll(ctx,dice): - """rolls a dice of sides var dice when specified""" - dicedict={"d4":random.randint(1,4), - "d6":random.randint(1,6), - "d8":random.randint(1,8), - "d10":random.randint(1,10), - "d12":random.randint(1,12), - "d20":random.randint(1,20), - "d100":random.randint(1,100) - } - await client.say("{0} you rolled a: {1}".format(ctx.message.author.mention, dicedict[dice])) - - -@client.command(description="randomly picks a winner from the user list", - brief="randomly picks a winner from the user list", - pass_context=True) -async def giveaway(ctx): - memberlist=[] - for member in ctx.message.server.members: - for role in member.roles: - if str(member.status) == "online" and role.name == "User": - memberlist.append(member) - await client.say("{} has won the giveaway".format(random.choice(memberlist).mention)) - -# used guide https://www.youtube.com/watch?v=gxKM6J5VmIc&t=708s +# used guide, loads and unloads cogs made in other files https://www.youtube.com/watch?v=gxKM6J5VmIc&t=708s ############################################################################################ @client.command(brief="loads command categories back") async def load(extension): @@ -155,8 +42,22 @@ async def unload(extension): print("{} cannot be unloaded [{}] ".format(extension, error)) ############################################################################################ +#end of code from https://www.youtube.com/watch?v=gxKM6J5VmIc&t=708s +#started writing code using googlesearch library but realised it was for python2 +"""@client.command(name="g", + brief="googles stuff", + pass_context=True) +async def google(ctx, *search : str): + search = "{}".format(" ".join(search)) + response = GoogleSearch().search(search) + for result in response.results: + title = ("Title: " + result.title) + content = ("Content: " + result.getText()) + await client.say("```{}\n{}```".format(title,content))""" + + @client.event async def on_ready(): # says that the bot is playing a game called name @@ -164,13 +65,17 @@ async def on_ready(): # prints logged in in the terminal for the code runner to know that they logged on print("Logged in as " + client.user.name) + +# used guide, loads cogs made in other files when the bot opens https://www.youtube.com/watch?v=gxKM6J5VmIc&t=708s +############################################################################################# if __name__ == "__main__": for extension in extensions: try: client.load_extension(extension) except Exception as error: print("{} cannot be loaded [{}] ".format(extension, error)) - +############################################################################################# +#ends using guide https://www.youtube.com/watch?v=gxKM6J5VmIc&t=708s @client.event async def on_message(message):