-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 14 #21
base: master
Are you sure you want to change the base?
Team 14 #21
Changes from all commits
70da776
b6dd9c5
6507c15
413d669
3766da4
2743cf7
2584a64
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,11 +1,10 @@ | ||
# coding=utf-8 | ||
import logging | ||
from typing import Any, Dict | ||
|
||
from discord.ext.commands import AutoShardedBot, Context, command | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
import discord | ||
|
||
class Snakes: | ||
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 should have two blank lines before a definition. |
||
""" | ||
|
@@ -18,29 +17,35 @@ 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 | ||
|
||
""" | ||
|
||
|
||
@command() | ||
async def get(self, ctx: Context, name: str = None): | ||
async def get(self, ctx: Context, *, query: 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 | ||
""" | ||
|
||
em = discord.Embed(title=str(query)) | ||
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. There's nothing wrong with using |
||
em.set_footer(text='Powered by wikipedia.org') | ||
async with self.bot.http_session.get(f"https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles={query}") as resp: | ||
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 want to have this string format defined on a separate line. Travis agrees. |
||
data = await resp.json() | ||
data = data['query'] | ||
em.description = (data["pages"][list(data["pages"].keys())[0]]["extract"])[:2000] | ||
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 line would look a lot better split over several lines. There's no need to have it all on a single line. |
||
await ctx.send(embed=em) | ||
|
||
|
||
# Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! | ||
|
||
|
||
|
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 module level import should be at the top of the file.
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.
(preferably before
from discord.ext.commands import AutoShardedBot, Context, command
)