-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
FoD Food War Commands (#512)
* wip * eraser wipe frames * fade in and out * eraser wipe in place * zero draw frames * final polish * lil tweaks to nexttrek and cornmander
- agimus-v2.13.3
- agimus-v2.13.2
- agimus-v2.13.0
- agimus-v2.12.18
- agimus-v2.12.17
- agimus-v2.12.16
- agimus-v2.12.15
- agimus-v2.12.14
- agimus-v2.12.13
- agimus-v2.12.11
- agimus-v2.12.8
- agimus-v2.12.7
- agimus-v2.12.6
- agimus-v2.12.5
- agimus-v2.12.4
- agimus-v2.12.3
- agimus-v2.12.2
- agimus-v2.12.1
- agimus-v2.12.0
- agimus-v2.11.20
- agimus-v2.11.19
- agimus-v2.11.18
- agimus-v2.11.16
- agimus-v2.11.15
- agimus-v2.11.14
- agimus-v2.11.13
- agimus-v2.11.12
- agimus-v2.11.11
- agimus-v2.11.10
- agimus-v2.11.9
- agimus-v2.11.8
- agimus-v2.11.7
- agimus-v2.11.6
- agimus-v2.11.5
- agimus-v2.11.4
- agimus-v2.11.3
- agimus-v2.11.2
- agimus-v2.11.1
- agimus-v2.11.0
- agimus-v2.10.28
- agimus-v2.10.27
- agimus-v2.10.26
- agimus-v2.10.25
- agimus-v2.10.24
- agimus-v2.10.23
- agimus-v2.10.22
- agimus-v2.10.21
- agimus-v2.10.20
- agimus-v2.10.19
- agimus-v2.10.18
- agimus-v2.10.17
- agimus-v2.10.16
- agimus-v2.10.15
- agimus-v2.10.14
- agimus-v2.10.13
- agimus-v2.10.12
- agimus-v2.10.11
- agimus-v2.10.10
- agimus-v2.10.9
- agimus-v2.10.8
- agimus-v2.10.7
- agimus-v2.10.6
- agimus-v2.10.5
- agimus-v2.10.4
- agimus-v2.10.3
- agimus-v2.10.2
- agimus-v2.10.1
- agimus-v2.10.0
- agimus-v2.9.4
- agimus-v2.9.3
- agimus-v2.9.2
- agimus-v2.9.1
- agimus-v2.9.0
- agimus-v2.8.8
- agimus-v2.8.7
- agimus-v2.8.6
- agimus-v2.8.5
- agimus-v2.8.4
- agimus-v2.8.3
- agimus-v2.8.2
- agimus-v2.8.1
- agimus-v2.8.0
- agimus-v2.7.25
- agimus-v2.7.24
- agimus-v2.7.23
- agimus-v2.7.22
- agimus-v2.7.21
- agimus-v2.7.20
- agimus-v2.7.19
- agimus-v2.7.18
- agimus-v2.7.17
1 parent
9b3f8f1
commit 6b5efca
Showing
81 changed files
with
334 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,253 @@ | ||
import time | ||
import pytz | ||
|
||
from common import * | ||
from utils.check_channel_access import access_check | ||
|
||
|
||
# Create drop Slash Command Group | ||
food_war = bot.create_group("food_war", "FoD Food War Commands!") | ||
|
||
@food_war.command( | ||
name="reset", | ||
description="Reset the days since last FoD Food War", | ||
) | ||
@option( | ||
name="reason", | ||
description="Reason for reset?", | ||
required=True, | ||
min_length=1, | ||
max_length=64 | ||
) | ||
@commands.check(access_check) | ||
async def reset(ctx:discord.ApplicationContext, reason:str): | ||
await ctx.defer() | ||
|
||
previous_reset = db_get_previous_reset() | ||
|
||
embed = discord.Embed( | ||
title="Resetting Days Since Last FoD Food War...", | ||
description=f"{ctx.author.mention} is resetting the clock!", | ||
color=discord.Color.gold() | ||
) | ||
embed.add_field( | ||
name="Reason", | ||
value=reason, | ||
inline=False | ||
) | ||
if previous_reset: | ||
pst_tz = pytz.timezone('America/Los_Angeles') | ||
raw_now = datetime.utcnow().replace(tzinfo=pytz.utc) | ||
raw_time_created = pytz.utc.localize(previous_reset['time_created']) | ||
aware_now = pst_tz.normalize(raw_now.astimezone(pst_tz)) | ||
aware_time_created = pst_tz.normalize(raw_time_created.astimezone(pst_tz)) | ||
|
||
lifespan = aware_now - aware_time_created | ||
days = lifespan.days | ||
|
||
embed.add_field( | ||
name="Previous Days", | ||
value=f"{days} {'Day' if days == 1 else 'Days'}", | ||
) | ||
embed.add_field( | ||
name=f"Previous Reason", | ||
value=previous_reset['reason'], | ||
) | ||
else: | ||
days = 0 | ||
|
||
db_reset_days(ctx.author.id, reason, days) | ||
|
||
gif = await generate_food_war_reset_gif(days) | ||
embed.set_image(url=f"attachment://{gif.filename}") | ||
embed.set_footer(text="Again!? 💣") | ||
await ctx.followup.send(embed=embed, file=gif) | ||
|
||
|
||
@food_war.command( | ||
name="check", | ||
description="Check how many days it's been since last FoD Food War", | ||
) | ||
@commands.check(access_check) | ||
async def check(ctx:discord.ApplicationContext): | ||
previous_reset = db_get_previous_reset() | ||
|
||
if not previous_reset: | ||
await ctx.respond( | ||
embed=discord.Embed( | ||
title="No Wars Registered Yet!", | ||
color=discord.Color.red() | ||
), | ||
ephemeral=True | ||
) | ||
return | ||
|
||
await ctx.defer() | ||
|
||
pst_tz = pytz.timezone('America/Los_Angeles') | ||
raw_now = datetime.utcnow().replace(tzinfo=pytz.utc) | ||
raw_time_created = pytz.utc.localize(previous_reset['time_created']) | ||
aware_now = pst_tz.normalize(raw_now.astimezone(pst_tz)) | ||
aware_time_created = pst_tz.normalize(raw_time_created.astimezone(pst_tz)) | ||
|
||
lifespan = aware_now - aware_time_created | ||
days = lifespan.days | ||
|
||
embed = discord.Embed( | ||
title=f"The Last FoD Food War...", | ||
description=f"was {days} {'Day' if days == 1 else 'Days'} ago...", | ||
color=discord.Color.gold() | ||
) | ||
|
||
embed.add_field( | ||
name="Previous Days Streak", | ||
value=f"{previous_reset['days']} {'Day' if previous_reset['days'] == 1 else 'Days'}", | ||
) | ||
embed.add_field( | ||
name=f"Previous Reason", | ||
value=previous_reset['reason'], | ||
) | ||
|
||
longest_reset = db_get_longest_reset() | ||
if previous_reset['id'] == longest_reset['id']: | ||
embed.add_field( | ||
name="All-Time Longest Streak Was The Previous!", | ||
value=f"Holy Guacamole! 🥑", | ||
inline=False | ||
) | ||
else: | ||
embed.add_field( | ||
name="All-Time Longest Streak", | ||
value=f"{longest_reset['days']} {'Day' if longest_reset['days'] == 1 else 'Days'}", | ||
inline=False | ||
) | ||
embed.add_field( | ||
name=f"All-Time Longest Streak Reason", | ||
value=longest_reset['reason'], | ||
inline=False | ||
) | ||
|
||
png = await generate_food_war_check_png(days) | ||
embed.set_image(url=f"attachment://{png.filename}") | ||
embed.set_footer(text="We can only hope it shall last longer... 🥑 ⚔️ 🙏") | ||
await ctx.followup.send(embed=embed, file=png) | ||
|
||
|
||
@to_thread | ||
def generate_food_war_check_png(days): | ||
marker_font = ImageFont.truetype("fonts/PermanentMarker.ttf", 200) | ||
|
||
base_width = 600 | ||
base_height = 775 | ||
|
||
food_war_sign_image = Image.open("./images/templates/food_war/blank_sign.png").convert("RGBA") | ||
food_war_base_image = Image.new("RGBA", (base_width, base_height), (0, 0, 0)) | ||
food_war_base_image.paste(food_war_sign_image, (0, 0)) | ||
|
||
d = ImageDraw.Draw(food_war_base_image) | ||
d.text( (base_width/2, 200), f"{days}", fill=(0, 0, 0, 255), font=marker_font, anchor="mm", align="center") | ||
|
||
image_filename = "current_days.png" | ||
image_filepath = f"./images/food_war/{image_filename}" | ||
if os.path.exists(image_filepath): | ||
os.remove(image_filepath) | ||
|
||
food_war_base_image.save(image_filepath) | ||
|
||
while True: | ||
time.sleep(0.05) | ||
if os.path.isfile(image_filepath): | ||
break | ||
|
||
discord_image = discord.File(fp=image_filepath, filename=image_filename) | ||
return discord_image | ||
|
||
@to_thread | ||
def generate_food_war_reset_gif(days): | ||
marker_font = ImageFont.truetype("fonts/PermanentMarker.ttf", 200) | ||
|
||
base_width = 600 | ||
base_height = 775 | ||
|
||
food_war_sign_image = Image.open("./images/templates/food_war/blank_sign.png").convert("RGBA") | ||
food_war_base_image = Image.new("RGBA", (base_width, base_height), (0, 0, 0)) | ||
food_war_base_image.paste(food_war_sign_image, (0, 0)) | ||
|
||
base_text_frame = food_war_base_image.copy() | ||
d = ImageDraw.Draw(base_text_frame) | ||
d.text( (base_width/2, 200), f"{days}", fill=(0, 0, 0, 255), font=marker_font, anchor="mm", align="center") | ||
frames = [base_text_frame]*20 | ||
|
||
# Eraser Wipe | ||
for n in range(0, 54): | ||
frame = base_text_frame.copy() | ||
wipe_frame = Image.open(f"./images/templates/food_war/wipe/{'{:02d}'.format(n)}.png").convert('RGBA') | ||
frame.paste(wipe_frame, (110, 85), wipe_frame) | ||
frames.append(frame) | ||
|
||
# Blank Frames | ||
blank_frame = food_war_base_image.copy() | ||
frames = frames + [blank_frame]*10 | ||
|
||
# Draw Zero | ||
for n in range(0, 13): | ||
frame = blank_frame.copy() | ||
draw_frame = Image.open(f"./images/templates/food_war/draw/{'{:02d}'.format(n)}.png").convert('RGBA') | ||
frame.paste(draw_frame, (110, 85), draw_frame) | ||
frames.append(frame) | ||
|
||
if n == 12: | ||
frames = frames + [frame]*30 | ||
|
||
# Save | ||
image_filename = "days_since_last_fod_food_war.gif" | ||
image_filepath = f"./images/food_war/{image_filename}" | ||
if os.path.exists(image_filepath): | ||
os.remove(image_filepath) | ||
|
||
frames[0].save( | ||
image_filepath, | ||
save_all=True, append_images=frames[1:], optimize=False, duration=40, loop=0 | ||
) | ||
|
||
while True: | ||
time.sleep(0.05) | ||
if os.path.isfile(image_filepath): | ||
break | ||
|
||
discord_image = discord.File(fp=image_filepath, filename=image_filename) | ||
return discord_image | ||
|
||
|
||
def db_get_previous_reset(): | ||
with AgimusDB(dictionary=True) as query: | ||
sql = "SELECT * FROM food_war ORDER BY id DESC LIMIT 1" | ||
query.execute(sql) | ||
previous_reset = query.fetchone() | ||
return previous_reset | ||
|
||
def db_reset_days(user_discord_id, reason, days): | ||
with AgimusDB(dictionary=True) as query: | ||
sql = "INSERT INTO food_war (user_discord_id, reason, days) VALUES (%s, %s, %s)" | ||
vals = (user_discord_id, reason, days) | ||
query.execute(sql, vals) | ||
|
||
def db_get_longest_reset(): | ||
with AgimusDB(dictionary=True) as query: | ||
sql = ''' | ||
SELECT fw.* | ||
FROM (select fw.*, | ||
(SELECT time_created | ||
FROM food_war fw2 | ||
WHERE fw2.time_created > fw.time_created | ||
ORDER BY time_created | ||
LIMIT 1 | ||
) AS next_time_created | ||
FROM food_war fw | ||
) fw | ||
ORDER BY timestampdiff(second, time_created, next_time_created) DESC | ||
LIMIT 1; | ||
''' | ||
query.execute(sql) | ||
longest_reset = query.fetchone() | ||
return longest_reset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.