Skip to content

Commit

Permalink
Implement pull()
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenzie committed May 15, 2023
1 parent 819c5b2 commit c19693a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
3 changes: 3 additions & 0 deletions common/tarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ def draw(n: int, invert=True, majorminor: MajorMinor = MajorMinor.BOTH) -> List[
"""
deck = make_deck(majorminor)
if n < 1 or n > len(deck):
raise ValueError(f"Number of cards must be between 1 and {len(deck)}")

hand = []
for i in range(n):
mycard = deck[random.randrange(len(deck))]
Expand Down
10 changes: 6 additions & 4 deletions discordbot/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"invert": True,
}

async def handle_generic(interaction: discord.Interaction, numcards, imgfunc, should_inline, reading_type_name):
async def handle_generic(ctx, numcards, imgfunc, should_inline, reading_type_name):
await ctx.defer()
interaction = ctx.interaction
opts = READING_DEFAULTS
gid = str(interaction.guild_id)
uid = str(interaction.user.id)
Expand Down Expand Up @@ -54,10 +56,10 @@ async def handle_generic(interaction: discord.Interaction, numcards, imgfunc, sh
for i, (n,v) in enumerate(response):
message = (message + "\n**" + str(i+1) + ") " +
n + "**\n" + v)
await interaction.response.send_message(content=message, file=file, embed=embed, ephemeral=opts["private"])
await ctx.followup.send(content=message, file=file, embed=embed, ephemeral=opts["private"])

async def handle(interaction: discord.Interaction, reading_type: ReadingType):
await handle_generic(interaction,
async def handle(ctx, reading_type: ReadingType):
await handle_generic(ctx,
reading_type.num,
reading_type.imgfunc,
reading_type in [ReadingType.ONE, ReadingType.THREE],
Expand Down
19 changes: 16 additions & 3 deletions discordbot/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# attempting to switch to pycord because interactions has annoyed me
from math import ceil
import os
from common import layouts
from common.tarot import ReadingType
from dotenv import load_dotenv
import discord
from discordbot.components import ReadingSelectorView, AboutView, SettingsView
from discordbot.handler import handle
from discordbot.handler import handle, handle_generic
import discordbot.makeBackupFile

# TODO update this
Expand Down Expand Up @@ -48,14 +50,25 @@ async def _tarotsettings(ctx):
guild_ids=guild_ids)
async def _about(ctx):
await ctx.respond(help_message, view=AboutView(), ephemeral=True)



@bot.slash_command(name="pull",
description="Pull cards from the deck",
guild_ids=guild_ids)
@discord.option("numcards", description="Number of cards to draw", required=True)
async def _pull(ctx, numcards: int):
for i in range(0, nummsg):
try:
await handle_generic(ctx, numcards, layouts.genericimg, False, "Pull")
except Exception as e:
await ctx.followup.send(e, ephemeral=True)

def addCommand(t):
@bot.slash_command(name=t.id,
description=t.description,
guild_ids=guild_ids)
async def _do_reading(ctx):
await handle(ctx.interaction, t)
await handle(ctx, t)

for t in ReadingType:
addCommand(t)
Expand Down

0 comments on commit c19693a

Please sign in to comment.