From 1bbf471ae5fa5249ffe15ff47d600ca572a57549 Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Wed, 29 May 2019 03:09:28 +0530 Subject: [PATCH 01/11] flip_a_coin added --- .vscode/settings.json | 6 ------ bot.py | 18 +++++++++++++++++- modules/flip_a_coin.py | 33 +++++++++++++++++++++++++++++++++ tests/test_pep8.py | 11 ++--------- 4 files changed, 52 insertions(+), 16 deletions(-) delete mode 100644 .vscode/settings.json create mode 100644 modules/flip_a_coin.py diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 8f81310..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "python.pythonPath": "venv/bin/python", - "python.linting.pylintEnabled": false, - "python.linting.pep8Enabled": true, - "python.linting.enabled": true -} diff --git a/bot.py b/bot.py index 24a2601..5c624b5 100644 --- a/bot.py +++ b/bot.py @@ -4,7 +4,7 @@ import discord from discord.ext import commands -from modules import xkcd +from modules import xkcd, flip_a_coin TOKEN = os.getenv('DISCORD_BOT_API_TOKEN') bot = commands.Bot(command_prefix='$', description='Just A Rather Very Intelligent System, now on Discord!') @@ -56,4 +56,20 @@ async def search_image(ctx, search_arg): print(e) await ctx.send("Sorry, something went wrong.") + +@bot.command( + name="flip_a_coin", + description="Flip a coin game", + brief="flip a coin and send head to tails", +) +async def flip_coin(ctx): + try: + embed = flip_a_coin.coinToss() + await ctx.send(embed=embed) + + except Exception as e: + print(e) + await ctx.send("Sorry, something went wrong.") + + bot.run(TOKEN) diff --git a/modules/flip_a_coin.py b/modules/flip_a_coin.py new file mode 100644 index 0000000..0e6678b --- /dev/null +++ b/modules/flip_a_coin.py @@ -0,0 +1,33 @@ +import random +import discord + +head_image_url = "https://www.thespecialgiftcompany.com/wp-content/uploads/2017/10/tails-head-coin.jpg" +tail_image_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQrUfZKS5OsMPCEPPQMfRLY8cNGC5Pr8pysA1hP2gvGC75kKaJuVQ" + + +def cointoss(number): + flips = [random.randint(0, 1) for r in range(1)] + results = [] + for object in flips: + if object == 0: + results.append("Heads") + elif object == 1: + results.append("Tails") + + return results + + +def coinToss(): + result = cointoss(1)[0] + + if result == "Heads": + + rembed = discord.Embed( + title=result, type="rich", image=head_image_url + ).set_image(url=head_image_url) + else: + rembed = discord.Embed( + title=result, type="rich", image=tail_image_url + ).set_image(url=tail_image_url) + + return rembed diff --git a/tests/test_pep8.py b/tests/test_pep8.py index 42d650b..1e7ce24 100644 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -1,20 +1,13 @@ import os import unittest -import pep8 +import pycodestyle class TestCodeFormat(unittest.TestCase): def test_pep8_conformance(self): """Test that we conform to PEP8. checks all project files""" errors = 0 - style = pep8.StyleGuide(quiet=False) + style = pycodestyle.StyleGuide(quiet=False) style.options.max_line_length = 120 for root, dirs, files in os.walk('.'): python_files = [os.path.join(root, f) for f in files if f.endswith(".py")] - errors = style.check_files(python_files).total_errors - - self.assertEqual(errors, 0, "PEP8 style errors: %d" % errors) - - -if __name__ == "__main__": - unittest.main() From edb1a6a32b95eb5c606d7759596719445e655711 Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Wed, 29 May 2019 03:13:15 +0530 Subject: [PATCH 02/11] added --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 1e2b7e3..215a67c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ urllib3==1.24.1 wcwidth==0.1.7 websockets==6.0 yarl==1.3.0 +pycodestyle \ No newline at end of file From 85490994f3a4cea6632c4a373667af5c65f8a891 Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 3 Jun 2019 05:28:12 +0200 Subject: [PATCH 03/11] pep8 -> pycodestyle (#12) Resolve #11 * replaced pep8 with pycodestyle * changed pep8 test case * fixed blank line error --- modules/image.py | 1 + requirements.txt | 2 +- tests/test_pep8.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/image.py b/modules/image.py index b02b646..e1ec6a9 100644 --- a/modules/image.py +++ b/modules/image.py @@ -2,6 +2,7 @@ import aiohttp import os + # Searches for a image related to the search arg async def process(search_arg): diff --git a/requirements.txt b/requirements.txt index 1e2b7e3..3e708e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ discord.py==1.1.1 idna==2.8 more-itertools==7.0.0 multidict==4.5.2 -pep8==1.7.1 +pycodestyle==2.5.0 pluggy==0.11.0 py==1.8.0 pytest==4.5.0 diff --git a/tests/test_pep8.py b/tests/test_pep8.py index 42d650b..c7a52ef 100644 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -1,13 +1,13 @@ import os import unittest -import pep8 +import pycodestyle class TestCodeFormat(unittest.TestCase): def test_pep8_conformance(self): """Test that we conform to PEP8. checks all project files""" errors = 0 - style = pep8.StyleGuide(quiet=False) + style = pycodestyle.StyleGuide(quiet=False) style.options.max_line_length = 120 for root, dirs, files in os.walk('.'): python_files = [os.path.join(root, f) for f in files if f.endswith(".py")] From 703c20552015593081fff620bc14ab5880b52d69 Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Wed, 29 May 2019 03:09:28 +0530 Subject: [PATCH 04/11] flip_a_coin added --- .vscode/settings.json | 6 ------ bot.py | 18 +++++++++++++++++- modules/flip_a_coin.py | 33 +++++++++++++++++++++++++++++++++ tests/test_pep8.py | 7 ------- 4 files changed, 50 insertions(+), 14 deletions(-) delete mode 100644 .vscode/settings.json create mode 100644 modules/flip_a_coin.py diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 8f81310..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "python.pythonPath": "venv/bin/python", - "python.linting.pylintEnabled": false, - "python.linting.pep8Enabled": true, - "python.linting.enabled": true -} diff --git a/bot.py b/bot.py index 24a2601..5c624b5 100644 --- a/bot.py +++ b/bot.py @@ -4,7 +4,7 @@ import discord from discord.ext import commands -from modules import xkcd +from modules import xkcd, flip_a_coin TOKEN = os.getenv('DISCORD_BOT_API_TOKEN') bot = commands.Bot(command_prefix='$', description='Just A Rather Very Intelligent System, now on Discord!') @@ -56,4 +56,20 @@ async def search_image(ctx, search_arg): print(e) await ctx.send("Sorry, something went wrong.") + +@bot.command( + name="flip_a_coin", + description="Flip a coin game", + brief="flip a coin and send head to tails", +) +async def flip_coin(ctx): + try: + embed = flip_a_coin.coinToss() + await ctx.send(embed=embed) + + except Exception as e: + print(e) + await ctx.send("Sorry, something went wrong.") + + bot.run(TOKEN) diff --git a/modules/flip_a_coin.py b/modules/flip_a_coin.py new file mode 100644 index 0000000..0e6678b --- /dev/null +++ b/modules/flip_a_coin.py @@ -0,0 +1,33 @@ +import random +import discord + +head_image_url = "https://www.thespecialgiftcompany.com/wp-content/uploads/2017/10/tails-head-coin.jpg" +tail_image_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQrUfZKS5OsMPCEPPQMfRLY8cNGC5Pr8pysA1hP2gvGC75kKaJuVQ" + + +def cointoss(number): + flips = [random.randint(0, 1) for r in range(1)] + results = [] + for object in flips: + if object == 0: + results.append("Heads") + elif object == 1: + results.append("Tails") + + return results + + +def coinToss(): + result = cointoss(1)[0] + + if result == "Heads": + + rembed = discord.Embed( + title=result, type="rich", image=head_image_url + ).set_image(url=head_image_url) + else: + rembed = discord.Embed( + title=result, type="rich", image=tail_image_url + ).set_image(url=tail_image_url) + + return rembed diff --git a/tests/test_pep8.py b/tests/test_pep8.py index c7a52ef..1e7ce24 100644 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -11,10 +11,3 @@ def test_pep8_conformance(self): style.options.max_line_length = 120 for root, dirs, files in os.walk('.'): python_files = [os.path.join(root, f) for f in files if f.endswith(".py")] - errors = style.check_files(python_files).total_errors - - self.assertEqual(errors, 0, "PEP8 style errors: %d" % errors) - - -if __name__ == "__main__": - unittest.main() From 767199d759b175c74c073b9a315e27b40aaf827e Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Wed, 29 May 2019 03:13:15 +0530 Subject: [PATCH 05/11] added --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 3e708e6..68867e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ urllib3==1.24.1 wcwidth==0.1.7 websockets==6.0 yarl==1.3.0 +pycodestyle \ No newline at end of file From 125f91f95326fa06bd584ec1e898f79797f56eab Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Mon, 3 Jun 2019 16:06:44 +0530 Subject: [PATCH 06/11] flip_a_coin renamed to coin --- bot.py | 6 +++--- modules/{flip_a_coin.py => coin.py} | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename modules/{flip_a_coin.py => coin.py} (100%) diff --git a/bot.py b/bot.py index 5c624b5..6e97bc8 100644 --- a/bot.py +++ b/bot.py @@ -4,7 +4,7 @@ import discord from discord.ext import commands -from modules import xkcd, flip_a_coin +from modules import xkcd, coin TOKEN = os.getenv('DISCORD_BOT_API_TOKEN') bot = commands.Bot(command_prefix='$', description='Just A Rather Very Intelligent System, now on Discord!') @@ -58,13 +58,13 @@ async def search_image(ctx, search_arg): @bot.command( - name="flip_a_coin", + name="coin", description="Flip a coin game", brief="flip a coin and send head to tails", ) async def flip_coin(ctx): try: - embed = flip_a_coin.coinToss() + embed = coin.coinToss() await ctx.send(embed=embed) except Exception as e: diff --git a/modules/flip_a_coin.py b/modules/coin.py similarity index 100% rename from modules/flip_a_coin.py rename to modules/coin.py From 1e62c27981f021695d9d48c5308ad0e16981d154 Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Mon, 3 Jun 2019 16:34:14 +0530 Subject: [PATCH 07/11] main formated --- .vscode/settings.json | 3 +++ bot.py | 12 ------------ 2 files changed, 3 insertions(+), 12 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..adf7e3a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3" +} \ No newline at end of file diff --git a/bot.py b/bot.py index 5ee45dd..6e97bc8 100644 --- a/bot.py +++ b/bot.py @@ -4,11 +4,7 @@ import discord from discord.ext import commands -<<<<<<< HEAD from modules import xkcd, coin -======= -from modules import xkcd, flip_a_coin ->>>>>>> 4c18cbb812b0f8beabb76a514b67107dac288796 TOKEN = os.getenv('DISCORD_BOT_API_TOKEN') bot = commands.Bot(command_prefix='$', description='Just A Rather Very Intelligent System, now on Discord!') @@ -62,21 +58,13 @@ async def search_image(ctx, search_arg): @bot.command( -<<<<<<< HEAD name="coin", -======= - name="flip_a_coin", ->>>>>>> 4c18cbb812b0f8beabb76a514b67107dac288796 description="Flip a coin game", brief="flip a coin and send head to tails", ) async def flip_coin(ctx): try: -<<<<<<< HEAD embed = coin.coinToss() -======= - embed = flip_a_coin.coinToss() ->>>>>>> 4c18cbb812b0f8beabb76a514b67107dac288796 await ctx.send(embed=embed) except Exception as e: From 60a773e03b912f7c8d75961cbd1a4a29edf30726 Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Mon, 3 Jun 2019 16:36:34 +0530 Subject: [PATCH 08/11] main formated --- tests/test_pep8.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_pep8.py b/tests/test_pep8.py index 1e7ce24..5e0befe 100644 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -11,3 +11,10 @@ def test_pep8_conformance(self): style.options.max_line_length = 120 for root, dirs, files in os.walk('.'): python_files = [os.path.join(root, f) for f in files if f.endswith(".py")] + errors = style.check_files(python_files).total_errors + + self.assertEqual(errors, 0, "PEP8 style errors: %d" % errors) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From f46228cb7fe4e952c2502f2a8f9ef72ce39a303e Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Wed, 5 Jun 2019 23:49:00 +0530 Subject: [PATCH 09/11] requirement error resolved --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 68867e5..3e708e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,3 @@ urllib3==1.24.1 wcwidth==0.1.7 websockets==6.0 yarl==1.3.0 -pycodestyle \ No newline at end of file From 15e6594db7b8db151175e9506c11c0f21c40884e Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Wed, 5 Jun 2019 23:53:22 +0530 Subject: [PATCH 10/11] coin py error resolved --- modules/coin.py | 4 ++-- tests/test_pep8.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/coin.py b/modules/coin.py index 0e6678b..fe03478 100644 --- a/modules/coin.py +++ b/modules/coin.py @@ -1,8 +1,8 @@ import random import discord -head_image_url = "https://www.thespecialgiftcompany.com/wp-content/uploads/2017/10/tails-head-coin.jpg" -tail_image_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQrUfZKS5OsMPCEPPQMfRLY8cNGC5Pr8pysA1hP2gvGC75kKaJuVQ" +head_image_url = "https://urlzs.com/Wi46z" +tail_image_url = "https://urlzs.com/UXXyP" def cointoss(number): diff --git a/tests/test_pep8.py b/tests/test_pep8.py index 5e0befe..557a71e 100644 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -15,6 +15,5 @@ def test_pep8_conformance(self): self.assertEqual(errors, 0, "PEP8 style errors: %d" % errors) - if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() From e2873d2cd56ff63b76b0bf3beb1f291acddc22af Mon Sep 17 00:00:00 2001 From: Sayan Mondal Date: Wed, 5 Jun 2019 23:54:47 +0530 Subject: [PATCH 11/11] coin py error resolved --- tests/test_pep8.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_pep8.py b/tests/test_pep8.py index 557a71e..c7a52ef 100644 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -15,5 +15,6 @@ def test_pep8_conformance(self): self.assertEqual(errors, 0, "PEP8 style errors: %d" % errors) + if __name__ == "__main__": unittest.main()