-
-
Notifications
You must be signed in to change notification settings - Fork 15
Team 11 #11
base: master
Are you sure you want to change the base?
Team 11 #11
Changes from 45 commits
4c99800
7ed1c2a
020deb7
968c748
3011280
1f6f877
fb31d2b
c8d42d3
b8fdfd7
810ebad
95443bb
367a400
502abb9
4e2c293
ac46387
57d1394
2bcae58
3c7367b
b1376c8
6734b50
090f14f
b5c5402
fcaecfb
71bde19
018e523
59fa010
8e5cf70
e36ae9e
9f075e9
e0db09f
28f1154
2f16d10
b63381e
33bddfc
a2eddb4
34864b5
2ff9b48
5a6932e
6f04e37
ff7469d
2d5f3b6
4765a23
aa5b3ed
9bbeb30
f448a4e
36933e4
417d7a7
6a804bd
ac7c08a
996edba
40efcaa
56da195
0c1c026
989e5d1
adff2e6
4399dcb
8904bce
e0bf1cc
f03b98f
127051f
41b2ba4
a620972
f811720
5987a8a
804af0a
f87d75e
42eae45
0c83aaf
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 |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ __pycache__/ | |
| # Distribution / packaging | ||
| .Python | ||
| env/ | ||
| .idea/ | ||
| .env | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ name = "pypi" | |
| aiodns = "*" | ||
| aiohttp = "<2.3.0,>=2.0.0" | ||
| websockets = ">=4.0,<5.0" | ||
| "beautifulsoup4" = "*" | ||
| wikipedia = "*" | ||
|
Contributor
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. If you're not using this, you should |
||
|
|
||
| [dev-packages] | ||
| "flake8" = "*" | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| # coding=utf-8 | ||
| import logging | ||
| import logging, aiohttp, random, wikipedia | ||
|
Contributor
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. No, you should be using separate lines, and they should be in alphabetical order. |
||
| from time import sleep | ||
| from bs4 import BeautifulSoup | ||
| from typing import Any, Dict | ||
|
|
||
| from discord.ext.commands import AutoShardedBot, Context, command | ||
| import asyncio | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -11,8 +13,22 @@ class Snakes: | |
| """ | ||
| Snake-related commands | ||
| """ | ||
| python_info = ''' | ||
| Python (Programming Language) | ||
|
Contributor
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 probably remove all these huge indents.
Contributor
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 also don't need the |
||
| \n | ||
| Python is powerful... and fast;\n | ||
| plays well with others;\n | ||
| runs everywhere;\n | ||
| is friendly & easy to learn;\n | ||
| is Open. | ||
| ------------------------------- | ||
| Created by: Guido Van Rossum \n | ||
| Founded: 20th of February, 1991 \n | ||
| Official website: https://python.org | ||
| ''' | ||
|
|
||
| def __init__(self, bot: AutoShardedBot): | ||
| self.inputs = [] | ||
| self.bot = bot | ||
|
|
||
| async def get_snek(self, name: str = None) -> Dict[str, Any]: | ||
|
|
@@ -28,9 +44,23 @@ 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 | ||
| """ | ||
| name = str(name) | ||
|
Contributor
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. No, don't do this. If there's no snake name passed, this will now be |
||
| site = 'https://en.wikipedia.org/wiki/' + name | ||
| async with aiohttp.ClientSession() as session: | ||
| async with session.get(site) as resp: | ||
| text = await resp.text() | ||
| soup = BeautifulSoup(text, 'lxml') | ||
|
|
||
|
|
||
| if name.lower() == 'python': | ||
| name = self.python_info | ||
|
|
||
| return name | ||
|
Contributor
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 method doesn't work at all. Return name? Are you still working on this? |
||
|
|
||
|
|
||
|
|
||
| @command() | ||
| async def get(self, ctx: Context, name: str = None): | ||
| async def get(self, ctx: Context, name: str = None,): | ||
| """ | ||
| Go online and fetch information about a snake | ||
|
|
||
|
|
@@ -40,8 +70,93 @@ 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 | ||
| """ | ||
| # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) | ||
| name = str(name) | ||
|
Contributor
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. Again, why are you doing this? |
||
| site = 'https://en.wikipedia.org/wiki/' + name | ||
| async with aiohttp.ClientSession() as session: | ||
| async with session.get(site) as resp: | ||
| text = await resp.text() | ||
| soup = BeautifulSoup(text, 'lxml') | ||
| title = soup.find('h1').text | ||
| description = soup.find('table').text | ||
|
|
||
| em = discord.Embed(title=title, description=description) | ||
|
Contributor
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. While you should be creating the embed in this method, you should be retrieving the information over in |
||
|
|
||
| if name.lower() == 'python': | ||
| await ctx.send(await self.get_snek(name)) | ||
| else: | ||
| await ctx.send(embed=em) | ||
| # await ctx.send(name) | ||
|
|
||
| # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! | ||
| @command() | ||
| async def snake(self, ctx: Context, x=50, y=30): | ||
|
Contributor
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. Really fun idea. But maybe a little ambitious for you guys.
Contributor
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 is super hard to read, I'm going to have to test it to really see what it does. Maybe you could comment it? Also, perhaps you could use reactions via |
||
| board = """""" | ||
| running = True | ||
| snake = [] | ||
|
|
||
| head = [x//2, y//2] | ||
| snake.append(head) | ||
| userID = ctx.author.id | ||
|
|
||
| facing = 0 | ||
|
|
||
| board += "```\n " + "#" * x + "##" | ||
| for yAxis in range(y): | ||
| board += "\n #" | ||
| for xAxis in range(x): | ||
| if head == [xAxis, yAxis]: | ||
| board += "X" | ||
| else: | ||
| board += "0" | ||
|
|
||
| board += "#" | ||
| board += "\n " + "#" * x + "##```" | ||
|
|
||
| snakeBoard = await ctx.send(board) | ||
|
|
||
| while running: | ||
| for mess in self.inputs: | ||
| if mess.author.id == userID: | ||
| self.inputs = [] | ||
| if mess.content == "a": | ||
| facing = (facing - 1) % 4 | ||
| if mess.content == "d": | ||
| facing = (facing + 1) % 4 | ||
| break | ||
|
|
||
| if facing == 0: | ||
| head[1] -= 1 | ||
| elif facing == 1: | ||
| head[0] += 1 | ||
| elif facing == 2: | ||
| head[1] += 1 | ||
| else: | ||
| head[0] -= 1 | ||
|
|
||
| snake.pop(-1) | ||
| snake.append(head) | ||
|
|
||
| board = """""" | ||
| board += "```\n " + "#" * x + "##" | ||
| for yAxis in range(y): | ||
| board += "\n #" | ||
| for xAxis in range(x): | ||
| if head == [xAxis, yAxis]: | ||
| board += "X" | ||
| else: | ||
| board += "0" | ||
|
|
||
| board += "#" | ||
| board += "\n " + "#" * x + "##```" | ||
|
|
||
| await snakeBoard.edit(content=board) | ||
| await asyncio.sleep(0.8) | ||
|
|
||
| # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! | ||
| async def on_message(self, message): | ||
| if message.content in ("w", "a", "s", "d"): | ||
| self.inputs.append(message) | ||
| await message.delete() | ||
|
|
||
|
|
||
| def setup(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.
Aren't these both already in the gitignore?