-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 6 #20
base: master
Are you sure you want to change the base?
Team 6 #20
Changes from all commits
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 |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
import logging | ||
from typing import Any, Dict | ||
|
||
import discord | ||
import random | ||
import aiohttp | ||
import json | ||
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. ditto with the imports. Try having your imports in separate groups: import logging
from typing import Any, Dict
import random
import json
import aiohttp
from bs4 import BeautifulSoup
import discord
from discord.ext.commands import AutoShardedBot, Context, command |
||
from bs4 import BeautifulSoup | ||
from discord.ext.commands import AutoShardedBot, Context, command | ||
|
||
log = logging.getLogger(__name__) | ||
|
@@ -29,6 +34,25 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: | |
:return: A dict containing information on a snake | ||
""" | ||
|
||
# Getting the summary | ||
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 function still needs to give a random snake when Additionally, this method is case-sensitive. |
||
|
||
async with aiohttp.ClientSession() as session: | ||
async with session.get('https://en.wikipedia.org/w/api.php?action=parse&format=json&page=' + name + '§ion=1') 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. This line is too long. Try defining your URL on a separate line, and passing that into |
||
text_data = await resp.json() | ||
text = json.loads(text_data) | ||
html = text["text"]["*"] | ||
soup = BeautifulSoup(html) | ||
summary = soup.find('p') | ||
|
||
# Getting the image | ||
|
||
async with aiohttp.ClientSession() as session: | ||
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 remove this 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. Meaning put everything under 1 session? |
||
async with session.get('https://en.wikipedia.org/w/api.php?format=json&action=query&titles=' + name + '&prop=pageimages&pithumbsize=300') 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. Line lengths again. Try having the URL string defined on a previous line. |
||
image_data = await resp.json() | ||
image = json.loads(image_data) | ||
url = image["thumbnail"]["source"] | ||
|
||
return {'summary': summary, 'url': url} | ||
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 should be a space after this line. |
||
@command() | ||
async def get(self, ctx: Context, name: str = None): | ||
""" | ||
|
@@ -41,8 +65,20 @@ async def get(self, ctx: Context, name: str = None): | |
:param name: Optional, the name of the snake to get information for - omit for a random snake | ||
""" | ||
|
||
# Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! | ||
data = await self.get_snek(name) | ||
await ctx.send(data) | ||
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. Your data needs to be formatted and placed into an embed. |
||
|
||
# The snake moult command | ||
|
||
@command() | ||
async def moult(self, ctx: Context): | ||
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 would prefer if this just got the bot role and changed its colour, but this is a fun command either way! |
||
await ctx.send("sssss... moulting in progress...") | ||
green = discord.utils.get(ctx.guild.roles, name="Green Skin") | ||
black = discord.utils.get(ctx.guild.roles, name="Black Skin") | ||
yellow = discord.utils.get(ctx.guild.roles, name="Yellow Skin") | ||
await ctx.guild.me.remove_roles() | ||
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 remove all the roles, won't it? Maybe specify the roles that should be removed. 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. Ill get right on fixing. :) |
||
await ctx.guild.me.add_roles(random.choice(green, black, yellow)) | ||
await ctx.send("sssss... and now you can't see me...") | ||
|
||
def setup(bot): | ||
bot.add_cog(Snakes(bot)) | ||
|
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 import should be two lines before
import discord
, since it's a standard library module.