This repository was archived by the owner on Mar 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 9 #17
Open
samhallam03
wants to merge
18
commits into
python-discord:master
Choose a base branch
from
samhallam03:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Team 9 #17
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1942d08
Merge pull request #1 from discord-python/master
samhallam03 ba3673e
Started get_snek, searching needs to be added but randomisation compl…
samhallam03 a4a6682
Changed location of snakes.json in snakes.py so that it can actually …
samhallam03 09bbae9
Finished get() command but may need to edit things later on.
samhallam03 1b213f3
Merge pull request #2 from discord-python/master
samhallam03 729023b
Fixing some travis issues
samhallam03 68f4869
Fixing more travis issues
samhallam03 9ad497c
Fixing flake8 issues
samhallam03 59beaed
Even more flake8 issues
samhallam03 c595d73
More flake8 issues
samhallam03 8c7b7f1
Added second command, it shows snake movies
samhallam03 792bba7
fixing flake8 issues
samhallam03 f1cdc6a
Added director and release date
samhallam03 b97736c
Added back string docs, also fixed some errors if snakes were not found
samhallam03 6b735de
Fixing flake8 issues
samhallam03 b8aedd6
fixing flake8 issues
samhallam03 5a32358
fixing flake8 issues
samhallam03 6f71cd7
Added more snakes
samhallam03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| # coding=utf-8 | ||
| import json | ||
| import logging | ||
| import random | ||
| from typing import Any, Dict | ||
|
|
||
| from discord import Embed | ||
| from discord.ext.commands import AutoShardedBot, Context, command | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
@@ -24,12 +27,33 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: | |
|
|
||
| If "python" is given as the snake name, you should return information about the programming language, but with | ||
| all the information you'd provide for a real snake. Try to have some fun with this! | ||
|
|
||
| :param name: Optional, the name of the snake to get information for - omit for a random snake | ||
| :return: A dict containing information on a snake | ||
| """ | ||
| with open('bot/db/snakes.json', 'r') as file: | ||
| snakes_dict = json.load(file) | ||
|
|
||
| if not name: | ||
| _, snake = random.choice(list(snakes_dict.items())) | ||
|
|
||
| elif name.lower() not in snakes_dict: | ||
| snake = "Not Found" | ||
|
|
||
| else: | ||
| snake = snakes_dict[name.lower()] | ||
| if snake['name'] == "python": | ||
| snake = { | ||
| 'name': snake['name'], | ||
| 'description': snake['description'], | ||
| 'creator': snake['creator'], | ||
| 'created': snake['created'], | ||
| 'image': snake['image'] | ||
| } | ||
|
|
||
| return snake | ||
|
|
||
| @command() | ||
| @command(name='get') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed, but nothing wrong with having it. |
||
| async def get(self, ctx: Context, name: str = None): | ||
| """ | ||
| Go online and fetch information about a snake | ||
|
|
@@ -40,8 +64,68 @@ async def get(self, ctx: Context, name: str = None): | |
| :param ctx: Context object passed from discord.py | ||
| :param name: Optional, the name of the snake to get information for - omit for a random snake | ||
| """ | ||
| snake = await self.get_snek(name) | ||
|
|
||
| if snake != "Not Found": | ||
| embed = Embed( | ||
| title=snake['name'].title(), | ||
| description=snake['description'] | ||
| ) | ||
|
|
||
| if snake['name'] != "python": | ||
| embed.add_field(name="Where can you find them?", value=snake['location']) | ||
| embed.add_field(name="Are they venomous?", value=snake['venomous']) | ||
| embed.set_image(url=snake['image']) | ||
| else: | ||
| embed.add_field(name="Who created it?", value=snake['creator']) | ||
| embed.add_field(name="When was it created?", value=snake['created']) | ||
| embed.set_thumbnail(url=snake['image']) | ||
| else: | ||
| embed = Embed( | ||
| title="Snake Not Found", | ||
| description="The snake you entered was not found." | ||
| ) | ||
|
|
||
| await ctx.send(embed=embed) | ||
|
|
||
| @command(name='movies') | ||
| async def movies(self, ctx: Context, movie_name: str = None): | ||
| """ | ||
| Shows 5 snake movies. Warning: They are all pretty bad. | ||
| """ | ||
|
|
||
| with open('bot/db/movies.json', 'r') as file: | ||
| movies_dict = json.load(file) | ||
|
|
||
| if not movie_name: | ||
| embed = Embed( | ||
| title="Snake Movies", | ||
| description="A list of snake movies.", | ||
| ) | ||
|
|
||
| for movie in movies_dict.values(): | ||
| embed.add_field(name=movie['title'], value=f"bot.movies('{movie['title']}')\n\n") | ||
|
|
||
| embed.set_thumbnail(url="https://i.imgur.com/dB38NwN.png") | ||
|
|
||
| else: | ||
| movie_name = movie_name.lower() | ||
| if movie_name in movies_dict: | ||
| embed = Embed( | ||
| title=movies_dict[movie_name]['title'], | ||
| description=movies_dict[movie_name]['description'] | ||
| ) | ||
|
|
||
| embed.add_field(name="Director", value=movies_dict[movie_name]['director']) | ||
| embed.add_field(name="Release Date", value=movies_dict[movie_name]['released']) | ||
| embed.set_image(url=movies_dict[movie_name]['image']) | ||
| else: | ||
| embed = Embed( | ||
| title="Movie Not Found", | ||
| description="The movie you entered was not found." | ||
| ) | ||
|
|
||
| # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! | ||
| await ctx.send(embed=embed) | ||
|
|
||
|
|
||
| def setup(bot): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| { | ||
| "snakes on a plane": | ||
| { | ||
| "title": "Snakes On A Plane", | ||
| "description": "An FBI agent takes on a plane full of deadly and venomous snakes, deliberately released to kill a witness being flown from Honolulu to Los Angeles to testify against a mob boss.", | ||
| "director": "David R. Ellis", | ||
| "released": "18 August 2006", | ||
| "image": "https://i.imgur.com/oxe9vyF.jpg" | ||
| }, | ||
|
|
||
| "anaconda": | ||
| { | ||
| "title": "Anaconda", | ||
| "description": "A 'National Geographic' film crew is taken hostage by an insane hunter, who takes them along on his quest to capture the world's largest - and deadliest - snake.", | ||
| "director": "Luis Llosa", | ||
| "released": "11 April 1997", | ||
| "image": "https://i.imgur.com/9fRXtXf.jpg" | ||
| }, | ||
|
|
||
| "snakes" : | ||
| { | ||
| "title": "Snakes", | ||
| "description": "A snake lover sends out venomous snakes and reptiles to kill his enemies.", | ||
| "director": "Arthur A. Names", | ||
| "released": "December 1974", | ||
| "image": "https://i.imgur.com/tWhqvJp.jpg" | ||
| }, | ||
|
|
||
| "king cobra": | ||
| { | ||
| "title": "King Cobra", | ||
| "description": "A mutated snake escapes from a laboratory and terrorizes the residents of a small California brewery town.", | ||
| "director": "David Hillenbrand", | ||
| "released": "10 August 1999", | ||
| "image": "https://i.imgur.com/egFXDoW.jpg" | ||
| }, | ||
|
|
||
| "venom": | ||
| { | ||
| "title": "Venom", | ||
| "description": "Terrorists in the process of kidnapping a child get trapped in a house with an extremely deadly snake.", | ||
| "director": "Piers Haggard", | ||
| "released": "29 January 1982", | ||
| "image": "https://i.imgur.com/izxwULE.jpg" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| { | ||
| "python": | ||
| { | ||
| "name": "python", | ||
| "description": "Python is an interpreted high-level programming language for general-purpose programming. Python has a design philosophy that emphasizes code readability, notably using significant whitespace. It provides constructs that enable clear programming on both small and large scales.", | ||
| "creator": "Guido van Rossum", | ||
| "created": "First concieved in the late 1980's.", | ||
| "image": "https://i.imgur.com/GDcwKmZ.png" | ||
| }, | ||
|
|
||
| "cobra": | ||
| { | ||
| "name": "cobra", | ||
| "description": "Cobras are large and diverse group of snakes. There are 270 different types of cobras.", | ||
| "location": "Africa, Asia and Australia, usually in forests and areas near river.", | ||
| "venomous": "Yes", | ||
| "image": "https://i.imgur.com/WSnvhC0.jpg" | ||
| }, | ||
|
|
||
| "anaconda": | ||
| { | ||
| "name": "anaconda", | ||
| "description": "Anacondas are the largest and heaviest known snakes. There are 4 types of anacondas.", | ||
| "location": "Tropical rainforests, lakes and swamps of South America. Anacondas are especially numerous near Amazon and Orinoco rivers.", | ||
| "venomous": "No", | ||
| "image": "https://i.imgur.com/MNIY8zX.jpg" | ||
| }, | ||
|
|
||
| "black mamba": | ||
| { | ||
| "name": "black mamba", | ||
| "description": "Black mamba is one of the deadliest snakes on the planet. Black mamba can survive in different types of habitat: savannas, swamps, forests, woods and rocky areas.", | ||
| "location": "Eastern and Southern parts of Africa", | ||
| "venomous": "Yes", | ||
| "image": "https://i.imgur.com/aLbAFkE.jpg" | ||
| }, | ||
|
|
||
| "rattlesnake": | ||
| { | ||
| "name": "rattlesnake", | ||
| "description": "Rattlesnakes are easily recognized animals. There are 32 known species of rattlesnakes. Major threats to survival of rattlesnakes are habitat loss and organized killing (extermination) due to fear of these creatures.", | ||
| "location": "North and South America.", | ||
| "venomous": "Yes", | ||
| "image": "https://i.imgur.com/BjWQ9Tv.jpg" | ||
| }, | ||
|
|
||
| "boa constrictor": | ||
| { | ||
| "name": "boa constrictor", | ||
| "description": "Boa constrictor is a close relative of anaconda. Boa constrictor is known as one of the most beautiful snakes because of its colorful skin with interesting prints.", | ||
| "location": "South and Central America.", | ||
| "venomous": "No", | ||
| "image": "https://i.imgur.com/vuJeUwl.jpg" | ||
| }, | ||
|
|
||
| "king": | ||
| { | ||
| "name": "king", | ||
| "description": "King snake is a type of snake that belongs to the colubrid family. There are 11 species and 45 subspecies of king snakes", | ||
| "location": "North, Central and South America. ", | ||
| "venomous": "No", | ||
| "image": "https://i.imgur.com/7XsXJGs.jpg" | ||
| }, | ||
|
|
||
| "taipan":{ | ||
| "name": "taipan", | ||
| "description": "The taipans are snakes of the genus Oxyuranus in the elapid family. They are large and fast-moving. The taipans are considered some of the most deadly known snakes.", | ||
| "location": "Australasia", | ||
| "venomous": "Yes", | ||
| "image": "https://i.imgur.com/Z0y52fm.jpg" | ||
| }, | ||
|
|
||
| "sea snake": | ||
| { | ||
| "name": "sea snake", | ||
| "description": "Sea snakes are group of snakes adapted to the life in salty and brackish water. Sea snakes belong to the family of cobras.", | ||
| "location": "Indian and Pacific Ocean.", | ||
| "venomous": "Yes", | ||
| "image": "https://i.imgur.com/hEjQK0m.jpg" | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break if the snake isn't in the dict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I send an error message to the discord chat if this is just a normal function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe look into exception handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should it just not prompt the user if the snake cannot be found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course it should. But you can't send the message directly from this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it doesn't exist, could I return
snakeas a string and test if it is a string inget()and just send a message if it is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might prefer to return
Noneor something, but yesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do
Noneit returns a random snake, so I'm not sure what I would do.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the approach is up to you. Do what works for you.