-
-
Notifications
You must be signed in to change notification settings - Fork 16
Team 2 #18
base: master
Are you sure you want to change the base?
Team 2 #18
Changes from 14 commits
7331dc5
387b504
bcf2211
82cfd2f
ca5cd02
6884ba5
f66327c
d941e7e
476836c
1b9cf13
6bc6636
1a033f4
058cef2
04fe132
9440cb1
4a18eae
8045186
cf67fd5
3ef6e5e
aa2a625
6a0c1ed
376547e
3d1bfba
79fbb86
c4975fa
c0b5b96
a0154b7
530d761
a5e5f22
3029f28
f8b0862
35636f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,6 +1,7 @@ | ||
| # coding=utf-8 | ||
| import logging | ||
|
|
||
|
|
||
| from discord.ext.commands import AutoShardedBot | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
| 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]: | ||
|
|
||
|
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. 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): | ||
|
|
||
|
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. Data retrieval needs to be in the |
||
| 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): | ||
|
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 need to be using |
||
| # snakes=['Cobra','Python','Anaconda','Black Mamba','Rattle Snake'] | ||
| randsnake = random.choice(['cobra', 'python', 'black mamba']) | ||
|
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. 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": | ||
|
|
||
|
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. Extra blank line here, should be removed |
||
| return await ctx.send("Your a lucky dude !", embed=embed) | ||
|
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.
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. Also, extra space before the |
||
| 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): | ||
|
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. Should use |
||
|
|
||
| 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 | ||
|
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. 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") | ||
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.
Are you guys using these modules? If not, please
pipenv uninstallthem.