From 4c998004441fd9c6c9bcaef7139976358ce70532 Mon Sep 17 00:00:00 2001 From: Hasan Date: Fri, 23 Mar 2018 06:15:01 +0000 Subject: [PATCH 01/58] first commit --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 1 + bot/cogs/snakes.py | 6 +++++- 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..215681ec687b156bfe407af3ed68748b0ce8abfa GIT binary patch literal 6148 zcmeHK%T59@6g?M+Ky<-Qm$P(5;@ZuKupm)mvZ*qJ3IH%K|Nv2Z((p$}rfDV8bQ?b@&@kQvk=2p}~j}D5?QBEgCIblnuv-k@R z=)0?9f)dMN5xu`-jvRita2u&(M%FZ8y(O$B&M?F&2DrcogP1M*TkK2BvA`|M0yhc! zC1LL&Vxvn9SA@Gn_nzq5xZ-+F(8oEki+jvsMeRCK?BEeAJdnGQwYuBTd=72e14y+x}??c8^%mY>)-KT?vy8;j! z>~_Jr`}rqk+Cj_%Rvy{I5HBTqse~(rgu8=yImh$BuRMA=#66kwgeOb5p-8xTNapB} z+@qD|fH@F5Q1{J_p8tdI@BgvLTIPT`@UI+@Mt{`raZBNB-P)X Dict[str, Any]: :return: A dict containing information on a snake """ + + + @command() async def get(self, ctx: Context, name: str = None): """ @@ -41,6 +44,7 @@ async def get(self, ctx: Context, name: str = None): :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! From 7ed1c2a6fe4ce980580c5965b9760716462c3c4f Mon Sep 17 00:00:00 2001 From: Hasan Date: Fri, 23 Mar 2018 07:58:41 +0000 Subject: [PATCH 02/58] Added temp code for bot.get --- Pipfile | 3 + Pipfile.lock | 139 ++++++++++++++++++++++++++++++++++++++++++++- bot/cogs/snakes.py | 6 +- 3 files changed, 146 insertions(+), 2 deletions(-) diff --git a/Pipfile b/Pipfile index 096fb9b3..fa67ef41 100644 --- a/Pipfile +++ b/Pipfile @@ -8,6 +8,9 @@ name = "pypi" aiodns = "*" aiohttp = "<2.3.0,>=2.0.0" websockets = ">=4.0,<5.0" +"beautifulsoup4" = "*" +requests-html = "*" +wikipedia = "*" [dev-packages] "flake8" = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 4e5214bb..11f54062 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d797e580ddcddc99bf058109ab0306ad584c2902752a3d4076ba713fdc580fb7" + "sha256": "3e4dd739b9ddb6bbc18598d29b1fd2288a186aaf15b41f08d2f2adab30af0ab7" }, "pipfile-spec": 6, "requires": { @@ -53,6 +53,28 @@ ], "version": "==2.0.1" }, + "beautifulsoup4": { + "hashes": [ + "sha256:11a9a27b7d3bddc6d86f59fb76afb70e921a25ac2d6cc55b40d072bd68435a76", + "sha256:7015e76bf32f1f574636c4288399a6de66ce08fb7b2457f628a8d70c0fbabb11", + "sha256:808b6ac932dccb0a4126558f7dfdcf41710dd44a4ef497a0bb59a77f9f078e89" + ], + "index": "pypi", + "version": "==4.6.0" + }, + "bs4": { + "hashes": [ + "sha256:36ecea1fd7cc5c0c6e4a1ff075df26d50da647b75376626cc186e2212886dd3a" + ], + "version": "==0.0.1" + }, + "certifi": { + "hashes": [ + "sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296", + "sha256:edbc3f203427eef571f79a7692bb160a2b0f7ccaa31953e99bd17e307cf63f7d" + ], + "version": "==2018.1.18" + }, "chardet": { "hashes": [ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", @@ -60,6 +82,19 @@ ], "version": "==3.0.4" }, + "cssselect": { + "hashes": [ + "sha256:066d8bc5229af09617e24b3ca4d52f1f9092d9e061931f4184cd572885c23204", + "sha256:3b5103e8789da9e936a68d993b70df732d06b8bb9a337a05ed4eb52c17ef7206" + ], + "version": "==1.0.3" + }, + "fake-useragent": { + "hashes": [ + "sha256:cc9b9ddcebc708b3deac846f5fccb16e37c02ee47435a4ec7132271dd96aec8c" + ], + "version": "==0.1.10" + }, "idna": { "hashes": [ "sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f", @@ -67,6 +102,39 @@ ], "version": "==2.6" }, + "lxml": { + "hashes": [ + "sha256:01c45df6d90497c20aa2a07789a41941f9a1029faa30bf725fc7f6d515b1afe9", + "sha256:0c9fef4f8d444e337df96c54544aeb85b7215b2ed7483bb6c35de97ac99f1bcd", + "sha256:0e3cd94c95d30ba9ca3cff40e9b2a14e1a10a4fd8131105b86c6b61648f57e4b", + "sha256:0e7996e9b46b4d8b4ac1c329a00e2d10edcd8380b95d2a676fccabf4c1dd0512", + "sha256:1858b1933d483ec5727549d3fe166eeb54229fbd6a9d3d7ea26d2c8a28048058", + "sha256:1b164bba1320b14905dcff77da10d5ce9c411ac4acc4fb4ed9a2a4d10fae38c9", + "sha256:1b46f37927fa6cd1f3fe34b54f1a23bd5bea1d905657289e08e1297069a1a597", + "sha256:231047b05907315ae9a9b6925751f9fd2c479cf7b100fff62485a25e382ca0d4", + "sha256:28f0c6652c1b130f1e576b60532f84b19379485eb8da6185c29bd8c9c9bc97bf", + "sha256:34d49d0f72dd82b9530322c48b70ac78cca0911275da741c3b1d2f3603c5f295", + "sha256:3682a17fbf72d56d7e46db2e80ca23850b79c28cfe75dcd9b82f58808f730909", + "sha256:3cf2830b9a6ad7f6e965fa53a768d4d2372a7856f20ffa6ce43d2fe9c0d34b19", + "sha256:5b653c9379ce29ce271fbe1010c5396670f018e78b643e21beefbb3dc6d291de", + "sha256:65a272821d5d8194358d6b46f3ca727fa56a6b63981606eac737c86d27309cdd", + "sha256:691f2cd97cf026c611df1ea5055755eec7f878f2d4f4330dc8686583de6fc5fd", + "sha256:6b6379495d3baacf7ed755ac68547c8dff6ce5d37bf370f0b7678888dc1283f9", + "sha256:75322a531504d4f383264391d89993a42e286da8821ddc5ac315e57305cb84f0", + "sha256:7f457cbda964257f443bac861d3a36732dcba8183149e7818ee2fb7c86901b94", + "sha256:7ff1fc76d8804e0f870c343a72007ff587090c218b0f92d8ee784ac2b6eaf5b9", + "sha256:8523fbde9c2216f3f2b950cb01ebe52e785eaa8a07ffeb456dd3576ca1b4fb9b", + "sha256:8f37627f16e026523fca326f1b5c9a43534862fede6c3e99c2ba6a776d75c1ab", + "sha256:a7182ea298cc3555ea56ffbb0748fe0d5e0d81451e2bc16d7f4645cd01b1ca70", + "sha256:abbd2fb4a5a04c11b5e04eb146659a0cf67bb237dd3d7ca3b9994d3a9f826e55", + "sha256:accc9f6b77bed0a6f267b4fae120f6008a951193d548cdbe9b61fc98a08b1cf8", + "sha256:bd88c8ce0d1504fdfd96a35911dd4f3edfb2e560d7cfdb5a3d09aa571ae5fbae", + "sha256:c557ad647facb3c0027a9d0af58853f905e85a0a2f04dcb73f8e665272fcdc3a", + "sha256:defabb7fbb99f9f7b3e0b24b286a46855caef4776495211b066e9e6592d12b04", + "sha256:e2629cdbcad82b83922a3488937632a4983ecc0fed3e5cfbf430d069382eeb9b" + ], + "version": "==4.2.1" + }, "multidict": { "hashes": [ "sha256:0462372fc74e4c061335118a4a5992b9a618d6c584b028ef03cf3e9b88a960e2", @@ -94,6 +162,12 @@ ], "version": "==4.1.0" }, + "parse": { + "hashes": [ + "sha256:8048dde3f5ca07ad7ac7350460952d83b63eaacecdac1b37f45fd74870d849d2" + ], + "version": "==1.8.2" + }, "pycares": { "hashes": [ "sha256:0e81c971236bb0767354f1456e67ab6ae305f248565ce77cd413a311f9572bf5", @@ -120,6 +194,62 @@ ], "version": "==2.3.0" }, + "pyee": { + "hashes": [ + "sha256:47f8fa96d6dee61c82001831e1fbba55f3f808003a322d0e6653aa01c59f6b9e", + "sha256:4ec22817297b7024f89721cc34f790ee2767c5b5ca44284c565ee643abafbe32" + ], + "version": "==5.0.0" + }, + "pyppeteer": { + "hashes": [ + "sha256:caedc32a9067df9f22370deb89d6167b9d63ae97adcff0c9cdd9c4d3c2f8b09e" + ], + "version": "==0.0.16" + }, + "pyquery": { + "hashes": [ + "sha256:07987c2ed2aed5cba29ff18af95e56e9eb04a2249f42ce47bddfb37f487229a3", + "sha256:4771db76bd14352eba006463656aef990a0147a0eeaf094725097acfa90442bf" + ], + "version": "==1.4.0" + }, + "requests": { + "hashes": [ + "sha256:6a1b267aa90cac58ac3a765d067950e7dbbf75b1da07e895d1f594193a40a38b", + "sha256:9c443e7324ba5b85070c4a818ade28bfabedf16ea10206da1132edaa6dda237e" + ], + "version": "==2.18.4" + }, + "requests-html": { + "hashes": [ + "sha256:34257d5249b20b8ed14573eba910f48032a61205e70d11ce8a3ef6abf8edc50b", + "sha256:9686f21c5753ba6c025c6ba223a8329c7b149a935a73055097faf8999eee85b1" + ], + "index": "pypi", + "version": "==0.9.0" + }, + "six": { + "hashes": [ + "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", + "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" + ], + "version": "==1.11.0" + }, + "urllib3": { + "hashes": [ + "sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b", + "sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f" + ], + "version": "==1.22" + }, + "w3lib": { + "hashes": [ + "sha256:55994787e93b411c2d659068b51b9998d9d0c05e0df188e6daf8f45836e1ea38", + "sha256:aaf7362464532b1036ab0092e2eee78e8fd7b56787baa9ed4967457b083d011b" + ], + "version": "==1.19.0" + }, "websockets": { "hashes": [ "sha256:0c31bc832d529dc7583d324eb6c836a4f362032a1902723c112cf57883488d8c", @@ -142,6 +272,13 @@ "index": "pypi", "version": "==4.0.1" }, + "wikipedia": { + "hashes": [ + "sha256:db0fad1829fdd441b1852306e9856398204dc0786d2996dd2e0c8bb8e26133b2" + ], + "index": "pypi", + "version": "==1.4.0" + }, "yarl": { "hashes": [ "sha256:045dbba18c9142278113d5dc62622978a6f718ba662392d406141c59b540c514", diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 11af00d7..d19abce6 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,9 +1,10 @@ # coding=utf-8 import logging from typing import Any, Dict -import discord +import wikipedia from discord.ext.commands import AutoShardedBot, Context, command + log = logging.getLogger(__name__) @@ -28,6 +29,8 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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 """ + snake_summary = wikipedia.sumamry(self.name) + @@ -43,6 +46,7 @@ async def get(self, ctx: Context, name: str = None): :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 """ + await ctx.send("hello") # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 020deb764fdb1e57d6543580e5df2e6624b104f4 Mon Sep 17 00:00:00 2001 From: Hasan Date: Fri, 23 Mar 2018 15:48:51 +0000 Subject: [PATCH 03/58] Updated pipfile/pipfile.lock --- Pipfile | 1 - Pipfile.lock | 102 +-------------------------------------------- bot/cogs/snakes.py | 9 +--- 3 files changed, 2 insertions(+), 110 deletions(-) diff --git a/Pipfile b/Pipfile index fa67ef41..c10c94db 100644 --- a/Pipfile +++ b/Pipfile @@ -9,7 +9,6 @@ aiodns = "*" aiohttp = "<2.3.0,>=2.0.0" websockets = ">=4.0,<5.0" "beautifulsoup4" = "*" -requests-html = "*" wikipedia = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 11f54062..7ced31d2 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "3e4dd739b9ddb6bbc18598d29b1fd2288a186aaf15b41f08d2f2adab30af0ab7" + "sha256": "89800ac602d63f956f05d7ce2df2166152ca722cab1aa564dfffd849c9d8c1bb" }, "pipfile-spec": 6, "requires": { @@ -62,12 +62,6 @@ "index": "pypi", "version": "==4.6.0" }, - "bs4": { - "hashes": [ - "sha256:36ecea1fd7cc5c0c6e4a1ff075df26d50da647b75376626cc186e2212886dd3a" - ], - "version": "==0.0.1" - }, "certifi": { "hashes": [ "sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296", @@ -82,19 +76,6 @@ ], "version": "==3.0.4" }, - "cssselect": { - "hashes": [ - "sha256:066d8bc5229af09617e24b3ca4d52f1f9092d9e061931f4184cd572885c23204", - "sha256:3b5103e8789da9e936a68d993b70df732d06b8bb9a337a05ed4eb52c17ef7206" - ], - "version": "==1.0.3" - }, - "fake-useragent": { - "hashes": [ - "sha256:cc9b9ddcebc708b3deac846f5fccb16e37c02ee47435a4ec7132271dd96aec8c" - ], - "version": "==0.1.10" - }, "idna": { "hashes": [ "sha256:2c6a5de3089009e3da7c5dde64a141dbc8551d5b7f6cf4ed7c2568d0cc520a8f", @@ -102,39 +83,6 @@ ], "version": "==2.6" }, - "lxml": { - "hashes": [ - "sha256:01c45df6d90497c20aa2a07789a41941f9a1029faa30bf725fc7f6d515b1afe9", - "sha256:0c9fef4f8d444e337df96c54544aeb85b7215b2ed7483bb6c35de97ac99f1bcd", - "sha256:0e3cd94c95d30ba9ca3cff40e9b2a14e1a10a4fd8131105b86c6b61648f57e4b", - "sha256:0e7996e9b46b4d8b4ac1c329a00e2d10edcd8380b95d2a676fccabf4c1dd0512", - "sha256:1858b1933d483ec5727549d3fe166eeb54229fbd6a9d3d7ea26d2c8a28048058", - "sha256:1b164bba1320b14905dcff77da10d5ce9c411ac4acc4fb4ed9a2a4d10fae38c9", - "sha256:1b46f37927fa6cd1f3fe34b54f1a23bd5bea1d905657289e08e1297069a1a597", - "sha256:231047b05907315ae9a9b6925751f9fd2c479cf7b100fff62485a25e382ca0d4", - "sha256:28f0c6652c1b130f1e576b60532f84b19379485eb8da6185c29bd8c9c9bc97bf", - "sha256:34d49d0f72dd82b9530322c48b70ac78cca0911275da741c3b1d2f3603c5f295", - "sha256:3682a17fbf72d56d7e46db2e80ca23850b79c28cfe75dcd9b82f58808f730909", - "sha256:3cf2830b9a6ad7f6e965fa53a768d4d2372a7856f20ffa6ce43d2fe9c0d34b19", - "sha256:5b653c9379ce29ce271fbe1010c5396670f018e78b643e21beefbb3dc6d291de", - "sha256:65a272821d5d8194358d6b46f3ca727fa56a6b63981606eac737c86d27309cdd", - "sha256:691f2cd97cf026c611df1ea5055755eec7f878f2d4f4330dc8686583de6fc5fd", - "sha256:6b6379495d3baacf7ed755ac68547c8dff6ce5d37bf370f0b7678888dc1283f9", - "sha256:75322a531504d4f383264391d89993a42e286da8821ddc5ac315e57305cb84f0", - "sha256:7f457cbda964257f443bac861d3a36732dcba8183149e7818ee2fb7c86901b94", - "sha256:7ff1fc76d8804e0f870c343a72007ff587090c218b0f92d8ee784ac2b6eaf5b9", - "sha256:8523fbde9c2216f3f2b950cb01ebe52e785eaa8a07ffeb456dd3576ca1b4fb9b", - "sha256:8f37627f16e026523fca326f1b5c9a43534862fede6c3e99c2ba6a776d75c1ab", - "sha256:a7182ea298cc3555ea56ffbb0748fe0d5e0d81451e2bc16d7f4645cd01b1ca70", - "sha256:abbd2fb4a5a04c11b5e04eb146659a0cf67bb237dd3d7ca3b9994d3a9f826e55", - "sha256:accc9f6b77bed0a6f267b4fae120f6008a951193d548cdbe9b61fc98a08b1cf8", - "sha256:bd88c8ce0d1504fdfd96a35911dd4f3edfb2e560d7cfdb5a3d09aa571ae5fbae", - "sha256:c557ad647facb3c0027a9d0af58853f905e85a0a2f04dcb73f8e665272fcdc3a", - "sha256:defabb7fbb99f9f7b3e0b24b286a46855caef4776495211b066e9e6592d12b04", - "sha256:e2629cdbcad82b83922a3488937632a4983ecc0fed3e5cfbf430d069382eeb9b" - ], - "version": "==4.2.1" - }, "multidict": { "hashes": [ "sha256:0462372fc74e4c061335118a4a5992b9a618d6c584b028ef03cf3e9b88a960e2", @@ -162,12 +110,6 @@ ], "version": "==4.1.0" }, - "parse": { - "hashes": [ - "sha256:8048dde3f5ca07ad7ac7350460952d83b63eaacecdac1b37f45fd74870d849d2" - ], - "version": "==1.8.2" - }, "pycares": { "hashes": [ "sha256:0e81c971236bb0767354f1456e67ab6ae305f248565ce77cd413a311f9572bf5", @@ -194,26 +136,6 @@ ], "version": "==2.3.0" }, - "pyee": { - "hashes": [ - "sha256:47f8fa96d6dee61c82001831e1fbba55f3f808003a322d0e6653aa01c59f6b9e", - "sha256:4ec22817297b7024f89721cc34f790ee2767c5b5ca44284c565ee643abafbe32" - ], - "version": "==5.0.0" - }, - "pyppeteer": { - "hashes": [ - "sha256:caedc32a9067df9f22370deb89d6167b9d63ae97adcff0c9cdd9c4d3c2f8b09e" - ], - "version": "==0.0.16" - }, - "pyquery": { - "hashes": [ - "sha256:07987c2ed2aed5cba29ff18af95e56e9eb04a2249f42ce47bddfb37f487229a3", - "sha256:4771db76bd14352eba006463656aef990a0147a0eeaf094725097acfa90442bf" - ], - "version": "==1.4.0" - }, "requests": { "hashes": [ "sha256:6a1b267aa90cac58ac3a765d067950e7dbbf75b1da07e895d1f594193a40a38b", @@ -221,21 +143,6 @@ ], "version": "==2.18.4" }, - "requests-html": { - "hashes": [ - "sha256:34257d5249b20b8ed14573eba910f48032a61205e70d11ce8a3ef6abf8edc50b", - "sha256:9686f21c5753ba6c025c6ba223a8329c7b149a935a73055097faf8999eee85b1" - ], - "index": "pypi", - "version": "==0.9.0" - }, - "six": { - "hashes": [ - "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", - "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" - ], - "version": "==1.11.0" - }, "urllib3": { "hashes": [ "sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b", @@ -243,13 +150,6 @@ ], "version": "==1.22" }, - "w3lib": { - "hashes": [ - "sha256:55994787e93b411c2d659068b51b9998d9d0c05e0df188e6daf8f45836e1ea38", - "sha256:aaf7362464532b1036ab0092e2eee78e8fd7b56787baa9ed4967457b083d011b" - ], - "version": "==1.19.0" - }, "websockets": { "hashes": [ "sha256:0c31bc832d529dc7583d324eb6c836a4f362032a1902723c112cf57883488d8c", diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index d19abce6..61e65706 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,10 +1,8 @@ # coding=utf-8 import logging from typing import Any, Dict -import wikipedia from discord.ext.commands import AutoShardedBot, Context, command - log = logging.getLogger(__name__) @@ -29,11 +27,6 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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 """ - snake_summary = wikipedia.sumamry(self.name) - - - - @command() async def get(self, ctx: Context, name: str = None): @@ -49,7 +42,7 @@ async def get(self, ctx: Context, name: str = None): await ctx.send("hello") - # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! + # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! def setup(bot): From 968c748e3776f330d5f0336e51fea5897f4297d8 Mon Sep 17 00:00:00 2001 From: Hasan Date: Fri, 23 Mar 2018 17:07:56 +0000 Subject: [PATCH 04/58] adding temporary code that fetches wiki page on snakes --- bot/cogs/snakes.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 61e65706..e91a9006 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,5 +1,7 @@ # coding=utf-8 import logging +import aiohttp +from bs4 import BeautifulSoup from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command @@ -27,6 +29,8 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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): @@ -39,8 +43,10 @@ async def get(self, ctx: Context, name: str = None): :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 """ - await ctx.send("hello") - + async with aiohttp.ClientSession() as session: + async with session.get('https://en.wikipedia.org/wiki/List_of_snakes_by_common_name') as resp: + text = await resp.read() + await ctx.send(BeautifulSoup(text, 'lxml').find("title")) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 3011280c02745b56f1bc7d52918d358a59aa256a Mon Sep 17 00:00:00 2001 From: Hasan Date: Fri, 23 Mar 2018 21:08:42 +0000 Subject: [PATCH 05/58] added the fetch code to getsnek --- bot/cogs/snakes.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index e91a9006..d503f5f8 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -29,7 +29,11 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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 """ - + site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' + async with aiohttp.ClientSession() as session: + async with session.get(site) as resp: + text = await resp.read() + return text @command() @@ -43,10 +47,7 @@ async def get(self, ctx: Context, name: str = None): :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 """ - async with aiohttp.ClientSession() as session: - async with session.get('https://en.wikipedia.org/wiki/List_of_snakes_by_common_name') as resp: - text = await resp.read() - await ctx.send(BeautifulSoup(text, 'lxml').find("title")) + # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 1f6f87711dce18a4fec194ac13540d8fe95f3590 Mon Sep 17 00:00:00 2001 From: xedre Date: Fri, 23 Mar 2018 21:19:03 +0000 Subject: [PATCH 06/58] added .idea/ to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1ee4aa51..932ecf25 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ __pycache__/ # Distribution / packaging .Python env/ +.idea/ .env build/ develop-eggs/ From fb31d2b3a5911650e1fa3537187535148ca0a674 Mon Sep 17 00:00:00 2001 From: xedre Date: Fri, 23 Mar 2018 21:25:13 +0000 Subject: [PATCH 07/58] added get_snek() call to get() --- bot/cogs/snakes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index d503f5f8..f475f222 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -48,7 +48,7 @@ async def get(self, ctx: Context, name: str = None): :param name: Optional, the name of the snake to get information for - omit for a random snake """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) - + await message.channel.send(self.get_snek(name)) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From c8d42d3c2dd14a07da816ad24705d712935f4e47 Mon Sep 17 00:00:00 2001 From: xedre Date: Fri, 23 Mar 2018 21:30:00 +0000 Subject: [PATCH 08/58] replaced message.channel with ctx --- bot/cogs/snakes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index f475f222..9fab2773 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -48,7 +48,7 @@ async def get(self, ctx: Context, name: str = None): :param name: Optional, the name of the snake to get information for - omit for a random snake """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) - await message.channel.send(self.get_snek(name)) + await ctx.send(self.get_snek(name)) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From b8fdfd715dd1bb21c16da43ae3262406aa5bcec9 Mon Sep 17 00:00:00 2001 From: Hasan Date: Fri, 23 Mar 2018 21:30:55 +0000 Subject: [PATCH 09/58] Removed snake find --- bot/cogs/snakes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index d503f5f8..26950134 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -33,7 +33,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: async with aiohttp.ClientSession() as session: async with session.get(site) as resp: text = await resp.read() - return text + @command() From 810ebad8079854a680e7e2f94bf7127049c58f74 Mon Sep 17 00:00:00 2001 From: Hasan Date: Fri, 23 Mar 2018 21:36:24 +0000 Subject: [PATCH 10/58] Fetching data --- .gitignore | 1 + bot/cogs/snakes.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1ee4aa51..932ecf25 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ __pycache__/ # Distribution / packaging .Python env/ +.idea/ .env build/ develop-eggs/ diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 26950134..dee3beee 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -48,7 +48,7 @@ async def get(self, ctx: Context, name: str = None): :param name: Optional, the name of the snake to get information for - omit for a random snake """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) - + await ctx.send(self.get_snek(name)) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 502abb91f37c7eaabe3acd7a81e263d4cdd33f35 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 08:20:46 +0000 Subject: [PATCH 11/58] Added random snake --- bot/cogs/snakes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index dee3beee..f2d88e22 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,6 +1,7 @@ # coding=utf-8 import logging import aiohttp +import random from bs4 import BeautifulSoup from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command @@ -49,6 +50,7 @@ async def get(self, ctx: Context, name: str = None): """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) await ctx.send(self.get_snek(name)) + await ctx.send(random.choice(["snake1", "snake2", "snake3"])) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 4e2c293573901c9697019697e025e8fc06c133fe Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 08:23:18 +0000 Subject: [PATCH 12/58] Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1 # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit. Adding random snakes --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 028645b4..9797a5cc 100644 --- a/tox.ini +++ b/tox.ini @@ -2,3 +2,4 @@ max-line-length=120 application_import_names=bot exclude=.venv +ignore=B311 From 57d1394755fd21f8a29594b5c1d90c6ba5f27b5b Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 08:29:52 +0000 Subject: [PATCH 13/58] wiki site now a member variable --- bot/cogs/snakes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index f2d88e22..ad1c8cfd 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -16,6 +16,7 @@ class Snakes: def __init__(self, bot: AutoShardedBot): self.bot = bot + self.site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' async def get_snek(self, name: str = None) -> Dict[str, Any]: """ @@ -30,7 +31,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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 """ - site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' + async with aiohttp.ClientSession() as session: async with session.get(site) as resp: text = await resp.read() From 2bcae5889cb90346766947a8df01293223cdf083 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 08:31:05 +0000 Subject: [PATCH 14/58] fixed post-merge issues --- bot/cogs/snakes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index ad1c8cfd..ec17e320 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -33,7 +33,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: """ async with aiohttp.ClientSession() as session: - async with session.get(site) as resp: + async with session.get(self.site) as resp: text = await resp.read() From 3c7367b0d4554f9fcb74751ad4e8a9853fddd0b7 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 08:48:13 +0000 Subject: [PATCH 15/58] combined imports --- bot/cogs/snakes.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index ec17e320..930e390d 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,7 +1,5 @@ # coding=utf-8 -import logging -import aiohttp -import random +import logging, aiohttp, random from bs4 import BeautifulSoup from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command @@ -16,7 +14,7 @@ class Snakes: def __init__(self, bot: AutoShardedBot): self.bot = bot - self.site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' + self.site = wikipedia.page('https://en.wikipedia.org/wiki/List_of_snakes_by_common_name') async def get_snek(self, name: str = None) -> Dict[str, Any]: """ @@ -32,6 +30,9 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :return: A dict containing information on a snake """ + if name is None: + + async with aiohttp.ClientSession() as session: async with session.get(self.site) as resp: text = await resp.read() @@ -51,7 +52,6 @@ async def get(self, ctx: Context, name: str = None): """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) await ctx.send(self.get_snek(name)) - await ctx.send(random.choice(["snake1", "snake2", "snake3"])) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From b1376c8f1b54ebeca41784921dcbf1b6d98f4743 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 08:49:09 +0000 Subject: [PATCH 16/58] added 'wikipedia' to imports --- bot/cogs/snakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 930e390d..73356194 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,5 +1,5 @@ # coding=utf-8 -import logging, aiohttp, random +import logging, aiohttp, random, wikipedia from bs4 import BeautifulSoup from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command @@ -31,7 +31,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: """ if name is None: - + print(self.site) async with aiohttp.ClientSession() as session: async with session.get(self.site) as resp: From 6734b50e5158d6dd12bcb6d8f0d583a09e56eea3 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 08:51:20 +0000 Subject: [PATCH 17/58] replace URL with string for wiki --- bot/cogs/snakes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 73356194..a16176c1 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -14,7 +14,7 @@ class Snakes: def __init__(self, bot: AutoShardedBot): self.bot = bot - self.site = wikipedia.page('https://en.wikipedia.org/wiki/List_of_snakes_by_common_name') + self.site = wikipedia.page('List of snakes by common name') async def get_snek(self, name: str = None) -> Dict[str, Any]: """ From 090f14f5bab769c6be481933c6abdef79b2e99e1 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 11:09:58 +0000 Subject: [PATCH 18/58] Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1 Added Python bot message From fcaecfb293772e160772c7f8ec50a5990d2908e3 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 11:12:51 +0000 Subject: [PATCH 19/58] Added python message --- bot/cogs/snakes.py | 47 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index ec17e320..40a119fe 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -13,10 +13,23 @@ class Snakes: """ Snake-related commands """ + embed = {} + python_info = ''' + Python (Programming Language) + \n + Python is powerful... and fast;\n + plays well with others;\n + runs everywhere;\n + is friendly & easy to learn;\n + is Open. + ------------------------------- + Created by: Guido Van Rossum \n + Founded: 20th of February, 1991 \n + Official website: https://python.org + ''' def __init__(self, bot: AutoShardedBot): self.bot = bot - self.site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' async def get_snek(self, name: str = None) -> Dict[str, Any]: """ @@ -31,12 +44,32 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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 """ - + ''' + site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' async with aiohttp.ClientSession() as session: - async with session.get(self.site) as resp: + async with session.get(site) as resp: text = await resp.read() - - + snake = name + soup = BeautifulSoup(text, 'lxml') + soup.find(snake) + ''' + + if str(name).lower() == 'python': + ''' + Python (Programming Language) + \n + Python is powerful... and fast;\n + plays well with others;\n + runs everywhere;\n + is friendly & easy to learn;\n + is Open. + ------------------------------- + Created by: Guido Van Rossum \n + Founded: 20th of February, 1991 \n + Official website: https://python.org + ''' + name = self.python_info + return name @command() async def get(self, ctx: Context, name: str = None): @@ -50,8 +83,8 @@ async def get(self, ctx: Context, name: str = None): :param name: Optional, the name of the snake to get information for - omit for a random snake """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) - await ctx.send(self.get_snek(name)) - await ctx.send(random.choice(["snake1", "snake2", "snake3"])) + await ctx.send(await self.get_snek(name)) + # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 018e5235e14bca5377c79c4b806d37e82af638de Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 15:36:36 +0000 Subject: [PATCH 20/58] Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1 PEP 8 fix --- bot/cogs/snakes.py | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 40a119fe..cafe656e 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,9 +1,12 @@ # coding=utf-8 import logging +from typing import Any, Dict + import aiohttp -import random + + from bs4 import BeautifulSoup -from typing import Any, Dict + from discord.ext.commands import AutoShardedBot, Context, command log = logging.getLogger(__name__) @@ -13,7 +16,6 @@ class Snakes: """ Snake-related commands """ - embed = {} python_info = ''' Python (Programming Language) \n @@ -23,7 +25,7 @@ class Snakes: is friendly & easy to learn;\n is Open. ------------------------------- - Created by: Guido Van Rossum \n + Created by: Guido Van Rossum \n Founded: 20th of February, 1991 \n Official website: https://python.org ''' @@ -44,31 +46,19 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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 """ - ''' + site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' async with aiohttp.ClientSession() as session: async with session.get(site) as resp: - text = await resp.read() - snake = name + text = await resp.text() soup = BeautifulSoup(text, 'lxml') - soup.find(snake) - ''' + snake = soup.find(text=name) if str(name).lower() == 'python': - ''' - Python (Programming Language) - \n - Python is powerful... and fast;\n - plays well with others;\n - runs everywhere;\n - is friendly & easy to learn;\n - is Open. - ------------------------------- - Created by: Guido Van Rossum \n - Founded: 20th of February, 1991 \n - Official website: https://python.org - ''' - name = self.python_info + name = self.python_info + elif name.lower() == snake.lower(): + name = snake + return name @command() @@ -84,6 +74,7 @@ async def get(self, ctx: Context, name: str = None): """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) await ctx.send(await self.get_snek(name)) + # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 8e5cf70fa600ebbc639f7e329cb89582af6d4d57 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 15:40:02 +0000 Subject: [PATCH 21/58] test --- bot/cogs/snakes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index cafe656e..4d04a8bc 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -74,6 +74,7 @@ async def get(self, ctx: Context, name: str = None): """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) await ctx.send(await self.get_snek(name)) + print('resp') # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From e36ae9e9a5216b1ef11ab291891120299d2f680e Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 15:41:28 +0000 Subject: [PATCH 22/58] PEP 8 fix --- bot/cogs/snakes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 4d04a8bc..cafe656e 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -74,7 +74,6 @@ async def get(self, ctx: Context, name: str = None): """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) await ctx.send(await self.get_snek(name)) - print('resp') # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 9f075e950f0354a9074197bc4e8bda4268207a1f Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 16:16:18 +0000 Subject: [PATCH 23/58] Updated snake name fetch --- bot/cogs/snakes.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index cafe656e..6a8dc906 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -46,7 +46,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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 """ - + name = str(name) site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' async with aiohttp.ClientSession() as session: async with session.get(site) as resp: @@ -54,11 +54,10 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: soup = BeautifulSoup(text, 'lxml') snake = soup.find(text=name) - if str(name).lower() == 'python': + if name.lower() == 'python': name = self.python_info - elif name.lower() == snake.lower(): + else: name = snake - return name @command() @@ -73,7 +72,10 @@ async def get(self, ctx: Context, name: str = None): :param name: Optional, the name of the snake to get information for - omit for a random snake """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) - await ctx.send(await self.get_snek(name)) + if name: + await ctx.send(await self.get_snek(name)) + else: + await ctx.send('') # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 28f11546099ae810d0bd0089a948e5688e2fefce Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 18:46:48 +0000 Subject: [PATCH 24/58] Adding embeds --- bot/cogs/snakes.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 6a8dc906..b28adf8a 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -2,6 +2,7 @@ import logging from typing import Any, Dict +import discord import aiohttp @@ -33,7 +34,7 @@ class Snakes: def __init__(self, bot: AutoShardedBot): self.bot = bot - async def get_snek(self, name: str = None) -> Dict[str, Any]: + async def get_snek(self, embed, name: str = None) -> Dict[str, Any]: """ Go online and fetch information about a snake @@ -47,21 +48,21 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :return: A dict containing information on a snake """ name = str(name) - site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' + site = 'https://en.wikipedia.org/wiki/' + name async with aiohttp.ClientSession() as session: async with session.get(site) as resp: text = await resp.text() soup = BeautifulSoup(text, 'lxml') - snake = soup.find(text=name) + table = discord.Embed(title=soup.find('tbody')) + if name.lower() == 'python': name = self.python_info else: - name = snake - return name + embed = table @command() - async def get(self, ctx: Context, name: str = None): + async def get(self, embed, ctx: Context, name: str = None,): """ Go online and fetch information about a snake @@ -75,7 +76,7 @@ async def get(self, ctx: Context, name: str = None): if name: await ctx.send(await self.get_snek(name)) else: - await ctx.send('') + ctx.send(embed=embed) # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From b63381e9bbdcee157ba5e88c67fe52620f65503a Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 18:49:20 +0000 Subject: [PATCH 25/58] removed some gentle hard-coding --- bot/cogs/snakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index c0ece110..7739c512 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -27,7 +27,7 @@ class Snakes: def __init__(self, bot: AutoShardedBot): self.bot = bot - self.site = wikipedia.page('List of snakes by common name') + self.site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' async def get_snek(self, embed, name: str = None) -> Dict[str, Any]: """ @@ -43,7 +43,7 @@ async def get_snek(self, embed, name: str = None) -> Dict[str, Any]: :return: A dict containing information on a snake """ name = str(name) - site = 'https://en.wikipedia.org/wiki/' + name + site = self.site + name async with aiohttp.ClientSession() as session: async with session.get(site) as resp: text = await resp.text() From 33bddfc080fc763c0a00089fe2bd24e3b60b40a2 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sat, 24 Mar 2018 19:24:19 +0000 Subject: [PATCH 26/58] updating embed --- bot/cogs/snakes.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index b28adf8a..8b5b49b5 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -34,7 +34,7 @@ class Snakes: def __init__(self, bot: AutoShardedBot): self.bot = bot - async def get_snek(self, embed, name: str = None) -> Dict[str, Any]: + async def get_snek(self, name: str = None) -> Dict[str, Any]: """ Go online and fetch information about a snake @@ -53,16 +53,17 @@ async def get_snek(self, embed, name: str = None) -> Dict[str, Any]: async with session.get(site) as resp: text = await resp.text() soup = BeautifulSoup(text, 'lxml') - table = discord.Embed(title=soup.find('tbody')) if name.lower() == 'python': name = self.python_info - else: - embed = table + + return name + + @command() - async def get(self, embed, ctx: Context, name: str = None,): + async def get(self, ctx: Context, name: str = None,): """ Go online and fetch information about a snake @@ -73,10 +74,18 @@ async def get(self, embed, ctx: Context, name: str = None,): :param name: Optional, the name of the snake to get information for - omit for a random snake """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) - if name: + name = str(name) + site = 'https://en.wikipedia.org/wiki/' + name + async with aiohttp.ClientSession() as session: + async with session.get(site) as resp: + text = await resp.text() + soup = BeautifulSoup(text, 'lxml') + em = discord.Embed(title=name, description="Description") + + if name.lower() == 'python': await ctx.send(await self.get_snek(name)) else: - ctx.send(embed=embed) + await ctx.send(embed=em) # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! From 34864b597121a33e83b8b34a2a76446402d9c6f8 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 20:22:21 +0000 Subject: [PATCH 27/58] begin working on snake --- bot/cogs/snakes.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 7739c512..67347ce6 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,5 +1,5 @@ # coding=utf-8 -import logging, aiohttp, random, wikipedia +import logging, aiohttp, random, wikipedia, time from bs4 import BeautifulSoup from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command @@ -26,6 +26,7 @@ class Snakes: ''' def __init__(self, bot: AutoShardedBot): + self.inputs = [] self.bot = bot self.site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' @@ -75,6 +76,34 @@ async def get(self, embed, ctx: Context, name: str = None,): # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! + @command() + async def snake(self, ctx: Context, x=10, y=5): + board = """""" + snake = [(x//2, y//2)] + + board += "```\n " + "#" * x + "##" + for yAxis in range(y): + board += "\n #" + for xAxis in range(x): + + for pos in snake: + if pos == (xAxis, yAxis): + board += "@" + break + else: + board += "0" + + board += "#" + board += "\n " + "#" * x + "##```" + + await ctx.send(board) + + async def on_message(self, message): + if message.content in ("w", "a", "s", "d"): + self.inputs.append(message.content) + + + def setup(bot): From 2ff9b487c4f192311de6122d99d772228c159ce5 Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 20:28:51 +0000 Subject: [PATCH 28/58] on_message now appends full object --- bot/cogs/snakes.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 67347ce6..b73a21fb 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -100,10 +100,7 @@ async def snake(self, ctx: Context, x=10, y=5): async def on_message(self, message): if message.content in ("w", "a", "s", "d"): - self.inputs.append(message.content) - - - + self.inputs.append(message) def setup(bot): From 5a6932ecd0ae23f17032b959a110fb1169c4e27d Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 21:02:15 +0000 Subject: [PATCH 29/58] working message logger --- bot/cogs/snakes.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index b73a21fb..1e7e9eed 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -79,8 +79,11 @@ async def get(self, embed, ctx: Context, name: str = None,): @command() async def snake(self, ctx: Context, x=10, y=5): board = """""" + running = True snake = [(x//2, y//2)] + userID = ctx.author.id + board += "```\n " + "#" * x + "##" for yAxis in range(y): board += "\n #" @@ -98,11 +101,19 @@ async def snake(self, ctx: Context, x=10, y=5): await ctx.send(board) + while True: + for mess in self.inputs: + if mess.author.id == userID: + await ctx.send("success") + self.inputs.clear + break + async def on_message(self, message): if message.content in ("w", "a", "s", "d"): self.inputs.append(message) + def setup(bot): bot.add_cog(Snakes(bot)) log.info("Cog loaded: Snakes") From 6f04e377569e664517ac2fb359d1509d29e438bd Mon Sep 17 00:00:00 2001 From: xedre Date: Sat, 24 Mar 2018 23:59:05 +0000 Subject: [PATCH 30/58] snake maybe possible probably not? --- bot/cogs/snakes.py | 54 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 1e7e9eed..7261255d 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,8 +1,10 @@ # coding=utf-8 -import logging, aiohttp, random, wikipedia, time +import logging, aiohttp, random, wikipedia +from time import sleep from bs4 import BeautifulSoup from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command +import asyncio log = logging.getLogger(__name__) @@ -51,7 +53,6 @@ async def get_snek(self, embed, name: str = None) -> Dict[str, Any]: soup = BeautifulSoup(text, 'lxml') table = discord.Embed(title=soup.find('tbody')) - if name.lower() == 'python': name = self.python_info else: @@ -77,41 +78,68 @@ async def get(self, embed, ctx: Context, name: str = None,): # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! @command() - async def snake(self, ctx: Context, x=10, y=5): + async def snake(self, ctx: Context, x=50, y=30): board = """""" running = True - snake = [(x//2, y//2)] + head = [x//2, y//2] userID = ctx.author.id + facing = 0 board += "```\n " + "#" * x + "##" for yAxis in range(y): board += "\n #" for xAxis in range(x): - - for pos in snake: - if pos == (xAxis, yAxis): - board += "@" - break + if head == [xAxis, yAxis]: + board += "X" else: board += "0" board += "#" board += "\n " + "#" * x + "##```" - await ctx.send(board) + snakeBoard = await ctx.send(board) - while True: + while running: for mess in self.inputs: if mess.author.id == userID: await ctx.send("success") - self.inputs.clear + self.inputs = [] + if mess.content == "a": + facing = (facing - 1) % 4 + if mess.content == "d": + facing = (facing + 1) % 4 break + if facing == 0: + head[1] -= 1 + elif facing == 1: + head[0] += 1 + elif facing == 2: + head[1] += 1 + else: + head[0] -= 1 + + board = """""" + board += "```\n " + "#" * x + "##" + for yAxis in range(y): + board += "\n #" + for xAxis in range(x): + if head == [xAxis, yAxis]: + board += "X" + else: + board += "0" + + board += "#" + board += "\n " + "#" * x + "##```" + + await snakeBoard.edit(content=board) + await asyncio.sleep(1) + async def on_message(self, message): if message.content in ("w", "a", "s", "d"): self.inputs.append(message) - + await message.delete() def setup(bot): From 2d5f3b6cf06036b68c7da25946fef4c5c114a986 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 25 Mar 2018 06:04:47 +0100 Subject: [PATCH 31/58] Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1 Added snake search --- bot/cogs/snakes.py | 83 +++++++--------------------------------------- 1 file changed, 12 insertions(+), 71 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index af40bb0f..75b99fbe 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,10 +1,12 @@ # coding=utf-8 -import logging, aiohttp, random, wikipedia -from time import sleep -from bs4 import BeautifulSoup +import logging +import aiohttp +import discord + + from typing import Any, Dict +from bs4 import BeautifulSoup from discord.ext.commands import AutoShardedBot, Context, command -import asyncio log = logging.getLogger(__name__) @@ -28,9 +30,7 @@ class Snakes: ''' def __init__(self, bot: AutoShardedBot): - self.inputs = [] self.bot = bot - self.site = 'https://en.wikipedia.org/wiki/List_of_snakes_by_common_name' async def get_snek(self, name: str = None) -> Dict[str, Any]: """ @@ -46,12 +46,13 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :return: A dict containing information on a snake """ name = str(name) - site = self.site + name + site = 'https://en.wikipedia.org/wiki/' + name async with aiohttp.ClientSession() as session: async with session.get(site) as resp: text = await resp.text() soup = BeautifulSoup(text, 'lxml') + if name.lower() == 'python': name = self.python_info @@ -77,7 +78,10 @@ async def get(self, ctx: Context, name: str = None,): async with session.get(site) as resp: text = await resp.text() soup = BeautifulSoup(text, 'lxml') - em = discord.Embed(title=name, description="Description") + title = soup.find('h1').text + description = soup.find('table').text + + em = discord.Embed(title=title, description=description) if name.lower() == 'python': await ctx.send(await self.get_snek(name)) @@ -86,69 +90,6 @@ async def get(self, ctx: Context, name: str = None,): # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! - @command() - async def snake(self, ctx: Context, x=50, y=30): - board = """""" - running = True - head = [x//2, y//2] - - userID = ctx.author.id - facing = 0 - - board += "```\n " + "#" * x + "##" - for yAxis in range(y): - board += "\n #" - for xAxis in range(x): - if head == [xAxis, yAxis]: - board += "X" - else: - board += "0" - - board += "#" - board += "\n " + "#" * x + "##```" - - snakeBoard = await ctx.send(board) - - while running: - for mess in self.inputs: - if mess.author.id == userID: - await ctx.send("success") - self.inputs = [] - if mess.content == "a": - facing = (facing - 1) % 4 - if mess.content == "d": - facing = (facing + 1) % 4 - break - - if facing == 0: - head[1] -= 1 - elif facing == 1: - head[0] += 1 - elif facing == 2: - head[1] += 1 - else: - head[0] -= 1 - - board = """""" - board += "```\n " + "#" * x + "##" - for yAxis in range(y): - board += "\n #" - for xAxis in range(x): - if head == [xAxis, yAxis]: - board += "X" - else: - board += "0" - - board += "#" - board += "\n " + "#" * x + "##```" - - await snakeBoard.edit(content=board) - await asyncio.sleep(1) - - async def on_message(self, message): - if message.content in ("w", "a", "s", "d"): - self.inputs.append(message) - await message.delete() def setup(bot): From 4765a23ab2c47290a79912b46564e7a999b69169 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 25 Mar 2018 06:06:27 +0100 Subject: [PATCH 32/58] update snakes.py --- bot/cogs/snakes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 75b99fbe..142b94d9 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -50,6 +50,7 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: async with aiohttp.ClientSession() as session: async with session.get(site) as resp: text = await resp.text() + print() soup = BeautifulSoup(text, 'lxml') From aa5b3ed039cd2c7a91836d0394724644c94dad9f Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 25 Mar 2018 06:08:49 +0100 Subject: [PATCH 33/58] update nakes.py --- bot/cogs/snakes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 142b94d9..75b99fbe 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -50,7 +50,6 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: async with aiohttp.ClientSession() as session: async with session.get(site) as resp: text = await resp.text() - print() soup = BeautifulSoup(text, 'lxml') From 9bbeb30b763ad41b03514637c4b59ceb8e7e2dae Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 10:09:24 +0100 Subject: [PATCH 34/58] snake no tail complete --- bot/cogs/snakes.py | 80 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 75b99fbe..ce50e0c9 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,12 +1,10 @@ # coding=utf-8 -import logging -import aiohttp -import discord - - -from typing import Any, Dict +import logging, aiohttp, random, wikipedia +from time import sleep from bs4 import BeautifulSoup +from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command +import asyncio log = logging.getLogger(__name__) @@ -30,6 +28,7 @@ class Snakes: ''' def __init__(self, bot: AutoShardedBot): + self.inputs = [] self.bot = bot async def get_snek(self, name: str = None) -> Dict[str, Any]: @@ -90,6 +89,75 @@ async def get(self, ctx: Context, name: str = None,): # await ctx.send(name) # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! + @command() + async def snake(self, ctx: Context, x=50, y=30): + board = """""" + running = True + snake = [] + + head = [x//2, y//2] + snake.append(head) + userID = ctx.author.id + + facing = 0 + + board += "```\n " + "#" * x + "##" + for yAxis in range(y): + board += "\n #" + for xAxis in range(x): + if head == [xAxis, yAxis]: + board += "X" + else: + board += "0" + + board += "#" + board += "\n " + "#" * x + "##```" + + snakeBoard = await ctx.send(board) + + while running: + for mess in self.inputs: + if mess.author.id == userID: + self.inputs = [] + if mess.content == "a": + facing = (facing - 1) % 4 + if mess.content == "d": + facing = (facing + 1) % 4 + break + + if facing == 0: + head[1] -= 1 + elif facing == 1: + head[0] += 1 + elif facing == 2: + head[1] += 1 + else: + head[0] -= 1 + + snake.pop(-1) + snake.append(head) + + board = """""" + board += "```\n " + "#" * x + "##" + for yAxis in range(y): + board += "\n #" + for xAxis in range(x): + for + if head == [xAxis, yAxis]: + board += "X" + else: + board += "0" + + board += "#" + board += "\n " + "#" * x + "##```" + + await snakeBoard.edit(content=board) + await asyncio.sleep(0.8) + + async def on_message(self, message): + if message.content in ("w", "a", "s", "d"): + self.inputs.append(message) + await message.delete() def setup(bot): From f448a4e35bce7e6353a671ee409c5174cf1e2a80 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 10:37:32 +0100 Subject: [PATCH 35/58] DNP: bug with logging --- bot/cogs/snakes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index ce50e0c9..3feeb1e2 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -142,7 +142,6 @@ async def snake(self, ctx: Context, x=50, y=30): for yAxis in range(y): board += "\n #" for xAxis in range(x): - for if head == [xAxis, yAxis]: board += "X" else: From 36933e461267b90f26b605725be44aae794837d0 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 11:15:26 +0100 Subject: [PATCH 36/58] apples and framework for tail --- bot/cogs/snakes.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 3feeb1e2..e35a05ae 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,6 +1,5 @@ # coding=utf-8 -import logging, aiohttp, random, wikipedia -from time import sleep +import logging, aiohttp, random from bs4 import BeautifulSoup from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command @@ -100,6 +99,8 @@ async def snake(self, ctx: Context, x=50, y=30): userID = ctx.author.id facing = 0 + snake.append(head) + apple = [random.randint(0, x), random.randint(0, y)] board += "```\n " + "#" * x + "##" for yAxis in range(y): @@ -134,7 +135,7 @@ async def snake(self, ctx: Context, x=50, y=30): else: head[0] -= 1 - snake.pop(-1) + snake.pop(0) snake.append(head) board = """""" @@ -142,10 +143,15 @@ async def snake(self, ctx: Context, x=50, y=30): for yAxis in range(y): board += "\n #" for xAxis in range(x): - if head == [xAxis, yAxis]: - board += "X" + for snakeTail in snake: + if snakeTail == [xAxis, yAxis]: + board += "X" + break else: - board += "0" + if apple == [xAxis, yAxis]: + board += "@" + else: + board += "0" board += "#" board += "\n " + "#" * x + "##```" From 417d7a7dce08928a3e5c9bdf46a8ca73d595422e Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 12:03:29 +0100 Subject: [PATCH 37/58] added lxml to pipfile --- Pipfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Pipfile b/Pipfile index c10c94db..9d8c7f12 100644 --- a/Pipfile +++ b/Pipfile @@ -10,6 +10,7 @@ aiohttp = "<2.3.0,>=2.0.0" websockets = ">=4.0,<5.0" "beautifulsoup4" = "*" wikipedia = "*" +lxml = "*" [dev-packages] "flake8" = "*" From 6a804bd0c608dc8b91e3c628e2cffd4b6d3680c6 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 12:21:03 +0100 Subject: [PATCH 38/58] tuples/tail converted all dict types apart from head to tuples added snake tail --- bot/cogs/snakes.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index e35a05ae..5cb7334d 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -100,7 +100,7 @@ async def snake(self, ctx: Context, x=50, y=30): facing = 0 snake.append(head) - apple = [random.randint(0, x), random.randint(0, y)] + apple = (random.randint(0, x), random.randint(0, y)) board += "```\n " + "#" * x + "##" for yAxis in range(y): @@ -135,8 +135,13 @@ async def snake(self, ctx: Context, x=50, y=30): else: head[0] -= 1 - snake.pop(0) - snake.append(head) + for snakeTail in snake: + if snakeTail == apple: + apple = (random.randint(0, x), random.randint(0, y)) + break + else: + snake.pop(0) + snake.append(tuple(head)) board = """""" board += "```\n " + "#" * x + "##" @@ -144,11 +149,11 @@ async def snake(self, ctx: Context, x=50, y=30): board += "\n #" for xAxis in range(x): for snakeTail in snake: - if snakeTail == [xAxis, yAxis]: + if snakeTail == (xAxis, yAxis): board += "X" break else: - if apple == [xAxis, yAxis]: + if apple == (xAxis, yAxis): board += "@" else: board += "0" @@ -157,7 +162,7 @@ async def snake(self, ctx: Context, x=50, y=30): board += "\n " + "#" * x + "##```" await snakeBoard.edit(content=board) - await asyncio.sleep(0.8) + await asyncio.sleep(0.9) async def on_message(self, message): if message.content in ("w", "a", "s", "d"): From ac7c08a59ac4c30af1239d2e3d742705912cf88e Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 25 Mar 2018 10:59:15 +0100 Subject: [PATCH 39/58] Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1 Delete unnecessary code --- bot/cogs/snakes.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 5cb7334d..186a463e 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -44,12 +44,6 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :return: A dict containing information on a snake """ name = str(name) - site = 'https://en.wikipedia.org/wiki/' + name - async with aiohttp.ClientSession() as session: - async with session.get(site) as resp: - text = await resp.text() - soup = BeautifulSoup(text, 'lxml') - if name.lower() == 'python': name = self.python_info From 996edbabe2ae602ecdd6b529c10229100a4bb2f1 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 25 Mar 2018 12:23:05 +0100 Subject: [PATCH 40/58] Merge branch 'master' of https://github.com/Hasan-Ahmad/code-jam-1 Adding snake description --- bot/cogs/snakes.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 186a463e..57306085 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,4 +1,6 @@ # coding=utf-8 +import logging, aiohttp, random, discord +from time import sleep import logging, aiohttp, random from bs4 import BeautifulSoup from typing import Any, Dict @@ -71,8 +73,11 @@ async def get(self, ctx: Context, name: str = None,): text = await resp.text() soup = BeautifulSoup(text, 'lxml') title = soup.find('h1').text - description = soup.find('table').text - + description = soup.find('p').text + table = soup.find('table').text + list(table) + table = ''.join(table[0:160].split()) + description = description + '\n \n \n' + table em = discord.Embed(title=title, description=description) if name.lower() == 'python': From 40efcaaf0eb1d3622839acb21fabd54bdb9019ae Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 12:28:08 +0100 Subject: [PATCH 41/58] removed unused imports --- bot/cogs/snakes.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 57306085..c8846887 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,7 +1,5 @@ # coding=utf-8 import logging, aiohttp, random, discord -from time import sleep -import logging, aiohttp, random from bs4 import BeautifulSoup from typing import Any, Dict from discord.ext.commands import AutoShardedBot, Context, command @@ -88,7 +86,7 @@ async def get(self, ctx: Context, name: str = None,): # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! @command() - async def snake(self, ctx: Context, x=50, y=30): + async def snake(self, ctx: Context, x=10, y=7): board = """""" running = True snake = [] @@ -142,7 +140,7 @@ async def snake(self, ctx: Context, x=50, y=30): snake.pop(0) snake.append(tuple(head)) - board = """""" + board = """Snake!\n""" board += "```\n " + "#" * x + "##" for yAxis in range(y): board += "\n #" From 56da19587d9e0324c0870f07c9bad35b067beb2f Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 25 Mar 2018 12:39:32 +0100 Subject: [PATCH 42/58] Changed how much info is scraped from the table --- bot/cogs/snakes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index c8846887..9f4a93d3 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -74,8 +74,9 @@ async def get(self, ctx: Context, name: str = None,): description = soup.find('p').text table = soup.find('table').text list(table) - table = ''.join(table[0:160].split()) - description = description + '\n \n \n' + table + table = table[120:] + table = ''.join(table) + description = description + '\n' + table em = discord.Embed(title=title, description=description) if name.lower() == 'python': From 0c1c026587fc86d3e1831438d2b08e0f4412883e Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 25 Mar 2018 13:11:54 +0100 Subject: [PATCH 43/58] PEP8 fix --- Pipfile | 1 - Pipfile.lock | 70 +++++++++++++++++++++++++--------------------- bot/cogs/snakes.py | 50 ++++++++++++++++----------------- 3 files changed, 63 insertions(+), 58 deletions(-) diff --git a/Pipfile b/Pipfile index 9d8c7f12..3cc318a5 100644 --- a/Pipfile +++ b/Pipfile @@ -9,7 +9,6 @@ aiodns = "*" aiohttp = "<2.3.0,>=2.0.0" websockets = ">=4.0,<5.0" "beautifulsoup4" = "*" -wikipedia = "*" lxml = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 7ced31d2..5a010121 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "89800ac602d63f956f05d7ce2df2166152ca722cab1aa564dfffd849c9d8c1bb" + "sha256": "b9b192123ee24bf056723e79ecaaf98633d36ec32fd0175f2823d20e13dc882b" }, "pipfile-spec": 6, "requires": { @@ -62,13 +62,6 @@ "index": "pypi", "version": "==4.6.0" }, - "certifi": { - "hashes": [ - "sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296", - "sha256:edbc3f203427eef571f79a7692bb160a2b0f7ccaa31953e99bd17e307cf63f7d" - ], - "version": "==2018.1.18" - }, "chardet": { "hashes": [ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", @@ -83,6 +76,40 @@ ], "version": "==2.6" }, + "lxml": { + "hashes": [ + "sha256:01c45df6d90497c20aa2a07789a41941f9a1029faa30bf725fc7f6d515b1afe9", + "sha256:0c9fef4f8d444e337df96c54544aeb85b7215b2ed7483bb6c35de97ac99f1bcd", + "sha256:0e3cd94c95d30ba9ca3cff40e9b2a14e1a10a4fd8131105b86c6b61648f57e4b", + "sha256:0e7996e9b46b4d8b4ac1c329a00e2d10edcd8380b95d2a676fccabf4c1dd0512", + "sha256:1858b1933d483ec5727549d3fe166eeb54229fbd6a9d3d7ea26d2c8a28048058", + "sha256:1b164bba1320b14905dcff77da10d5ce9c411ac4acc4fb4ed9a2a4d10fae38c9", + "sha256:1b46f37927fa6cd1f3fe34b54f1a23bd5bea1d905657289e08e1297069a1a597", + "sha256:231047b05907315ae9a9b6925751f9fd2c479cf7b100fff62485a25e382ca0d4", + "sha256:28f0c6652c1b130f1e576b60532f84b19379485eb8da6185c29bd8c9c9bc97bf", + "sha256:34d49d0f72dd82b9530322c48b70ac78cca0911275da741c3b1d2f3603c5f295", + "sha256:3682a17fbf72d56d7e46db2e80ca23850b79c28cfe75dcd9b82f58808f730909", + "sha256:3cf2830b9a6ad7f6e965fa53a768d4d2372a7856f20ffa6ce43d2fe9c0d34b19", + "sha256:5b653c9379ce29ce271fbe1010c5396670f018e78b643e21beefbb3dc6d291de", + "sha256:65a272821d5d8194358d6b46f3ca727fa56a6b63981606eac737c86d27309cdd", + "sha256:691f2cd97cf026c611df1ea5055755eec7f878f2d4f4330dc8686583de6fc5fd", + "sha256:6b6379495d3baacf7ed755ac68547c8dff6ce5d37bf370f0b7678888dc1283f9", + "sha256:75322a531504d4f383264391d89993a42e286da8821ddc5ac315e57305cb84f0", + "sha256:7f457cbda964257f443bac861d3a36732dcba8183149e7818ee2fb7c86901b94", + "sha256:7ff1fc76d8804e0f870c343a72007ff587090c218b0f92d8ee784ac2b6eaf5b9", + "sha256:8523fbde9c2216f3f2b950cb01ebe52e785eaa8a07ffeb456dd3576ca1b4fb9b", + "sha256:8f37627f16e026523fca326f1b5c9a43534862fede6c3e99c2ba6a776d75c1ab", + "sha256:a7182ea298cc3555ea56ffbb0748fe0d5e0d81451e2bc16d7f4645cd01b1ca70", + "sha256:abbd2fb4a5a04c11b5e04eb146659a0cf67bb237dd3d7ca3b9994d3a9f826e55", + "sha256:accc9f6b77bed0a6f267b4fae120f6008a951193d548cdbe9b61fc98a08b1cf8", + "sha256:bd88c8ce0d1504fdfd96a35911dd4f3edfb2e560d7cfdb5a3d09aa571ae5fbae", + "sha256:c557ad647facb3c0027a9d0af58853f905e85a0a2f04dcb73f8e665272fcdc3a", + "sha256:defabb7fbb99f9f7b3e0b24b286a46855caef4776495211b066e9e6592d12b04", + "sha256:e2629cdbcad82b83922a3488937632a4983ecc0fed3e5cfbf430d069382eeb9b" + ], + "index": "pypi", + "version": "==4.2.1" + }, "multidict": { "hashes": [ "sha256:0462372fc74e4c061335118a4a5992b9a618d6c584b028ef03cf3e9b88a960e2", @@ -136,20 +163,6 @@ ], "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", @@ -172,13 +185,6 @@ "index": "pypi", "version": "==4.0.1" }, - "wikipedia": { - "hashes": [ - "sha256:db0fad1829fdd441b1852306e9856398204dc0786d2996dd2e0c8bb8e26133b2" - ], - "index": "pypi", - "version": "==1.4.0" - }, "yarl": { "hashes": [ "sha256:045dbba18c9142278113d5dc62622978a6f718ba662392d406141c59b540c514", @@ -319,10 +325,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/snakes.py b/bot/cogs/snakes.py index 9f4a93d3..140f0046 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,9 +1,15 @@ # coding=utf-8 -import logging, aiohttp, random, discord -from bs4 import BeautifulSoup +import asyncio +import logging +import random from typing import Any, Dict + +import aiohttp + +from bs4 import BeautifulSoup + +import discord from discord.ext.commands import AutoShardedBot, Context, command -import asyncio log = logging.getLogger(__name__) @@ -12,19 +18,16 @@ class Snakes: """ Snake-related commands """ - python_info = ''' - Python (Programming Language) - \n - Python is powerful... and fast;\n - plays well with others;\n - runs everywhere;\n - is friendly & easy to learn;\n - is Open. - ------------------------------- - Created by: Guido Van Rossum \n - Founded: 20th of February, 1991 \n - Official website: https://python.org - ''' + python_info = '''Python (Programming Language) + Python is powerful... and fast; + plays well with others; + runs everywhere; + is friendly & easy to learn; + is Open source. + ------------------------------- + Created by: Guido Van Rossum + Founded: 20th of February, 1991 + Official website: https://python.org''' def __init__(self, bot: AutoShardedBot): self.inputs = [] @@ -43,17 +46,14 @@ async def get_snek(self, name: str = None) -> Dict[str, Any]: :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 """ - name = str(name) if name.lower() == 'python': name = self.python_info return name - - @command() - async def get(self, ctx: Context, name: str = None,): + async def get(self, ctx: Context, name: str = None, ): """ Go online and fetch information about a snake @@ -64,7 +64,6 @@ async def get(self, ctx: Context, name: str = None,): :param name: Optional, the name of the snake to get information for - omit for a random snake """ # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) - name = str(name) site = 'https://en.wikipedia.org/wiki/' + name async with aiohttp.ClientSession() as session: async with session.get(site) as resp: @@ -83,16 +82,17 @@ async def get(self, ctx: Context, name: str = None,): await ctx.send(await self.get_snek(name)) else: await ctx.send(embed=em) - # await ctx.send(name) + # await ctx.send(name) + + # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! - # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! @command() async def snake(self, ctx: Context, x=10, y=7): board = """""" running = True snake = [] - head = [x//2, y//2] + head = [x // 2, y // 2] snake.append(head) userID = ctx.author.id @@ -107,7 +107,7 @@ async def snake(self, ctx: Context, x=10, y=7): if head == [xAxis, yAxis]: board += "X" else: - board += "0" + board += "0" board += "#" board += "\n " + "#" * x + "##```" From 989e5d1523071eaee90152ad9389d1502f19dddd Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 13:10:22 +0100 Subject: [PATCH 44/58] you can die now: improved message deletion, mentions, Python is now Open-Source --- bot/cogs/snakes.py | 49 ++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 140f0046..9f7c03ec 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -18,16 +18,19 @@ class Snakes: """ Snake-related commands """ - python_info = '''Python (Programming Language) - Python is powerful... and fast; - plays well with others; - runs everywhere; - is friendly & easy to learn; - is Open source. - ------------------------------- - Created by: Guido Van Rossum - Founded: 20th of February, 1991 - Official website: https://python.org''' + python_info = ''' + Python (Programming Language) + \n + Python is powerful... and fast;\n + plays well with others;\n + runs everywhere;\n + is friendly & easy to learn;\n + is Open-Source. + ------------------------------- + Created by: Guido Van Rossum \n + Founded: 20th of February, 1991 \n + Official website: https://python.org + ''' def __init__(self, bot: AutoShardedBot): self.inputs = [] @@ -115,14 +118,20 @@ async def snake(self, ctx: Context, x=10, y=7): snakeBoard = await ctx.send(board) while running: + directionChange = True for mess in self.inputs: if mess.author.id == userID: self.inputs = [] if mess.content == "a": - facing = (facing - 1) % 4 - if mess.content == "d": - facing = (facing + 1) % 4 - break + if directionChange: + facing = (facing - 1) % 4 + directionChange = False + await mess.delete() + elif mess.content == "d": + if directionChange: + facing = (facing + 1) % 4 + directionChange = False + await mess.delete() if facing == 0: head[1] -= 1 @@ -133,6 +142,13 @@ async def snake(self, ctx: Context, x=10, y=7): else: head[0] -= 1 + if tuple(head) == any(snake): + await ctx.send(str(ctx.author.mention) + " ate yourself...") + break + if head[0] < 0 or head[1] < 0 or head[0] > x or head[1] > y: + await ctx.send(str(ctx.author.mention) + " ate a wall?") + break + for snakeTail in snake: if snakeTail == apple: apple = (random.randint(0, x), random.randint(0, y)) @@ -141,7 +157,7 @@ async def snake(self, ctx: Context, x=10, y=7): snake.pop(0) snake.append(tuple(head)) - board = """Snake!\n""" + board = """Snake! {}\n""".format(ctx.author.mention) board += "```\n " + "#" * x + "##" for yAxis in range(y): board += "\n #" @@ -163,9 +179,8 @@ async def snake(self, ctx: Context, x=10, y=7): await asyncio.sleep(0.9) async def on_message(self, message): - if message.content in ("w", "a", "s", "d"): + if message.content in ("a", "d"): self.inputs.append(message) - await message.delete() def setup(bot): From adff2e69eb75e6dfe156d085404c5e6de05563d0 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 15:20:53 +0100 Subject: [PATCH 45/58] Snake complete --- bot/cogs/snakes.py | 48 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 9f7c03ec..5629451f 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -91,19 +91,18 @@ async def get(self, ctx: Context, name: str = None, ): @command() async def snake(self, ctx: Context, x=10, y=7): - board = """""" - running = True - snake = [] - head = [x // 2, y // 2] - snake.append(head) - userID = ctx.author.id + snake = [] # define snake (where snake sections are stored) + head = [x // 2, y // 2] # define head (where current snake head is stored) + apple = (random.randint(0, x), random.randint(0, y)) # define apple (where current apple position is stored) + userID = ctx.author.id facing = 0 + snake.append(head) - apple = (random.randint(0, x), random.randint(0, y)) + running = True - board += "```\n " + "#" * x + "##" + board = "```\n " + "#" * x + "##" for yAxis in range(y): board += "\n #" for xAxis in range(x): @@ -122,11 +121,13 @@ async def snake(self, ctx: Context, x=10, y=7): for mess in self.inputs: if mess.author.id == userID: self.inputs = [] + if mess.content == "a": if directionChange: facing = (facing - 1) % 4 directionChange = False await mess.delete() + elif mess.content == "d": if directionChange: facing = (facing + 1) % 4 @@ -142,42 +143,61 @@ async def snake(self, ctx: Context, x=10, y=7): else: head[0] -= 1 - if tuple(head) == any(snake): - await ctx.send(str(ctx.author.mention) + " ate yourself...") - break if head[0] < 0 or head[1] < 0 or head[0] > x or head[1] > y: - await ctx.send(str(ctx.author.mention) + " ate a wall?") + await ctx.send(str(ctx.author.mention) + " become a wall :cry:") break + # check if + for snakeTail in snake: + if snakeTail == tuple(head): + await ctx.send(str(ctx.author.mention) + " ate himself :open_mouth: ") + running = False + + # check if an apple was eaten for snakeTail in snake: if snakeTail == apple: - apple = (random.randint(0, x), random.randint(0, y)) + # if so it generates a new apple + apple = (random.randrange(x), random.randrange(y)) break + # if no apple is eaten then the else will run. So when a apple is eaten the last tuple to be added to list (snake) will not be removed + # this effectively makes the snake one section longer. else: snake.pop(0) + # add the current snake head to the list snake snake.append(tuple(head)) - board = """Snake! {}\n""".format(ctx.author.mention) + # add title + board = """Snake! \n""" + # add top of board board += "```\n " + "#" * x + "##" for yAxis in range(y): + # add side of board board += "\n #" for xAxis in range(x): + # add snake sections for snakeTail in snake: if snakeTail == (xAxis, yAxis): board += "X" break + else: + # add apple if apple == (xAxis, yAxis): board += "@" + # add background else: board += "0" + # add side of board board += "#" + # add bottom of board board += "\n " + "#" * x + "##```" + # edit message then wait for next frame await snakeBoard.edit(content=board) await asyncio.sleep(0.9) + # get user snake inputs async def on_message(self, message): if message.content in ("a", "d"): self.inputs.append(message) From 4399dcb14166cb370ce7690a82badef4f0fe69df Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 25 Mar 2018 15:42:03 +0100 Subject: [PATCH 46/58] PEP8 fix, typo fix, removed unnecessary comments --- bot/cogs/snakes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 5629451f..91a8a66b 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -66,7 +66,7 @@ async def get(self, ctx: Context, name: str = None, ): :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 """ - # await ctx.send(BeautifulSoup(text, 'lxml').find("title")) + site = 'https://en.wikipedia.org/wiki/' + name async with aiohttp.ClientSession() as session: async with session.get(site) as resp: @@ -93,8 +93,8 @@ async def get(self, ctx: Context, name: str = None, ): async def snake(self, ctx: Context, x=10, y=7): snake = [] # define snake (where snake sections are stored) - head = [x // 2, y // 2] # define head (where current snake head is stored) - apple = (random.randint(0, x), random.randint(0, y)) # define apple (where current apple position is stored) + head = [x // 2, y // 2] # define head (where current snake head is stored) + apple = (random.randint(0, x), random.randint(0, y)) # define apple (where current apple position is stored) userID = ctx.author.id facing = 0 @@ -159,7 +159,8 @@ async def snake(self, ctx: Context, x=10, y=7): # if so it generates a new apple apple = (random.randrange(x), random.randrange(y)) break - # if no apple is eaten then the else will run. So when a apple is eaten the last tuple to be added to list (snake) will not be removed + # if no apple is eaten then the else will run. + # So when an apple is eaten the last tuple to be added to list (snake) will not be removed # this effectively makes the snake one section longer. else: snake.pop(0) From 8904bce3227a8e51a8ebea7631119c6d6ed8c4bf Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 17:30:28 +0100 Subject: [PATCH 47/58] emogis --- bot/cogs/snakes.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 91a8a66b..5d05fafb 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -93,7 +93,7 @@ async def get(self, ctx: Context, name: str = None, ): async def snake(self, ctx: Context, x=10, y=7): snake = [] # define snake (where snake sections are stored) - head = [x // 2, y // 2] # define head (where current snake head is stored) + head = [x // 2, y ] # define head (where current snake head is stored) apple = (random.randint(0, x), random.randint(0, y)) # define apple (where current apple position is stored) userID = ctx.author.id @@ -102,19 +102,20 @@ async def snake(self, ctx: Context, x=10, y=7): snake.append(head) running = True - board = "```\n " + "#" * x + "##" + board = "\n " + ":black_large_square:" * x + ":black_large_square::black_large_square:" for yAxis in range(y): - board += "\n #" + board += "\n:black_large_square:" for xAxis in range(x): if head == [xAxis, yAxis]: - board += "X" + board += ":snake:" else: - board += "0" + board += ":white_large_square:" - board += "#" - board += "\n " + "#" * x + "##```" + board += ":black_large_square:" + board += "\n" + ":black_large_square:" * x + ":black_large_square::black_large_square:" - snakeBoard = await ctx.send(board) + Board = discord.Embed(title="Snake!", description=board) + snakeBoard = await ctx.send(embed=Board) while running: directionChange = True @@ -168,34 +169,35 @@ async def snake(self, ctx: Context, x=10, y=7): snake.append(tuple(head)) # add title - board = """Snake! \n""" + board = """""" # add top of board - board += "```\n " + "#" * x + "##" + board += "\n " + ":black_large_square:" * x + ":black_large_square::black_large_square:" for yAxis in range(y): # add side of board - board += "\n #" + board += "\n:black_large_square:" for xAxis in range(x): # add snake sections for snakeTail in snake: if snakeTail == (xAxis, yAxis): - board += "X" + board += ":snake:" break else: # add apple if apple == (xAxis, yAxis): - board += "@" + board += ":apple:" # add background else: - board += "0" + board += ":white_large_square:" # add side of board - board += "#" + board += ":black_large_square:" # add bottom of board - board += "\n " + "#" * x + "##```" + board += "\n " + ":black_large_square:" * x + ":black_large_square::black_large_square:" # edit message then wait for next frame - await snakeBoard.edit(content=board) + Board = discord.Embed(title="Snake!", description=board) + await snakeBoard.edit(embed=Board) await asyncio.sleep(0.9) # get user snake inputs From e0bf1cccf5547ad6e4d16fb419004282a1e17eb1 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 17:40:00 +0100 Subject: [PATCH 48/58] petty rage push --- bot/cogs/snakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 5d05fafb..89d26f80 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -144,7 +144,7 @@ async def snake(self, ctx: Context, x=10, y=7): else: head[0] -= 1 - if head[0] < 0 or head[1] < 0 or head[0] > x or head[1] > y: + if head[0] < 0 or head[1] < 0 or head[0] > x - 1 or head[1] > y - 1: await ctx.send(str(ctx.author.mention) + " become a wall :cry:") break @@ -193,7 +193,7 @@ async def snake(self, ctx: Context, x=10, y=7): # add side of board board += ":black_large_square:" # add bottom of board - board += "\n " + ":black_large_square:" * x + ":black_large_square::black_large_square:" + board += "\n" + ":black_large_square:" * x + ":black_large_square::black_large_square:" # edit message then wait for next frame Board = discord.Embed(title="Snake!", description=board) From f03b98f4c6d848da595b8f1e8419d4c62c28c282 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:16:02 +0100 Subject: [PATCH 49/58] done stuff to changes --- .gitignore | 2 -- bot/cogs/snakes.py | 42 ++++++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 932ecf25..2895fff3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,6 @@ __pycache__/ # Distribution / packaging .Python env/ -.idea/ -.env build/ develop-eggs/ dist/ diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 89d26f80..1ce8aaaf 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,36 +1,34 @@ # coding=utf-8 +import aiohttp import asyncio import logging import random -from typing import Any, Dict - -import aiohttp - from bs4 import BeautifulSoup +from typing import Any, Dict +# from discord import Embed, Reaction, Member import discord from discord.ext.commands import AutoShardedBot, Context, command log = logging.getLogger(__name__) - class Snakes: """ Snake-related commands """ python_info = ''' - Python (Programming Language) - \n - Python is powerful... and fast;\n - plays well with others;\n - runs everywhere;\n - is friendly & easy to learn;\n - is Open-Source. - ------------------------------- - Created by: Guido Van Rossum \n - Founded: 20th of February, 1991 \n - Official website: https://python.org - ''' + Python (Programming Language) + \n + Python is powerful... and fast;\n + plays well with others;\n + runs everywhere;\n + is friendly & easy to learn;\n + is Open-Source. + ------------------------------- + Created by: Guido Van Rossum \n + Founded: 20th of February, 1991 \n + Official website: https://python.org + ''' def __init__(self, bot: AutoShardedBot): self.inputs = [] @@ -90,11 +88,11 @@ async def get(self, ctx: Context, name: str = None, ): # Any additional commands can be placed here. Be creative, but keep it to a reasonable amount! @command() - async def snake(self, ctx: Context, x=10, y=7): + async def snake(self, ctx: Context, x=8, y=8): snake = [] # define snake (where snake sections are stored) - head = [x // 2, y ] # define head (where current snake head is stored) - apple = (random.randint(0, x), random.randint(0, y)) # define apple (where current apple position is stored) + head = [x // 2, y] # define head (where current snake head is stored) + apple = (random.randrange(x), random.randrange(y)) # define apple (where current apple position is stored) userID = ctx.author.id facing = 0 @@ -171,7 +169,7 @@ async def snake(self, ctx: Context, x=10, y=7): # add title board = """""" # add top of board - board += "\n " + ":black_large_square:" * x + ":black_large_square::black_large_square:" + board += "\n " + ":black_large_square:" * (x + 2) for yAxis in range(y): # add side of board board += "\n:black_large_square:" @@ -193,7 +191,7 @@ async def snake(self, ctx: Context, x=10, y=7): # add side of board board += ":black_large_square:" # add bottom of board - board += "\n" + ":black_large_square:" * x + ":black_large_square::black_large_square:" + board += "\n" + ":black_large_square:" * (x + 2) # edit message then wait for next frame Board = discord.Embed(title="Snake!", description=board) From 127051f45de973a87738d02de71d958baafa7e6c Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:26:47 +0100 Subject: [PATCH 50/58] main loop breaks now all use Running --- bot/cogs/snakes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 1ce8aaaf..b31a286e 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -144,7 +144,7 @@ async def snake(self, ctx: Context, x=8, y=8): if head[0] < 0 or head[1] < 0 or head[0] > x - 1 or head[1] > y - 1: await ctx.send(str(ctx.author.mention) + " become a wall :cry:") - break + running = False # check if for snakeTail in snake: From 41b2ba42052e5fb341e3a16ae9265de0bf4e7ef2 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:29:22 +0100 Subject: [PATCH 51/58] added break to user inputs --- bot/cogs/snakes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index b31a286e..c4386b53 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -119,7 +119,6 @@ async def snake(self, ctx: Context, x=8, y=8): directionChange = True for mess in self.inputs: if mess.author.id == userID: - self.inputs = [] if mess.content == "a": if directionChange: @@ -132,6 +131,10 @@ async def snake(self, ctx: Context, x=8, y=8): facing = (facing + 1) % 4 directionChange = False await mess.delete() + break + + self.inputs = [] + if facing == 0: head[1] -= 1 From a62097236cfe57ddfef0a798c0ebbae26f4d16c1 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:34:20 +0100 Subject: [PATCH 52/58] removed black line --- bot/cogs/snakes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index c4386b53..0571f596 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -135,7 +135,6 @@ async def snake(self, ctx: Context, x=8, y=8): self.inputs = [] - if facing == 0: head[1] -= 1 elif facing == 1: From f8117201a32f061fc741910db68c8b5956225907 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:34:45 +0100 Subject: [PATCH 53/58] added blank line --- bot/cogs/snakes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 0571f596..a75c281d 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -12,6 +12,7 @@ log = logging.getLogger(__name__) + class Snakes: """ Snake-related commands From 5987a8ac4c37d539ae7634a487da63d5ab83a201 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:35:36 +0100 Subject: [PATCH 54/58] re-ordered some imports --- bot/cogs/snakes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index a75c281d..d32e7bbf 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,6 +1,7 @@ # coding=utf-8 -import aiohttp import asyncio + +import aiohttp import logging import random from bs4 import BeautifulSoup From 804af0a58374735b362c20585b693bdca7bf3831 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:36:01 +0100 Subject: [PATCH 55/58] re-ordered some imports --- bot/cogs/snakes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index d32e7bbf..1af07c44 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -4,8 +4,10 @@ import aiohttp import logging import random -from bs4 import BeautifulSoup + from typing import Any, Dict +from bs4 import BeautifulSoup + # from discord import Embed, Reaction, Member import discord From f87d75e0e91dda03c881ea630d754e6beabe91ef Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:36:14 +0100 Subject: [PATCH 56/58] re-ordered some imports --- bot/cogs/snakes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 1af07c44..ea33cf7c 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -6,6 +6,7 @@ import random from typing import Any, Dict + from bs4 import BeautifulSoup From 42eae457219e8c1e8d97436fc7d9e456c68835d4 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 22:39:55 +0100 Subject: [PATCH 57/58] re-ordered some imports --- bot/cogs/snakes.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index ea33cf7c..20a6a9ae 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -1,10 +1,9 @@ # coding=utf-8 import asyncio - -import aiohttp import logging import random +import aiohttp from typing import Any, Dict from bs4 import BeautifulSoup From 0c83aaf3e369dd4a7887a3d29a07ed65ef6e4965 Mon Sep 17 00:00:00 2001 From: xedre Date: Sun, 25 Mar 2018 23:13:10 +0100 Subject: [PATCH 58/58] Update import order --- bot/cogs/snakes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bot/cogs/snakes.py b/bot/cogs/snakes.py index 20a6a9ae..d0f096df 100644 --- a/bot/cogs/snakes.py +++ b/bot/cogs/snakes.py @@ -9,7 +9,6 @@ from bs4 import BeautifulSoup -# from discord import Embed, Reaction, Member import discord from discord.ext.commands import AutoShardedBot, Context, command