Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flip_a_coin added #15

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

18 changes: 17 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import discord
from discord.ext import commands
from modules import xkcd
from modules import xkcd, flip_a_coin
sayanmondal2098 marked this conversation as resolved.
Show resolved Hide resolved

TOKEN = os.getenv('DISCORD_BOT_API_TOKEN')
bot = commands.Bot(command_prefix='$', description='Just A Rather Very Intelligent System, now on Discord!')
Expand Down Expand Up @@ -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)
33 changes: 33 additions & 0 deletions modules/flip_a_coin.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ urllib3==1.24.1
wcwidth==0.1.7
websockets==6.0
yarl==1.3.0
pycodestyle
11 changes: 2 additions & 9 deletions tests/test_pep8.py
Original file line number Diff line number Diff line change
@@ -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()