Added spoiler and proper file name, fixed ratio and size prompt options
This commit is contained in:
parent
895d250dda
commit
0451c913b2
@ -130,6 +130,7 @@ async def on_message_or_reaction(client, obj):
|
||||
SHOW_REPEAT = settings["show_repeat"]
|
||||
REPEAT_EMOJI = settings["repeat_emoji"]
|
||||
WAITING_EMOJI = settings["waiting_emoji"]
|
||||
USE_SPOILER = settings["use_spoiler"]
|
||||
|
||||
if rxn is not None:
|
||||
if rxn.emoji.name != REPEAT_EMOJI:
|
||||
@ -219,18 +220,21 @@ async def on_message_or_reaction(client, obj):
|
||||
discord_files = []
|
||||
|
||||
for a in attachments_buffer:
|
||||
attachment_filename = get_prompt_filename(msg.content)
|
||||
spoiler_text = "SPOILER_" if USE_SPOILER else ""
|
||||
|
||||
bytes_generated = bytes_generated + len(a)
|
||||
images_generated = images_generated + 1
|
||||
megabytes_uploading = bytes_generated / (1024 * 1024)
|
||||
|
||||
if megabytes_uploading > 4.5:
|
||||
log.write(f"PNG generated is {megabytes_uploading} MB and will be delivered as a JPEG", log.colors.fg.lightred)
|
||||
log.write(f"PNG generated is {megabytes_uploading:0.2f} MB and will be delivered as a JPEG", log.colors.fg.lightred)
|
||||
jpeg_bytes = png_to_jpg(a)
|
||||
discord_file = discord.File(io.BytesIO(jpeg_bytes), filename="file.jpg")
|
||||
discord_file = discord.File(io.BytesIO(jpeg_bytes), filename=f"{spoiler_text}{attachment_filename}.jpg")
|
||||
discord_files.append(discord_file)
|
||||
continue
|
||||
|
||||
discord_file = discord.File(io.BytesIO(a), filename="file.png")
|
||||
discord_file = discord.File(io.BytesIO(a), filename=f"{spoiler_text}{attachment_filename}.png")
|
||||
discord_files.append(discord_file)
|
||||
|
||||
if len(discord_files) < 1:
|
||||
@ -267,6 +271,7 @@ async def on_message_or_reaction(client, obj):
|
||||
"guild_name": chl.guild.name,
|
||||
"channel_id": chl.id,
|
||||
"channel_name": chl.name,
|
||||
"channel_topic": chl.topic,
|
||||
"author_id": author.id,
|
||||
"author_name": get_legacy_username(author),
|
||||
"user_id": user.id,
|
||||
|
@ -1,5 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import random
|
||||
|
||||
# Make it easy to read a json file
|
||||
def read_json(path, default_value={}):
|
||||
@ -54,3 +56,12 @@ def get_legacy_username(obj):
|
||||
if obj.discriminator is not None:
|
||||
discriminator = obj.discriminator
|
||||
return f"{username}#{discriminator}"
|
||||
|
||||
def get_prompt_filename(input_string):
|
||||
output = input_string
|
||||
output = re.sub(r"\s", "_", output)
|
||||
output = re.sub(r"[^A-Za-z0-9_]", "", output)
|
||||
output = re.sub(r"[_]{2,}", "_", output)
|
||||
output = output[:25]
|
||||
output = f"{output}_" + str(random.randint(1000, 9999))
|
||||
return output
|
||||
|
@ -48,13 +48,13 @@ def get_prompt_parameters(user_message, settings):
|
||||
|
||||
|
||||
# Allow user to specify ratio:
|
||||
match = re.search(r"([0-9]{1,2})(x|\:)([0-9]{1,2})", options)
|
||||
match = re.search(r"([0-9\.]{1,5})(x|\:)([0-9\.]{1,5})", options)
|
||||
if match is not None:
|
||||
# Use the smallest dimension for calculations:
|
||||
size = params["width"] if params["width"] <= params["height"] else params["height"]
|
||||
|
||||
r_num = int(match.group(1))
|
||||
r_den = int(match.group(3))
|
||||
r_num = float(match.group(1))
|
||||
r_den = float(match.group(3))
|
||||
|
||||
# Largest dimension not to exceed the size:
|
||||
if r_num > r_den:
|
||||
@ -68,10 +68,10 @@ def get_prompt_parameters(user_message, settings):
|
||||
|
||||
|
||||
# Allow user to explicitly set the size by WWWxHHHp:
|
||||
match = re.search(r"([0-9]{1,})(x)([0-9]{1,})p", options)
|
||||
match = re.search(r"([0-9]{3,})(x)([0-9]{3,})p", options)
|
||||
if match is not None:
|
||||
output["width"] = int(match.group(1))
|
||||
output["height"] = int(match.group(3))
|
||||
params["width"] = int(match.group(1))
|
||||
params["height"] = int(match.group(3))
|
||||
|
||||
|
||||
# Allow all other explicit parameter overrides:
|
||||
|
@ -13,6 +13,7 @@ def get_settings(initialize=False):
|
||||
"show_repeat": True,
|
||||
"repeat_emoji": "♻️",
|
||||
"waiting_emoji": "🕒",
|
||||
"use_spoiler": True,
|
||||
"defaults": {
|
||||
"checkpoint_1": "v1-5-pruned-emaonly.safetensors",
|
||||
"width": 512,
|
||||
|
Loading…
Reference in New Issue
Block a user