Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions bot/cogs/snakes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# coding=utf-8
import json
import logging
from typing import Any, Dict
import random
from typing import Tuple

from discord import Embed
from discord.ext.commands import AutoShardedBot, Context, command

log = logging.getLogger(__name__)
Expand All @@ -14,8 +17,14 @@ class Snakes:

def __init__(self, bot: AutoShardedBot):
self.bot = bot
self.python_image = "https://www.python.org/static/community_logos/python-logo-master-v3-TM.png"
self.python_info = ("The Python Programming language(Python Sermone) is a dynamically typed, interpreted "
"programming language. It is a member of the high level programming languges usually "
"found in areas like backend web development data science and AI.")
with open("bot/db/db.json", "r") as db:
self.db = json.load(db)

async def get_snek(self, name: str = None) -> Dict[str, Any]:
async def get_snek(self, name: str = None) -> Tuple[str, str, str]:
"""
Go online and fetch information about a snake

Expand All @@ -28,6 +37,16 @@ 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
"""
if name:
name = name.lower()
if name == "python":
return ("python", self.python_info, self.python_image)
else:
for key in self.db.keys():
if key.lower() == name.lower():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but you already lowered the name..?

return (key, self.db[key][0], self.db[key][1])
else:
return self.db[random.choice(list(self.db.keys()))]

@command()
async def get(self, ctx: Context, name: str = None):
Expand All @@ -40,6 +59,13 @@ 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:
snake_embed = Embed(title=snake[0], description=snake[1])
snake_embed.set_image(url=snake[2])
await ctx.send(embed=snake_embed)
else:
await ctx.send("I was not able to find your snake, I am sorry.")

# Any additional commands can be placed here. Be creative, but keep it to a reasonable amount!

Expand Down
1 change: 1 addition & 0 deletions bot/db/db.json

Large diffs are not rendered by default.