diff --git a/Pipfile b/Pipfile index 096fb9b3..10c6fd56 100644 --- a/Pipfile +++ b/Pipfile @@ -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" = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 4e5214bb..6e1fabdf 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d797e580ddcddc99bf058109ab0306ad584c2902752a3d4076ba713fdc580fb7" + "sha256": "71337d959acc1cf7725dabf5b49701da64e6482aa69261394f29b1fd233575b4" }, "pipfile-spec": 6, "requires": { @@ -29,22 +29,24 @@ }, "aiohttp": { "hashes": [ - "sha256:129d83dd067760cec3cfd4456b5c6d7ac29f2c639d856884568fd539bed5a51f", - "sha256:33c62afd115c456b0cf1e890fe6753055effe0f31a28321efd4f787378d6f4ab", - "sha256:666756e1d4cf161ed1486b82f65fdd386ac07dd20fb10f025abf4be54be12746", - "sha256:9705ded5a0faa25c8f14c6afb7044002d66c9120ed7eadb4aa9ca4aad32bd00c", - "sha256:af5bfdd164256118a0a306b3f7046e63207d1f8cba73a67dcc0bd858dcfcd3bc", - "sha256:b80f44b99fa3c9b4530fcfa324a99b84843043c35b084e0b653566049974435d", - "sha256:c67e105ec74b85c8cb666b6877569dee6f55b9548f982983b9bee80b3d47e6f3", - "sha256:d15c6658de5b7783c2538407278fa062b079a46d5f814a133ae0f09bbb2cfbc4", - "sha256:d611ebd1ef48498210b65486306e065fde031040a1f3c455ca1b6baa7bf32ad3", - "sha256:dcc7e4dcec6b0012537b9f8a0726f8b111188894ab0f924b680d40b13d3298a0", - "sha256:de8ef106e130b94ca143fdfc6f27cda1d8ba439462542377738af4d99d9f5dd2", - "sha256:eb6f1405b607fff7e44168e3ceb5d3c8a8c5a2d3effe0a27f843b16ec047a6d7", - "sha256:f0e2ac69cb709367400008cebccd5d48161dd146096a009a632a132babe5714c" + "sha256:04ec521058055b2501b5c31419c8bd6212e10785653834838981fcd234402364", + "sha256:3f197bcdc0a801ecfa48d2ed0a0a49842668da1cbec25745cf65da68f7e62069", + "sha256:44373fee917bafe243aed7e4831eface7fa10dd54f7205f091d22c3bc6ae95e9", + "sha256:4f94b2b9e70a2e91e7ba2caf05c21251741af9db9c837e5ec874042bef34879a", + "sha256:73beb2efcce172af584ba233c4448f6860947aa81a4db8867bb8211124859777", + "sha256:7e74f2f0c5c8c9da14ffd224dbdcef0b315201e3986f5b9961ea30f6d1754b1f", + "sha256:8d87c610dc8c762e2f9e5fbe127fd0e0e850cf36141db939788558a225596506", + "sha256:8fe4cb34b734377d1e64070a7eea50a3776dd9478f91722f4dbb1a57ff9e6d99", + "sha256:9c68046dd6f986619942149b87e13e6be5272fbcb268d791dc8f2015eb9e30cc", + "sha256:a66c36fd969336278ccb8398c891e268e9fb2ee9e5866433fa4e0b7436d747e7", + "sha256:b27f5f1d93dc05e25b3dc315ab76c7bd106fd0d58d4bb7ed0256e3a538300e65", + "sha256:b99c8286770bbec5f226786d453a4e5602a052843f0865735b22ac6be5c20972", + "sha256:c0c12ca08d97e5a19a4e65573eaee70d3d371f2f1a8059e5229684d3eef1d10c", + "sha256:d69ead4d1a9ad02c4164cb3ff75b6e95793540517f9085430d25d521f50bcd1c", + "sha256:feb57395cacf87cc4b621d4b4cf8eb2dfb0dc97b47e7443d2b3349dff4c3769e" ], "index": "pypi", - "version": "==2.2.5" + "version": "==3.1.0" }, "async-timeout": { "hashes": [ @@ -53,6 +55,28 @@ ], "version": "==2.0.1" }, + "attrs": { + "hashes": [ + "sha256:1c7960ccfd6a005cd9f7ba884e6316b5e430a3f1a6c37c5f87d8b43f83b54ec9", + "sha256:a17a9573a6f475c99b551c0e0a812707ddda1ec9653bed04c13841404ed6f450" + ], + "version": "==17.4.0" + }, + "beautifulsoup4": { + "hashes": [ + "sha256:11a9a27b7d3bddc6d86f59fb76afb70e921a25ac2d6cc55b40d072bd68435a76", + "sha256:7015e76bf32f1f574636c4288399a6de66ce08fb7b2457f628a8d70c0fbabb11", + "sha256:808b6ac932dccb0a4126558f7dfdcf41710dd44a4ef497a0bb59a77f9f078e89" + ], + "version": "==4.6.0" + }, + "certifi": { + "hashes": [ + "sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296", + "sha256:edbc3f203427eef571f79a7692bb160a2b0f7ccaa31953e99bd17e307cf63f7d" + ], + "version": "==2018.1.18" + }, "chardet": { "hashes": [ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", @@ -67,6 +91,12 @@ ], "version": "==2.6" }, + "idna-ssl": { + "hashes": [ + "sha256:1293f030bc608e9aa9cdee72aa93c1521bbb9c7698068c61c9ada6772162b979" + ], + "version": "==1.0.1" + }, "multidict": { "hashes": [ "sha256:0462372fc74e4c061335118a4a5992b9a618d6c584b028ef03cf3e9b88a960e2", @@ -120,6 +150,20 @@ ], "version": "==2.3.0" }, + "requests": { + "hashes": [ + "sha256:6a1b267aa90cac58ac3a765d067950e7dbbf75b1da07e895d1f594193a40a38b", + "sha256:9c443e7324ba5b85070c4a818ade28bfabedf16ea10206da1132edaa6dda237e" + ], + "version": "==2.18.4" + }, + "urllib3": { + "hashes": [ + "sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b", + "sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f" + ], + "version": "==1.22" + }, "websockets": { "hashes": [ "sha256:0c31bc832d529dc7583d324eb6c836a4f362032a1902723c112cf57883488d8c", @@ -142,6 +186,13 @@ "index": "pypi", "version": "==4.0.1" }, + "wikipedia": { + "hashes": [ + "sha256:db0fad1829fdd441b1852306e9856398204dc0786d2996dd2e0c8bb8e26133b2" + ], + "index": "pypi", + "version": "==1.4.0" + }, "yarl": { "hashes": [ "sha256:045dbba18c9142278113d5dc62622978a6f718ba662392d406141c59b540c514", @@ -282,10 +333,10 @@ }, "gitpython": { "hashes": [ - "sha256:ad61bc25deadb535b047684d06f3654c001d9415e1971e51c9c20f5b510076e9", - "sha256:b8367c432de995dc330b5b146c5bfdc0926b8496e100fda6692134e00c0dcdc5" + "sha256:05069e26177c650b3cb945dd543a7ef7ca449f8db5b73038b465105673c1ef61", + "sha256:c47cc31af6e88979c57a33962cbc30a7c25508d74a1b3a19ec5aa7ed64b03129" ], - "version": "==2.1.8" + "version": "==2.1.9" }, "idna": { "hashes": [ diff --git a/bot/cogs/logging.py b/bot/cogs/logging.py index 5f5cd85c..62566663 100644 --- a/bot/cogs/logging.py +++ b/bot/cogs/logging.py @@ -1,6 +1,7 @@ # coding=utf-8 import logging + from discord.ext.commands import AutoShardedBot log = logging.getLogger(__name__) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index c9ed8042..3f4e669f 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -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 + 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") diff --git a/run.py b/run.py index 2ec711fd..22edf4f2 100644 --- a/run.py +++ b/run.py @@ -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 diff --git a/tox.ini b/tox.ini index c9de86ca..c617f486 100644 --- a/tox.ini +++ b/tox.ini @@ -2,4 +2,6 @@ max-line-length=120 application_import_names=bot exclude=.venv +import-order-style=pep8 ignore=B311,W503,E226 +