-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 9 #17
base: master
Are you sure you want to change the base?
Team 9 #17
Changes from 13 commits
1942d08
ba3673e
a4a6682
09bbae9
1b213f3
729023b
68f4869
9ad497c
59beaed
c595d73
8c7b7f1
792bba7
f1cdc6a
b97736c
6b735de
b8aedd6
5a32358
6f71cd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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__) | ||
|
|
@@ -16,32 +19,88 @@ def __init__(self, bot: AutoShardedBot): | |
| self.bot = bot | ||
|
|
||
| async def get_snek(self, name: str = None) -> Dict[str, Any]: | ||
| """ | ||
| Go online and fetch information about a snake | ||
| with open('bot/db/snakes.json', 'r') as file: | ||
| snakes_dict = json.load(file) | ||
|
|
||
| The information includes the name of the snake, a picture of the snake, and various other pieces of info. | ||
| What information you get for the snake is up to you. Be creative! | ||
| if name is None or len(name) == 0: | ||
|
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. You could replace this entire thing with |
||
| _, snake_info = random.choice(list(snakes_dict.items())) | ||
|
|
||
| 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! | ||
| elif len(name) > 0: | ||
|
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. That can just be an |
||
| snake = snakes_dict[name.lower()] | ||
|
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. This will break if the snake isn't in the dict.
Author
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. How can I send an error message to the discord chat if this is just a normal function?
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. You can't.
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. Maybe look into exception handling?
Author
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. So should it just not prompt the user if the snake cannot be found?
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. Of course it should. But you can't send the message directly from this method.
Author
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. If it doesn't exist, could I return
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. You might prefer to return
Author
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. If I do
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. Well, the approach is up to you. Do what works for you. |
||
| if snake['name'] != "python": | ||
| snake_info = { | ||
| 'name': snake['name'], | ||
| 'description': snake['description'], | ||
| 'location': snake['location'], | ||
| 'venomous': snake['venomous'], | ||
| 'image': snake['image'] | ||
| } | ||
|
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. If this is how the information is stored, then you could just
Author
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. I see what you mean, I think I did that because I have different information for the Python Language. I guess I would only need to change
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. Well, no, I mean, the keys you're placing into the dict match the keys that you're pulling out of the snake dict. It's just redundant. |
||
| else: | ||
| snake_info = { | ||
| 'name': snake['name'], | ||
| 'description': snake['description'], | ||
| 'creator': snake['creator'], | ||
| 'created': snake['created'], | ||
| 'image': snake['image'] | ||
| } | ||
|
|
||
| :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 | ||
| """ | ||
| return snake_info | ||
|
|
||
| @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 | ||
| Shows information on different snakes. | ||
| """ | ||
|
|
||
| snake_info = await self.get_snek(name) | ||
|
|
||
| This should make use of your `get_snek` method, using it to get information about a snake. This information | ||
| should be sent back to Discord in an embed. | ||
| embed = Embed( | ||
| title=snake_info['name'].title(), | ||
| description=snake_info['description'] | ||
| ) | ||
|
|
||
| :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 | ||
| if snake_info['name'] != "python": | ||
| embed.add_field(name="Where can you find them?", value=snake_info['location']) | ||
| embed.add_field(name="Are they venomous?", value=snake_info['venomous']) | ||
| embed.set_image(url=snake_info['image']) | ||
| else: | ||
| embed.add_field(name="Who created it?", value=snake_info['creator']) | ||
| embed.add_field(name="When was it created?", value=snake_info['created']) | ||
| embed.set_thumbnail(url=snake_info['image']) | ||
|
|
||
| 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. | ||
| """ | ||
|
|
||
| # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! | ||
| with open('bot/db/movies.json', 'r') as file: | ||
| movies_dict = json.load(file) | ||
|
|
||
| if movie_name is None or len(movie_name) == 0: | ||
|
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. Again, could use |
||
| 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'].lower()}')\n\n") | ||
|
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. Maybe |
||
|
|
||
| embed.set_thumbnail(url="https://i.imgur.com/dB38NwN.png") | ||
|
|
||
| elif len(movie_name) > 0: | ||
|
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. Again, could just be |
||
| embed = Embed( | ||
| title=movies_dict[movie_name]['title'], | ||
|
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. This will break if the movie isn't in the dict, or it isn't entirely lowercase. Should fix that. |
||
| 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']) | ||
|
|
||
| await ctx.send(embed=embed) | ||
|
|
||
|
|
||
| def setup(bot): | ||
|
|
||
| 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" | ||
| } | ||
| } |
| 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" | ||
| } | ||
| } |
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 should bring back the docstring - why'd you remove it?