From ba3673eed2357967d702d81f36d0c8213f104ac8 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Fri, 23 Mar 2018 22:39:30 +0000 Subject: [PATCH 01/16] Started get_snek, searching needs to be added but randomisation completed --- bot/cogs/snakes.py | 13 +++++++++++++ bot/db/snakes.json | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 bot/db/snakes.json diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index c9ed8042..7bea3462 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,6 +1,8 @@ # coding=utf-8 import logging from typing import Any, Dict +import json +import random from discord.ext.commands import AutoShardedBot, Context, command @@ -28,6 +30,17 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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('snakes.json', 'r') as file: + snakes_dict = json.load(file) + + if name == None: + snake_name, snake_info = random.choice(list(snakes_dict.items())) + + elif name == "Python": + print("stuff about python lang") + + return snake_name, snake_info + @command() async def get(self, ctx: Context, name: str = None): diff --git a/bot/db/snakes.json b/bot/db/snakes.json new file mode 100644 index 00000000..a8dc1037 --- /dev/null +++ b/bot/db/snakes.json @@ -0,0 +1,17 @@ +{ + "cobra": + { + "info": "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": + { + "info": "Anacondas are the largest and heaviest known snakes. There are 4 types of anacondas", + "location": "Tropical rainforests, lakes and swamps of South America", + "venomous": "No", + "image": "https://i.imgur.com/MNIY8zX.jpg" + } +} \ No newline at end of file From a4a6682dfbb6634d84ae8d8016c4996ed5d6d336 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Fri, 23 Mar 2018 22:55:03 +0000 Subject: [PATCH 02/16] Changed location of snakes.json in snakes.py so that it can actually read the file --- bot/cogs/snakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 7bea3462..8bbdef14 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -30,7 +30,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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('snakes.json', 'r') as file: + with open('bot/db/snakes.json', 'r') as file: snakes_dict = json.load(file) if name == None: @@ -38,7 +38,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: elif name == "Python": print("stuff about python lang") - + return snake_name, snake_info From 09bbae95087ba8362ce3278c5f178525a88fa8a6 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sat, 24 Mar 2018 13:33:45 +0000 Subject: [PATCH 03/16] Finished get() command but may need to edit things later on. --- bot/cogs/snakes.py | 73 +++++++++++++++++++++++++++------------------- bot/db/snakes.json | 19 +++++++++--- 2 files changed, 58 insertions(+), 34 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 8bbdef14..432f4f6b 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -5,6 +5,7 @@ import random from discord.ext.commands import AutoShardedBot, Context, command +from discord import Embed log = logging.getLogger(__name__) @@ -18,41 +19,53 @@ 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 - - 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 "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 name == None: - snake_name, snake_info = random.choice(list(snakes_dict.items())) + if name == None or len(name) == 0: + _, snake_info = random.choice(list(snakes_dict.items())) - elif name == "Python": - print("stuff about python lang") - - return snake_name, snake_info - - - @command() + elif len(name) > 0: + snake = snakes_dict[name] + if snake['name'] != "Python": + snake_info = { + 'name': snake['name'], + 'description': snake['description'], + 'location': snake['location'], + 'venomous': snake['venomous'], + 'image': snake['image'] + } + else: + snake_info = { + 'name': snake['name'], + 'description': snake['description'], + 'creator': snake['creator'], + 'created': snake['created'], + 'image': snake['image'] + } + + return snake_info + + + @command(name='get') async def get(self, ctx: Context, name: str = None): - """ - Go online and fetch information about a snake - - 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. - - :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_info = await self.get_snek(name) + + embed = Embed( + title=snake_info['name'], + description=snake_info['description'] + ) + + 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) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! diff --git a/bot/db/snakes.json b/bot/db/snakes.json index a8dc1037..f6ae9159 100644 --- a/bot/db/snakes.json +++ b/bot/db/snakes.json @@ -1,16 +1,27 @@ { + "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": { - "info": "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", + "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": { - "info": "Anacondas are the largest and heaviest known snakes. There are 4 types of anacondas", - "location": "Tropical rainforests, lakes and swamps of South America", + "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" } From 729023be1fa04140f55b758bdecda418494e367a Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sat, 24 Mar 2018 14:51:44 +0000 Subject: [PATCH 04/16] Fixing some travis issues --- bot/cogs/snakes.py | 25 ++++++++++++------------- bot/db/snakes.json | 10 +++++----- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 432f4f6b..c2102c2b 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,11 +1,11 @@ # coding=utf-8 import logging -from typing import Any, Dict import json +from typing import Any, Dict import random -from discord.ext.commands import AutoShardedBot, Context, command from discord import Embed +from discord.ext.commands import AutoShardedBot, Context, command log = logging.getLogger(__name__) @@ -22,12 +22,12 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: with open('bot/db/snakes.json', 'r') as file: snakes_dict = json.load(file) - if name == None or len(name) == 0: + if name is None or len(name) == 0: _, snake_info = random.choice(list(snakes_dict.items())) - + elif len(name) > 0: - snake = snakes_dict[name] - if snake['name'] != "Python": + snake = snakes_dict[name.lower()] + if snake['name'] != "python": snake_info = { 'name': snake['name'], 'description': snake['description'], @@ -46,23 +46,22 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: return snake_info - @command(name='get') async def get(self, ctx: Context, name: str = None): snake_info = await self.get_snek(name) embed = Embed( - title=snake_info['name'], + title=snake_info['name'].title(), description=snake_info['description'] ) - 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']) + 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.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) diff --git a/bot/db/snakes.json b/bot/db/snakes.json index f6ae9159..4e87f986 100644 --- a/bot/db/snakes.json +++ b/bot/db/snakes.json @@ -1,16 +1,16 @@ { - "Python": + "python": { - "name": "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", + "created": "First concieved in the late 1980's.", "image": "https://i.imgur.com/GDcwKmZ.png" }, "cobra": { - "name": "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", @@ -19,7 +19,7 @@ "anaconda": { - "name": "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", From 68f4869c6c45ba5e03871ee43c37de40b0631417 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sat, 24 Mar 2018 14:55:28 +0000 Subject: [PATCH 05/16] Fixing more travis issues --- bot/cogs/snakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index c2102c2b..4be67c7d 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,8 +1,8 @@ # coding=utf-8 -import logging import json -from typing import Any, Dict +import logging import random +from typing import Any, Dict from discord import Embed from discord.ext.commands import AutoShardedBot, Context, command From 9ad497c6abe23907f19af827f7dc0c7f14d3a1d9 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sat, 24 Mar 2018 15:02:35 +0000 Subject: [PATCH 06/16] Fixing flake8 issues --- bot/cogs/snakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 4be67c7d..548a6f7b 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -49,12 +49,12 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: @command(name='get') async def get(self, ctx: Context, name: str = None): snake_info = await self.get_snek(name) - + embed = Embed( title=snake_info['name'].title(), description=snake_info['description'] ) - + 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']) From 59beaedb5213b12036f07b21ac2e25ded14694e4 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sat, 24 Mar 2018 15:29:07 +0000 Subject: [PATCH 07/16] Even more flake8 issues --- bot/cogs/snakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 548a6f7b..fa3f8714 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -54,7 +54,7 @@ async def get(self, ctx: Context, name: str = None): title=snake_info['name'].title(), description=snake_info['description'] ) - + 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']) @@ -63,7 +63,7 @@ async def get(self, ctx: Context, name: str = None): 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) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From c595d738800ce52b4f9500f0ac5645140a375000 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sat, 24 Mar 2018 15:41:34 +0000 Subject: [PATCH 08/16] More flake8 issues --- bot/cogs/snakes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index fa3f8714..cb652882 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -63,7 +63,7 @@ async def get(self, ctx: Context, name: str = None): 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) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 8c7b7f190bd308fc344c12c962cd2359c61e9533 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sat, 24 Mar 2018 22:15:30 +0000 Subject: [PATCH 09/16] Added second command, it shows snake movies --- bot/cogs/snakes.py | 33 ++++++++++++++++++++++++++++++++- bot/db/movies.json | 36 ++++++++++++++++++++++++++++++++++++ bot/db/snakes.json | 27 +++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 bot/db/movies.json diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index cb652882..04710c38 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -48,6 +48,10 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: @command(name='get') async def get(self, ctx: Context, name: str = None): + """ + Shows information on different snakes. + """ + snake_info = await self.get_snek(name) embed = Embed( @@ -66,8 +70,35 @@ async def get(self, ctx: Context, name: str = None): await ctx.send(embed=embed) - # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! + @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 movie_name is None or len(movie_name) == 0: + 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") + + embed.set_thumbnail(url="https://i.imgur.com/dB38NwN.png") + + elif len(movie_name) > 0: + embed = Embed( + title=movies_dict[movie_name]['title'], + description=movies_dict[movie_name]['description'] + ) + + embed.set_image(url=movies_dict[movie_name]['image']) + + await ctx.send(embed=embed) def setup(bot): bot.add_cog(Snakes(bot)) diff --git a/bot/db/movies.json b/bot/db/movies.json new file mode 100644 index 00000000..cd78680c --- /dev/null +++ b/bot/db/movies.json @@ -0,0 +1,36 @@ +{ + "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.", + "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.", + "image": "https://i.imgur.com/9fRXtXf.jpg" + }, + + "snakes" : + { + "title": "Snakes", + "description": "A snake lover sends out venomous snakes and reptiles to kill his enemies.", + "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.", + "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.", + "image": "https://i.imgur.com/izxwULE.jpg" + } +} \ No newline at end of file diff --git a/bot/db/snakes.json b/bot/db/snakes.json index 4e87f986..5e173d45 100644 --- a/bot/db/snakes.json +++ b/bot/db/snakes.json @@ -24,5 +24,32 @@ "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" } } \ No newline at end of file From 792bba764f8efed922f681b5786325f677241aeb Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sat, 24 Mar 2018 22:20:19 +0000 Subject: [PATCH 10/16] fixing flake8 issues --- bot/cogs/snakes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 04710c38..975e285f 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -51,7 +51,7 @@ async def get(self, ctx: Context, name: str = None): """ Shows information on different snakes. """ - + snake_info = await self.get_snek(name) embed = Embed( @@ -100,6 +100,7 @@ async def movies(self, ctx: Context, movie_name: str = None): await ctx.send(embed=embed) + def setup(bot): bot.add_cog(Snakes(bot)) log.info("Cog loaded: Snakes") From f1cdc6a0b3de5fa93eec780c1d817577138ebef9 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sun, 25 Mar 2018 00:51:40 +0000 Subject: [PATCH 11/16] Added director and release date --- bot/cogs/snakes.py | 2 ++ bot/db/movies.json | 10 ++++++++++ bot/db/snakes.json | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 975e285f..37d1ef79 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -96,6 +96,8 @@ async def movies(self, ctx: Context, movie_name: str = None): 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) diff --git a/bot/db/movies.json b/bot/db/movies.json index cd78680c..1df44012 100644 --- a/bot/db/movies.json +++ b/bot/db/movies.json @@ -3,6 +3,8 @@ { "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" }, @@ -10,6 +12,8 @@ { "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" }, @@ -17,6 +21,8 @@ { "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" }, @@ -24,6 +30,8 @@ { "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" }, @@ -31,6 +39,8 @@ { "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" } } \ No newline at end of file diff --git a/bot/db/snakes.json b/bot/db/snakes.json index 5e173d45..968c6864 100644 --- a/bot/db/snakes.json +++ b/bot/db/snakes.json @@ -51,5 +51,31 @@ "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" } } \ No newline at end of file From b97736cce2ad766ffc6dfd225fc45bcc9adff5fa Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sun, 25 Mar 2018 14:12:53 +0100 Subject: [PATCH 12/16] Added back string docs, also fixed some errors if snakes were not found --- bot/cogs/snakes.py | 103 ++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 37d1ef79..8142e34f 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -19,24 +19,31 @@ 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 + + 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 "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 name is None or len(name) == 0: - _, snake_info = random.choice(list(snakes_dict.items())) + if not name: + _, snake = random.choice(list(snakes_dict.items())) + + elif name.lower() not in snakes_dict: + snake = "Not Found" - elif len(name) > 0: + else: snake = snakes_dict[name.lower()] - if snake['name'] != "python": - snake_info = { - 'name': snake['name'], - 'description': snake['description'], - 'location': snake['location'], - 'venomous': snake['venomous'], - 'image': snake['image'] - } - else: - snake_info = { + if snake['name'] == "python": + snake = { 'name': snake['name'], 'description': snake['description'], 'creator': snake['creator'], @@ -44,29 +51,40 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: 'image': snake['image'] } - return snake_info + return snake @command(name='get') async def get(self, ctx: Context, name: str = None): """ - Shows information on different snakes. + Go online and fetch information about a snake + + 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. + + :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) - snake_info = await self.get_snek(name) - - embed = Embed( - title=snake_info['name'].title(), - description=snake_info['description'] - ) + if snake != "Not Found": + embed = Embed( + title=snake['name'].title(), + description=snake['description'] + ) - 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']) + 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.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']) + embed = Embed( + title="Snake Not Found", + description="The snake you entered was not found." + ) await ctx.send(embed=embed) @@ -79,26 +97,33 @@ async def movies(self, ctx: Context, movie_name: str = None): with open('bot/db/movies.json', 'r') as file: movies_dict = json.load(file) - if movie_name is None or len(movie_name) == 0: + 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'].lower()}')\n\n") + embed.add_field(name=movie['title'], value=f"bot.movies('{movie['title']}')\n\n") embed.set_thumbnail(url="https://i.imgur.com/dB38NwN.png") - elif len(movie_name) > 0: - 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: + 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." + ) await ctx.send(embed=embed) From 6b735ded005f2681912686f18826ca24fb2ddfe6 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sun, 25 Mar 2018 14:16:43 +0100 Subject: [PATCH 13/16] Fixing flake8 issues --- bot/cogs/snakes.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 8142e34f..3fa79750 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -21,13 +21,13 @@ def __init__(self, bot: AutoShardedBot): async def get_snek(self, name: str = None) -> Dict[str, Any]: """ Go online and fetch information about a snake - + 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 "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 """ @@ -57,7 +57,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: async def get(self, ctx: Context, name: str = None): """ Go online and fetch information about a snake - + 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. From b8aedd602104b12ecf8a711ebc4f167295b45541 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sun, 25 Mar 2018 14:31:49 +0100 Subject: [PATCH 14/16] fixing flake8 issues --- bot/cogs/snakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 3fa79750..1d0d4762 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -27,7 +27,7 @@ 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 """ @@ -60,7 +60,7 @@ async def get(self, ctx: Context, name: str = None): 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. - + :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 """ From 5a32358674829fe5825d2ca8757716fdadc78736 Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sun, 25 Mar 2018 14:45:58 +0100 Subject: [PATCH 15/16] fixing flake8 issues --- bot/cogs/snakes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 1d0d4762..782d805e 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -27,7 +27,7 @@ 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 """ From 6f71cd798508aea3b6ad019bff1e366088167e2e Mon Sep 17 00:00:00 2001 From: SamuelHallam Date: Sun, 25 Mar 2018 16:54:11 +0100 Subject: [PATCH 16/16] Added more snakes --- bot/cogs/snakes.py | 4 ++-- bot/db/movies.json | 10 ++++----- bot/db/snakes.json | 56 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 782d805e..93d76f09 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -104,7 +104,7 @@ async def movies(self, ctx: Context, movie_name: str = None): ) for movie in movies_dict.values(): - embed.add_field(name=movie['title'], value=f"bot.movies('{movie['title']}')\n\n") + embed.add_field(name=movie['title'].title(), value=f"bot.movies('{movie['title'].title()}')\n\n") embed.set_thumbnail(url="https://i.imgur.com/dB38NwN.png") @@ -112,7 +112,7 @@ async def movies(self, ctx: Context, movie_name: str = None): movie_name = movie_name.lower() if movie_name in movies_dict: embed = Embed( - title=movies_dict[movie_name]['title'], + title=movies_dict[movie_name]['title'].title(), description=movies_dict[movie_name]['description'] ) diff --git a/bot/db/movies.json b/bot/db/movies.json index 1df44012..f5043d18 100644 --- a/bot/db/movies.json +++ b/bot/db/movies.json @@ -1,7 +1,7 @@ { "snakes on a plane": { - "title": "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", @@ -10,7 +10,7 @@ "anaconda": { - "title": "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", @@ -19,7 +19,7 @@ "snakes" : { - "title": "Snakes", + "title": "snakes", "description": "A snake lover sends out venomous snakes and reptiles to kill his enemies.", "director": "Arthur A. Names", "released": "December 1974", @@ -28,7 +28,7 @@ "king cobra": { - "title": "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", @@ -37,7 +37,7 @@ "venom": { - "title": "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", diff --git a/bot/db/snakes.json b/bot/db/snakes.json index 968c6864..c93f2465 100644 --- a/bot/db/snakes.json +++ b/bot/db/snakes.json @@ -53,7 +53,7 @@ "image": "https://i.imgur.com/vuJeUwl.jpg" }, - "king": + "king snake": { "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", @@ -77,5 +77,59 @@ "location": "Indian and Pacific Ocean.", "venomous": "Yes", "image": "https://i.imgur.com/hEjQK0m.jpg" + }, + + "garter": + { + "name": "garter snake", + "description": "Garter snakes are among the most common snakes in some countries. Often kept as pets, they are relatively harmless, although some species do possess a mild neurotoxic venom.", + "location": "North America; from Canada to Florida", + "venomous": "No", + "image": "https://i.imgur.com/qTFD4ml.jpg" + }, + + "mole snake": + { + "name": "mole snake", + "description": "Mole snakes spend the vast majority of their time underground. Their muscular build and pointed snout make them adept at pushing themselves through sandy burrows after their prey which consists primarily of golden moles and mole/dune rats.", + "location": "South Africa", + "venomous": "No", + "image": "https://i.imgur.com/VQKg9kb.jpg" + }, + + "false cobra": + { + "name": "false cobra", + "description": "The name 'false cobra' comes from the fact that this is not a cobra. It imitates a cobra's stance by spreading its neck into a hood and hissing like the cobra. It can grow up to 1.5 metres in length and preys on rodents and lizards.", + "location": "Africa and the Middle East", + "venomous": "Yes", + "image": "https://i.imgur.com/xmkrI4v.jpg" + }, + + "ninia": + { + "name": "ninia", + "description": "Ninia is a genus of colubroid snakes commonly referred to as coffee snakes. The genus consists of 10 species.", + "location": "Mexico, Central America and northern South America.", + "venomous": "No", + "image": "https://i.imgur.com/4BUr6vH.jpg" + }, + + "sharp-tailed": + { + "name": "sharp-tailed", + "description": "The sharp-tailed snake averages from eight to twelve inches long as an adult. It is distinguished by its sharp tail spine, which is the protruding tip of the last tail vertebra. The spine is not toxic and cannot injure humans.", + "location": "Western United States and parts of British Colombia", + "venomous": "No", + "image": "https://i.imgur.com/SNX5p2Z.jpg" + }, + + "sunbeam": + { + "name": "sunbeam", + "description": "Sunbeam snakes are thicker than a large banana (with skin) as adults. Their scales are very smooth and the snake has a texture like rubber. Dirt doesn’t appear to stick to the scales.", + "location": "South East Asia", + "venomous": "No", + "image": "https://i.imgur.com/vBRnuxv.jpg" } } \ No newline at end of file