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

Coin flip renamed #19

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
7 changes: 2 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"python.pythonPath": "venv/bin/python",
"python.linting.pylintEnabled": false,
"python.linting.pep8Enabled": true,
"python.linting.enabled": true
}
"python.pythonPath": "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3"
}
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, coin

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="coin",
description="Flip a coin game",
brief="flip a coin and send head to tails",
)
async def flip_coin(ctx):
try:
embed = 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/coin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import random
import discord

head_image_url = "https://urlzs.com/Wi46z"
tail_image_url = "https://urlzs.com/UXXyP"


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