Skip to content

Commit

Permalink
Merge pull request #174 from crimsobot/aeroplane-cover
Browse files Browse the repository at this point in the history
In the Aeroplane Over the Sea cover maker; GIF processing in DMs
  • Loading branch information
h-anjru authored Jul 31, 2024
2 parents 1b1f14e + 634f5e1 commit 02e1750
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
14 changes: 13 additions & 1 deletion crimsobot/cogs/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from discord.ext import commands

from crimsobot.bot import CrimsoBOT
from crimsobot.data.img import AENIMA, CAPTION_RULES, CURRENTS, IMAGE_RULES, LATERALUS, URL_CONTAINS
from crimsobot.data.img import AENIMA, AEROPLANE, CAPTION_RULES, CURRENTS, IMAGE_RULES, LATERALUS, URL_CONTAINS
from crimsobot.exceptions import BadCaption, NoImageFound
from crimsobot.utils import image as imagetools, tools as c

Expand Down Expand Up @@ -174,6 +174,18 @@ async def aenima(self, ctx: commands.Context, image: Optional[str] = None) -> No

await self.get_image_and_embed(ctx, image, effect, None, title)

@commands.command()
async def aeroplane(self, ctx: commands.Context, image: Optional[str] = None) -> None:
"""Make a new cover for ITAOTS."""

effect = 'aeroplane'
title = random.choice(AEROPLANE)

if image is None:
image = await self.get_previous_image(ctx) # will be a URL

await self.get_image_and_embed(ctx, image, effect, None, title)

@commands.command(hidden=True)
@commands.cooldown(1, 4 * 60 * 60, commands.BucketType.user)
@shared_max_concurrency(eface_bucket)
Expand Down
1 change: 1 addition & 0 deletions crimsobot/data/img/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
EIMG_WIDTH = _EIMG_RULES['width']

AENIMA = _ruleset['aenima']
AEROPLANE = _ruleset['aeroplane']
CURRENTS = _ruleset['currents']
LATERALUS = _ruleset['lateralus']

Expand Down
Binary file added crimsobot/data/img/aeroplane_cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions crimsobot/data/img/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,34 @@ aenima:
- Dreaming of that fix again
- So good to see you once again
- Blue as our new second sun
aeroplane:
- When you were young you were the king of carrot flowers
- And from above you how I sank into your soul
- Each one a little more than he would dare to try
- I love you, Jesus Christ
- I will float until I learn how to swim
- Mouths open wide and spitting snow
- What a beautiful face I have found in this place
- Soft and sweet
- Count every beautiful thing we can see
- Two-headed boy all floating in glass
- I am listening to hear where you are
- Catching signals that sound in the dark
- Playing pianos filled with flames
- The Earth looks better from a star
- He didn't mean to make you cry
- Cars careening from the clouds
- Sweet communist, the communist daughter
- Wanting something warm and moving
- Oh, comely
- With some pretty, bright and bubbly terrible scene
- In your memory, you're drunk on your awe to me
- She was born in a bottle-rocket in 1929
- All drenched in milk and holy water pouring from the sky
- I know you live within me, feel as you fly
- Blister, please, with those wings in your spine
- Secret songs that you keep wrapped in boxes so tight
- Your brains fell out through your teeth
currents:
- All this running around
- Just let it happen
Expand Down
35 changes: 32 additions & 3 deletions crimsobot/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def make_aenima_img(img: Image.Image, arg: None) -> Image.Image:
width, height = img.size

# 2. paste over white bg
bg = Image.new('RGBA', (500, 500), (255, 255, 255, 255))
bg = Image.new('RGBA', (500, 500), (240, 230, 190, 255))
position = int(250 - height/2)
bg.paste(img, (163, position), img)

Expand All @@ -426,6 +426,35 @@ def make_aenima_img(img: Image.Image, arg: None) -> Image.Image:
return bg


def make_aeroplane_img(img: Image.Image, arg: None) -> Image.Image:
# 1. determine user image size, resize to fit in its place
width, height = img.size

# resize to hole opening (141 x 160)
if height > width:
ratio = width / 141
else:
ratio = height / 160

img = img.resize((int(width / ratio), int(height / ratio)), resample=Image.BICUBIC)

# get new size
width, height = img.size

# 2. calculate position of image, centered over hole
corner = 406 - width // 2, 147 - height // 2

# 3. paste over cream white bg
bg = Image.new('RGBA', (600, 600), (240, 230, 190, 255))
bg.paste(img, corner, img)

# 4. paste cover over result
with Image.open(c.clib_path_join('img', 'aeroplane_cover.png')) as cover:
bg.alpha_composite(cover, (0, 0))

return bg


def make_captioned_img(img: Image.Image, caption_list: List[str]) -> Image.Image:
"""Captions an image!"""
# 1. determine image size, resize to standardize text addition
Expand Down Expand Up @@ -690,6 +719,7 @@ def process_lower_level(img: Image.Image, effect: str, arg: int) -> BytesIO:
function_dict: Mapping[str, Callable] = {
'acid': make_acid_img,
'aenima': make_aenima_img,
'aeroplane': make_aeroplane_img,
'caption': make_captioned_img,
'currents': make_currents_img,
'lateralus': make_lateralus_img,
Expand Down Expand Up @@ -752,9 +782,8 @@ async def process_image(ctx: Context, image: Optional[str], effect: str, arg: Op
return None, None

else:
# debit the user, credit the bot
# debit the user
await crimsogames.win(ctx.author, -cost)
await crimsogames.win(ctx.guild.me, cost)
new_bal = await crimsogames.check_balance(ctx.author)

# this embed will keep user updated on processing status; will be edited below as it progresses
Expand Down

0 comments on commit 02e1750

Please sign in to comment.