Skip to content

Commit

Permalink
Merge pull request #252 from Kilvoctu/fix-at
Browse files Browse the repository at this point in the history
fix who is @'d when using buttons
  • Loading branch information
Kilvoctu authored Mar 5, 2024
2 parents c61ac11 + a12e97d commit 1b17f17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
11 changes: 7 additions & 4 deletions core/stablecog.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,10 @@ def dream(self, event_loop: queuehandler.GlobalQueue.event_loop, queue_object: q
queue_object.view.input_tuple = new_tuple

# set up discord message
content = f'> for {queue_object.ctx.author.name}'
try:
user_id = queue_object.ctx.author.id
except(Exception,):
user_id = queue_object.ctx.user.id
noun_descriptor = "drawing" if image_count == 1 else f'{image_count} drawings'
draw_time = '{0:.3f}'.format(end_time - start_time)
message = f'my {noun_descriptor} of ``{queue_object.simple_prompt}`` took me ``{draw_time}`` seconds!'
Expand Down Expand Up @@ -579,10 +582,10 @@ def dream(self, event_loop: queuehandler.GlobalQueue.event_loop, queue_object: q
filename = f'SPOILER_{queue_object.seed}-{count}.png'
file = add_metadata_to_image(grid, images[current_grid * 25][2], filename)
if current_grid == 0:
content = f'<@{queue_object.ctx.author.id}>, {message}\n ' \
content = f'<@{user_id}>, {message}\n ' \
f'Batch ID: {epoch_time}-{queue_object.seed}\n Image IDs: {id_start}-{id_end}'
else:
content = f'> for {queue_object.ctx.author.name}, ' \
content = f'> for {user_id}, ' \
f'use /info or context menu to retrieve.\n ' \
f'Batch ID: {epoch_time}-{queue_object.seed}\n Image IDs: {id_start}-{id_end}'
view = None
Expand All @@ -594,7 +597,7 @@ def dream(self, event_loop: queuehandler.GlobalQueue.event_loop, queue_object: q
self, queue_object.ctx, content=content, file=file, embed='', view=view))

else:
content = f'<@{queue_object.ctx.author.id}>, {message}'
content = f'<@{user_id}>, {message}'
filename = f'{queue_object.seed}-{count}.png'
if queue_object.spoiler:
filename = f'SPOILER_{queue_object.seed}-{count}.png'
Expand Down
6 changes: 5 additions & 1 deletion core/upscalecog.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,14 @@ def post_dream():
draw_time = '{0:.3f}'.format(end_time - start_time)
message = f'my upscale of ``{queue_object.resize}``x took me ``{draw_time}`` seconds!'
file = discord.File(fp=buffer, filename=f'{self.file_name[0:120]}-{queue_object.resize}.png')
try:
user_id = queue_object.ctx.author.id
except(Exception,):
user_id = queue_object.ctx.user.id

queuehandler.process_post(
self, queuehandler.PostObject(
self, queue_object.ctx, content=f'<@{queue_object.ctx.author.id}>, {message}', file=file, embed='', view=queue_object.view))
self, queue_object.ctx, content=f'<@{user_id}>, {message}', file=file, embed='', view=queue_object.view))
Thread(target=post_dream, daemon=True).start()

except Exception as e:
Expand Down
12 changes: 7 additions & 5 deletions core/viewhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ async def callback(self, interaction: discord.Interaction):
pen[13] = [1, 1]

# the updated tuple to send to queue
pen[0] = interaction
prompt_tuple = tuple(pen)
draw_dream = stablecog.StableCog(self)

Expand All @@ -290,7 +291,7 @@ async def callback(self, interaction: discord.Interaction):
elif str(pen[18]) != str(self.input_tuple[18]):
prompt_output += f'\nNew extra network: ``{pen[18]}``'

print(f'Redraw -- {interaction.user.name}#{interaction.user.discriminator} -- Prompt: {pen[1]}')
print(f'Redraw -- {interaction.user.name} -- Prompt: {pen[1]}')

# check queue again, but now we know user is not in queue
if queuehandler.GlobalQueue.dream_thread.is_alive():
Expand Down Expand Up @@ -360,13 +361,14 @@ async def button_roll(self, button, interaction):
if buttons_free:
# update the tuple with a new seed
new_seed = list(self.input_tuple)
new_seed[0] = interaction
new_seed[10] = random.randint(0, 0xFFFFFFFF)
# set batch to 1
if settings.global_var.batch_buttons == "False":
new_seed[13] = [1, 1]
seed_tuple = tuple(new_seed)

print(f'Reroll -- {interaction.user.name}#{interaction.user.discriminator} -- Prompt: {seed_tuple[1]}')
print(f'Reroll -- {interaction.user.name} -- Prompt: {seed_tuple[1]}')

# set up the draw dream and do queue code again for lack of a more elegant solution
draw_dream = stablecog.StableCog(self)
Expand Down Expand Up @@ -411,13 +413,13 @@ async def button_upscale(self, button, interaction):
await interaction.response.send_message("Use the drop down menu to upscale batch images!", ephemeral=True) # tell user to use dropdown for upscaling
else:
init_image = self.message.attachments[0]
ctx = self.input_tuple[0]
ctx = interaction
channel = '% s' % ctx.channel.id
settings.check(channel)
upscaler_1 = settings.read(channel)['upscaler_1']
upscale_tuple = (ctx, '2.0', init_image, upscaler_1, "None", '0.5', '0.0', '0.0', False) # Create defaults for upscale. If desired we can add options to the per channel upscale settings for this.

print(f'Upscaling -- {interaction.user.name}#{interaction.user.discriminator}')
print(f'Upscaling -- {interaction.user.name}')

# set up the draw dream and do queue code again for lack of a more elegant solution
draw_dream = upscalecog.UpscaleCog(self)
Expand Down Expand Up @@ -568,7 +570,7 @@ async def callback(self, interaction: discord.Interaction):
upscaler_1 = settings.read(channel)['upscaler_1']
upscale_tuple = (ctx, '2.0', init_image, upscaler_1, "None", '0.5', '0.0', '0.0', False) # Create defaults for upscale. If desired we can add options to the per channel upscale settings for this.

print(f'Upscaling -- {interaction.user.name}#{interaction.user.discriminator}')
print(f'Upscaling -- {interaction.user.name}')

# set up the draw dream and do queue code again for lack of a more elegant solution
draw_dream = upscalecog.UpscaleCog(self)
Expand Down

0 comments on commit 1b17f17

Please sign in to comment.