Skip to content

Commit

Permalink
Merge pull request #170 from crimsobot/image-options-embed
Browse files Browse the repository at this point in the history
Fix image options embed for currents and pingbadge
  • Loading branch information
h-anjru authored Jul 29, 2024
2 parents 7b35005 + 5f13caf commit 91945c2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 45 deletions.
89 changes: 47 additions & 42 deletions crimsobot/cogs/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,34 +255,37 @@ async def currents(self, ctx: commands.Context, image: Optional[str] = None) ->
# ask if the image should be flipped to "face right"
embed = c.crimbed(
title='Flip image?',
descr='\n'.join([
'1. Yes',
'2. No',
]),
footer='You can flip the image to face right.'
descr='You can flip the image to face right.',
footer='Timeout = 10 seconds'
)
prompt = await ctx.send(embed=embed)
await asyncio.sleep(0.36)

options = {'✅': True, '❌': False}

# add reactions to msg
for emoji in options:
await prompt.add_reaction(emoji)
await asyncio.sleep(0.36)

# define check for position vote
def check(msg: discord.Message) -> bool:
try:
valid_choice = 0 < int(msg.content) <= 2
in_channel = msg.channel == ctx.message.channel
is_author = msg.author == ctx.message.author
return valid_choice and in_channel and is_author
except ValueError:
return False
def check(reaction: discord.Reaction, user: discord.User) -> bool:
is_author = user == ctx.message.author
is_msg = reaction.message.id == prompt.id
is_valid = reaction.emoji in options

return is_author and is_msg and is_valid

# define default position, listen for user to specify different one
msg = await self.bot.wait_for('message', check=check, timeout=15)
if msg is None:
flip = 2
else:
flip = int(msg.content)
try:
reaction = await self.bot.wait_for('reaction_add', check=check, timeout=10)
flip = options[reaction[0].emoji]

except asyncio.TimeoutError:
flip = False

# delete prompt and vote, send image
if msg is not None:
await msg.delete()
await asyncio.sleep(0.36)
await prompt.delete()

effect = 'currents'
Expand Down Expand Up @@ -452,38 +455,40 @@ async def pingbadge(self, ctx: commands.Context, image: Optional[str] = None) ->
if image is None:
image = await self.get_previous_image(ctx) # will be a URL

# ask if the image should be flipped to "face right"
embed = c.crimbed(
title='Choose a corner:',
descr='\n'.join([
'1. Top left',
'2. Top right',
'3. Bottom left',
'4. Bottom right',
]),
thumb_name='https://i.imgur.com/cgGKghX.png',
title='Pick a corner!',
descr='Use the arrows to select a corner.',
footer='Timeout = 10 seconds'
)
prompt = await ctx.send(embed=embed)
await asyncio.sleep(0.36)

options = {'↖️': 1, '↗️': 2, '↙️': 3, '↘️': 4}

# add reactions to msg
for emoji in options:
await prompt.add_reaction(emoji)
await asyncio.sleep(0.36)

# define check for position vote
def check(msg: discord.Message) -> bool:
try:
valid_choice = 0 < int(msg.content) <= 4
in_channel = msg.channel == ctx.message.channel
is_author = msg.author == ctx.message.author
return valid_choice and in_channel and is_author
except ValueError:
return False
def check(reaction: discord.Reaction, user: discord.User) -> bool:
is_author = user == ctx.message.author
is_msg = reaction.message.id == prompt.id
is_valid = reaction.emoji in options

return is_author and is_msg and is_valid

# define default position, listen for user to specify different one
msg = await self.bot.wait_for('message', check=check, timeout=15)
if msg is None:
try:
reaction = await self.bot.wait_for('reaction_add', check=check, timeout=10)
position = options[reaction[0].emoji]

except asyncio.TimeoutError:
position = 4
else:
position = int(msg.content)

# delete prompt and vote, send image
if msg is not None:
await msg.delete()
await asyncio.sleep(0.36)
await prompt.delete()

effect = 'pingbadge'
Expand Down
2 changes: 1 addition & 1 deletion crimsobot/data/img/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ currents:
- Does it really fucking matter, babe?
- I've heard these words before
- And suddenly I'm the phony one
- Feel like a brand new person (but you'll make hte same old mistakes)
- Feel like a brand new person (but you'll make the same old mistakes)
- Well I don't care, I'm in love
- Maybe fake's what I like
lateralus:
Expand Down
4 changes: 2 additions & 2 deletions crimsobot/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,10 @@ def make_captioned_img(img: Image.Image, caption_list: List[str]) -> Image.Image
return final_image


def make_currents_img(img: Image.Image, flip: int) -> Image.Image:
def make_currents_img(img: Image.Image, flip: bool) -> Image.Image:
img = img.convert('RGBA')

if flip == 1:
if flip is True:
img = img.transpose(Image.FLIP_LEFT_RIGHT)

# 1. determine user image size, resize to fit in its place
Expand Down

0 comments on commit 91945c2

Please sign in to comment.