This repository was archived by the owner on Mar 14, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 2 #18
Open
RohanJnr
wants to merge
32
commits into
python-discord:master
Choose a base branch
from
RohanJnr:Iceman
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Team 2 #18
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
7331dc5
added welcome msg
RohanJnr 387b504
Add files via upload
bcf2211
Update snakes.py
82cfd2f
added more cmds
RohanJnr ca5cd02
modified snakerandom
RohanJnr 6884ba5
edited get
RohanJnr f66327c
adding random name
RohanJnr d941e7e
randname
RohanJnr 476836c
make get() simpler
RohanJnr 1b9cf13
added wikipedia
RohanJnr 6bc6636
wiki
RohanJnr 1a033f4
edited randname
RohanJnr 058cef2
some editing
RohanJnr 04fe132
editing
RohanJnr 9440cb1
adding another random name with better code
RohanJnr 4a18eae
get command
LaVieEstDure 8045186
commiting
RohanJnr cf67fd5
Merge branch 'Iceman' of https://github.com/RohanJnr/code-jam-1 into …
RohanJnr 3ef6e5e
removed
RohanJnr aa2a625
added python pic
RohanJnr 6a0c1ed
removed some spaces
RohanJnr 376547e
final submit
RohanJnr 3d1bfba
reformatted
RohanJnr 79fbb86
final editing done !!!
RohanJnr c4975fa
format
RohanJnr c0b5b96
format according to travis
RohanJnr a0154b7
formatting
RohanJnr 530d761
added to txi
RohanJnr a5e5f22
hopefully the format,plz travis
RohanJnr 3029f28
Merge branch 'master' into Iceman
RohanJnr f8b0862
FINAL FORMAT
RohanJnr 35636f9
Merge branch 'Iceman' of https://github.com/RohanJnr/code-jam-1 into …
RohanJnr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: | ||
|
||
""" | ||
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 | ||
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. 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
max-line-length=120 | ||
application_import_names=bot | ||
exclude=.venv | ||
import-order-style=pep8 | ||
ignore=B311,W503,E226 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Extra space here that should be removed