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 45 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
4c99800
first commit
delterr Mar 23, 2018
7ed1c2a
Added temp code for bot.get
delterr Mar 23, 2018
020deb7
Updated pipfile/pipfile.lock
delterr Mar 23, 2018
968c748
adding temporary code that fetches wiki page on snakes
delterr Mar 23, 2018
3011280
added the fetch code to getsnek
delterr Mar 23, 2018
1f6f877
added .idea/ to .gitignore
Mar 23, 2018
fb31d2b
added get_snek() call to get()
Mar 23, 2018
c8d42d3
replaced message.channel with ctx
Mar 23, 2018
b8fdfd7
Removed snake find
delterr Mar 23, 2018
810ebad
Fetching data
delterr Mar 23, 2018
95443bb
Merge remote-tracking branch 'origin/master'
delterr Mar 23, 2018
367a400
Merge pull request #1 from discord-python/master
delterr Mar 24, 2018
502abb9
Added random snake
delterr Mar 24, 2018
4e2c293
Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1
delterr Mar 24, 2018
ac46387
Merge remote-tracking branch 'origin/master'
delterr Mar 24, 2018
57d1394
wiki site now a member variable
Mar 24, 2018
2bcae58
fixed post-merge issues
Mar 24, 2018
3c7367b
combined imports
Mar 24, 2018
b1376c8
added 'wikipedia' to imports
Mar 24, 2018
6734b50
replace URL with string for wiki
Mar 24, 2018
090f14f
Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1
delterr Mar 24, 2018
b5c5402
Merge remote-tracking branch 'origin/master'
delterr Mar 24, 2018
fcaecfb
Added python message
delterr Mar 24, 2018
71bde19
Merge pull request #2 from discord-python/master
delterr Mar 24, 2018
018e523
Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1
delterr Mar 24, 2018
59fa010
Merge remote-tracking branch 'origin/master'
delterr Mar 24, 2018
8e5cf70
test
delterr Mar 24, 2018
e36ae9e
PEP 8 fix
delterr Mar 24, 2018
9f075e9
Updated snake name fetch
delterr Mar 24, 2018
e0db09f
Merge remote-tracking branch 'origin/master'
Mar 24, 2018
28f1154
Adding embeds
delterr Mar 24, 2018
2f16d10
Merge remote-tracking branch 'origin/master'
Mar 24, 2018
b63381e
removed some gentle hard-coding
Mar 24, 2018
33bddfc
updating embed
delterr Mar 24, 2018
a2eddb4
Merge remote-tracking branch 'origin/master'
delterr Mar 24, 2018
34864b5
begin working on snake
Mar 24, 2018
2ff9b48
on_message now appends full object
Mar 24, 2018
5a6932e
working message logger
Mar 24, 2018
6f04e37
snake maybe possible probably not?
Mar 24, 2018
ff7469d
Merge remote-tracking branch 'origin/master'
delterr Mar 25, 2018
2d5f3b6
Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1
delterr Mar 25, 2018
4765a23
update snakes.py
delterr Mar 25, 2018
aa5b3ed
update nakes.py
delterr Mar 25, 2018
9bbeb30
snake no tail complete
Mar 25, 2018
f448a4e
DNP: bug with logging
Mar 25, 2018
36933e4
apples and framework for tail
Mar 25, 2018
417d7a7
added lxml to pipfile
Mar 25, 2018
6a804bd
tuples/tail
Mar 25, 2018
ac7c08a
Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1
delterr Mar 25, 2018
996edba
Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1
delterr Mar 25, 2018
40efcaa
removed unused imports
Mar 25, 2018
56da195
Changed how much info is scraped from the table
delterr Mar 25, 2018
0c1c026
PEP8 fix
delterr Mar 25, 2018
989e5d1
you can die now:
Mar 25, 2018
adff2e6
Snake complete
Mar 25, 2018
4399dcb
PEP8 fix, typo fix, removed unnecessary comments
delterr Mar 25, 2018
8904bce
emogis
Mar 25, 2018
e0bf1cc
petty rage push
Mar 25, 2018
f03b98f
done stuff to changes
Mar 25, 2018
127051f
main loop breaks now all use Running
Mar 25, 2018
41b2ba4
added break to user inputs
Mar 25, 2018
a620972
removed black line
Mar 25, 2018
f811720
added blank line
Mar 25, 2018
5987a8a
re-ordered some imports
Mar 25, 2018
804af0a
re-ordered some imports
Mar 25, 2018
f87d75e
re-ordered some imports
Mar 25, 2018
42eae45
re-ordered some imports
Mar 25, 2018
0c83aaf
Update import order
Mar 25, 2018
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
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ __pycache__/
# Distribution / packaging
.Python
env/
.idea/
.env

Copy link
Copy Markdown
Contributor

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?

build/
develop-eggs/
dist/
Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ name = "pypi"
aiodns = "*"
aiohttp = "<2.3.0,>=2.0.0"
websockets = ">=4.0,<5.0"
"beautifulsoup4" = "*"
wikipedia = "*"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you're not using this, you should pipenv uninstall it.


[dev-packages]
"flake8" = "*"
Expand Down
39 changes: 38 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 119 additions & 4 deletions bot/cogs/snakes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# coding=utf-8
import logging
import logging, aiohttp, random, wikipedia

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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__)

Expand All @@ -11,8 +13,22 @@ class Snakes:
"""
Snake-related commands
"""
python_info = '''
Python (Programming Language)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should probably remove all these huge indents.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You also don't need the \ns in here. Those are taken from how you've formatted the string.

\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]:
Expand All @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 "None", which is annoying to check for.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Expand All @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 get_snek().


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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really fun idea. But maybe a little ambitious for you guys.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 wait_for_reactions() instead of a list of inputs?

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