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 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7331dc5
added welcome msg
RohanJnr Mar 23, 2018
387b504
Add files via upload
Mar 23, 2018
bcf2211
Update snakes.py
Mar 23, 2018
82cfd2f
added more cmds
RohanJnr Mar 23, 2018
ca5cd02
modified snakerandom
RohanJnr Mar 23, 2018
6884ba5
edited get
RohanJnr Mar 24, 2018
f66327c
adding random name
RohanJnr Mar 24, 2018
d941e7e
randname
RohanJnr Mar 24, 2018
476836c
make get() simpler
RohanJnr Mar 24, 2018
1b9cf13
added wikipedia
RohanJnr Mar 24, 2018
6bc6636
wiki
RohanJnr Mar 24, 2018
1a033f4
edited randname
RohanJnr Mar 24, 2018
058cef2
some editing
RohanJnr Mar 24, 2018
04fe132
editing
RohanJnr Mar 25, 2018
9440cb1
adding another random name with better code
RohanJnr Mar 25, 2018
4a18eae
get command
LaVieEstDure Mar 25, 2018
8045186
commiting
RohanJnr Mar 25, 2018
cf67fd5
Merge branch 'Iceman' of https://github.com/RohanJnr/code-jam-1 into …
RohanJnr Mar 25, 2018
3ef6e5e
removed
RohanJnr Mar 25, 2018
aa2a625
added python pic
RohanJnr Mar 25, 2018
6a0c1ed
removed some spaces
RohanJnr Mar 25, 2018
376547e
final submit
RohanJnr Mar 25, 2018
3d1bfba
reformatted
RohanJnr Mar 25, 2018
79fbb86
final editing done !!!
RohanJnr Mar 25, 2018
c4975fa
format
RohanJnr Mar 25, 2018
c0b5b96
format according to travis
RohanJnr Mar 25, 2018
a0154b7
formatting
RohanJnr Mar 25, 2018
530d761
added to txi
RohanJnr Mar 25, 2018
a5e5f22
hopefully the format,plz travis
RohanJnr Mar 25, 2018
3029f28
Merge branch 'master' into Iceman
RohanJnr Mar 25, 2018
f8b0862
FINAL FORMAT
RohanJnr Mar 25, 2018
35636f9
Merge branch 'Iceman' of https://github.com/RohanJnr/code-jam-1 into …
RohanJnr 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
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"
wikipedia = "*"
wikiapi = "*"
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.

Are you guys using these modules? If not, please pipenv uninstall them.


[dev-packages]
"flake8" = "*"
Expand Down
113 changes: 109 additions & 4 deletions Pipfile.lock

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

1 change: 1 addition & 0 deletions bot/cogs/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding=utf-8
import logging


from discord.ext.commands import AutoShardedBot

log = logging.getLogger(__name__)
Expand Down
155 changes: 106 additions & 49 deletions bot/cogs/snakes.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,106 @@
# coding=utf-8
import logging
from typing import Any, Dict

from discord.ext.commands import AutoShardedBot, Context, command

log = logging.getLogger(__name__)


class Snakes:
"""
Snake-related commands
"""

def __init__(self, bot: AutoShardedBot):
self.bot = bot

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

# Any additional commands can be placed here. Be creative, but keep it to a reasonable amount!


def setup(bot):
bot.add_cog(Snakes(bot))
log.info("Cog loaded: Snakes")
# coding=utf-8
import logging
from typing import Any, Dict
import random
import wikipedia
import aiohttp
import requests
import discord
from discord.ext.commands import AutoShardedBot, Context, command

log = logging.getLogger(__name__)


class Snakes:
"""
Snake-related commands
"""

def __init__(self, bot: AutoShardedBot):
self.bot = bot

async def get_snek(self, name: str = None) -> Dict[str, Any]:

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.

Extra space here that should be removed

"""
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(name="get")
async def get(self, ctx: Context):#, name: str = None):

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.

Data retrieval needs to be in the get_snek() method.

async with aiohttp.ClientSession() as session:
async with session.get('https://en.wikipedia.org/wiki/Cobra') as resp:
return await ctx.send(yield from resp.text)
#return await resp.()
#r = yield from aiohttp.request('get', 'http://python.org')
#raw = yield from r.text()

#print(raw)

"""if name.lower() == "python":
name_rechange = "Python Programming Language"
else:
name_rechange = name
test = wikipedia.page(name_rechange)

embed = discord.Embed(
title=test.title,
description=wikipedia.summary(name_rechange, sentences=1),
color=0x00ff00,
)
embed.add_field(name="Image", value=test.images[0], inline=False)
return await ctx.send(embed=embed)
"""

# Any additional commands can be placed here. Be creative, but keep it to a reasonable amount!

@command(name="snakerandom")
async def SnakeRandom(self, ctx: Context, name: str = None):
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 need to be using snake_case for the function name here.

# snakes=['Cobra','Python','Anaconda','Black Mamba','Rattle Snake']
randsnake = random.choice(['cobra', 'python', 'black mamba'])
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.

Could do with a few more snakes :P

print(randsnake)
embed = discord.Embed(
title="Snake Random !",
description="lets see what snake you got !",
color=0x00ff00,
)

embed.add_field(name="Result", value="You got yourself a " + randsnake, inline=False)
embed.add_field(name="Expectation", value=f"@{ctx.author} expected {name}", inline=False)

if randsnake == "python":

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.

Extra blank line here, should be removed

return await ctx.send("Your a lucky dude !", embed=embed)
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're

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.

Also, extra space before the ! should be removed

elif randsnake == "cobra":
return await ctx.send("Good old cobra !", embed=embed)
elif randsnake.startswith("blac"):
return await ctx.send("Shiny liitle fella !", embed=embed)

@command(name="randname")
async def RandName(self, ctx: Context, name: str = None):
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.

Should use snake_case here


snk = random.choice(['Cobra', 'Python', 'Anaconda', 'Viper', 'Mamba'])
snLen = len(snk)
p = len(name)
result = ""
front_back = 1
if front_back == 1: # so the users name is substring from the front and snake random substring from back
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.

Would be clearer with a blank line above this

ran = random.randint(1, p - 2)
ranSnk = random.randint(1, snLen - 1)
result = name[:ran] + snk[ranSnk:]

return await ctx.send(result)


def setup(bot):
bot.add_cog(Snakes(bot))
log.info("Cog loaded: Snakes")