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

Team 2 #18

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ name = "pypi"
[packages]
"72eb2aa" = {file = "https://github.com/Rapptz/discord.py/archive/rewrite.zip"}
aiodns = "*"
aiohttp = "<2.3.0,>=2.0.0"
websockets = ">=4.0,<5.0"
wikipedia = "*"
aiohttp = "*"

[dev-packages]
"flake8" = "*"
Expand Down
87 changes: 69 additions & 18 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
204 changes: 155 additions & 49 deletions bot/cogs/snakes.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,155 @@
# 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
import random
from typing import Any, Dict

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


log = logging.getLogger(__name__)

SNAKE_LIST = ['cobra', 'python', 'anaconda', 'viper', 'mamba', 'taipan', 'rattle', 'garter', 'cylindrophis',
'colubridae']


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

if name is None:
name = random.choice(SNAKE_LIST)

elif name.lower() == "python":
name = "Python(Programming Language)"

try:
text = wikipedia.summary(name, sentences=2)
except Exception as e:
text = wikipedia.summary(e.options[0], sentences=2)
return (name, text)

@command(name="get")
async def get(self, ctx: Context, name: str = None):

name, text = await self.get_snek(name)
for_image = ''
if name == "Python(Programming Language)":
for_image = 'https://raw.githubusercontent.com/discord-python/branding/master/logos/logo_full.png'
embed = Embed(title="Programming !!", color=0x00ff00)
embed.add_field(name=name, value=text)
embed.set_image(url=for_image)
await ctx.send(embed=embed)
else:
webpage = wikipedia.WikipediaPage(name)
for_image = webpage.images[0]
embed = Embed(title="Snake !!", color=0x00ff00)
embed.add_field(name=name, value=text)
embed.set_image(url=for_image)
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 snake_random(self, ctx: Context, name: str = None):

randsnake = random.choice(SNAKE_LIST)
print(randsnake)
embed = 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":
return await ctx.send("You're a lucky dude ! ", embed=embed)
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") # this name generator randomply slics strings and joins them
async def Random_name(self, ctx: Context, name: str = None):

snk = random.choice(SNAKE_LIST)
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
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:]
embed = Embed(
title="Random Name",
description="You're that is generated is " + result,
color=0x00ff00
)
embed.add_field(name="Snake", value="Your name was merged with the snake " + snk)
return await ctx.send(embed=embed)

@command(name="namegen") # this name generator looks at vowels
async def name_generator(self, ctx: Context, name: str = None):
snk = random.choice(SNAKE_LIST)
s = name
str1 = ""
str2 = ""
for i in s:
str1 = i + str1

index2 = 0
index1 = 0
for index, char in enumerate(str1):
if char in 'aeiou':
index1 = index
break

name_index = len(s) - index1

name_sub_string = s[:name_index - 1]

snake = snk
for i in snake:
str2 = i + str2

for index, char in enumerate(str2):
if char in 'aeiou':
index2 = index
break

sub_string_index = len(snake) - index2
snake_sub_string = snake[1:sub_string_index]
result = name_sub_string + snake_sub_string
embed = Embed(
title="NAME GENERATOR",
description="You're that is generated is " + result,
color=0x00ff00
)
embed.add_field(name="Snake", value="Your name was merged with the snake " + snake)

return await ctx.send(embed=embed)


def setup(bot):
bot.add_cog(Snakes(bot))
log.info("Cog loaded: Snakes")
1 change: 0 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os

from aiohttp import AsyncResolver, ClientSession, TCPConnector

from discord import Game
from discord.ext.commands import AutoShardedBot, when_mentioned_or

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
max-line-length=120
application_import_names=bot
exclude=.venv
import-order-style=pep8
ignore=B311,W503,E226