Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.

Team 6 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
38 changes: 37 additions & 1 deletion bot/cogs/snakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import logging
from typing import Any, Dict

import discord
import random
Copy link

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.

import aiohttp
import json
Copy link

Choose a reason for hiding this comment

The 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__)
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

This function still needs to give a random snake when name is None, and also it needs to special-case Python and return information about the programming language.

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 + '&section=1') as resp:
Copy link

Choose a reason for hiding this comment

The 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 session.get.

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

You could remove this with block and just use the one you already have above.

Copy link
Author

Choose a reason for hiding this comment

The 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:
Copy link

Choose a reason for hiding this comment

The 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}
Copy link
Contributor

Choose a reason for hiding this comment

The 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):
"""
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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):
Copy link
Contributor

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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))
Expand Down