2
2
import discord
3
3
from discord import app_commands
4
4
from discord .ext import commands
5
+ import traceback
5
6
6
- from constants import MODELS
7
+ from config import config
7
8
from utils .image_gen_utils import generate_image , validate_dimensions , validate_prompt
8
9
from utils .embed_utils import generate_pollinate_embed , generate_error_message
9
10
from utils .pollinate_utils import parse_url
10
11
from utils .error_handler import send_error_embed
11
12
from exceptions import DimensionTooSmallError , PromptTooLongError , APIError
12
- import traceback
13
13
14
14
15
15
class ImagineButtonView (discord .ui .View ):
@@ -20,7 +20,7 @@ def __init__(self) -> None:
20
20
label = "Regenerate" ,
21
21
style = discord .ButtonStyle .secondary ,
22
22
custom_id = "regenerate-button" ,
23
- emoji = "<:redo:1187101382101180456 >" ,
23
+ emoji = f "<:redo:{ config . bot . emojis [ 'redo_emoji_id' ] } >" ,
24
24
)
25
25
async def regenerate (
26
26
self , interaction : discord .Interaction , button : discord .ui .Button
@@ -29,7 +29,7 @@ async def regenerate(
29
29
embed = discord .Embed (
30
30
title = "Regenerating Your Image" ,
31
31
description = "Please wait while we generate your image" ,
32
- color = discord . Color . blurple ( ),
32
+ color = int ( config . ui . colors . success , 16 ),
33
33
),
34
34
ephemeral = True ,
35
35
)
@@ -49,7 +49,7 @@ async def regenerate(
49
49
embed = discord .Embed (
50
50
title = "Couldn't Generate the Requested Image 😔" ,
51
51
description = f"```\n { e .message } \n ```" ,
52
- color = discord . Color . red ( ),
52
+ color = int ( config . ui . colors . error , 16 ),
53
53
),
54
54
ephemeral = True ,
55
55
)
@@ -60,7 +60,7 @@ async def regenerate(
60
60
embed = discord .Embed (
61
61
title = "Error" ,
62
62
description = f"Error generating image : { e } " ,
63
- color = discord . Color . red ( ),
63
+ color = int ( config . ui . colors . error , 16 ),
64
64
),
65
65
ephemeral = True ,
66
66
)
@@ -86,7 +86,7 @@ async def regenerate(
86
86
@discord .ui .button (
87
87
style = discord .ButtonStyle .red ,
88
88
custom_id = "delete-button" ,
89
- emoji = "<:delete:1187102382312652800 >" ,
89
+ emoji = f "<:delete:{ config . bot . emojis [ 'delete_emoji_id' ] } >" ,
90
90
)
91
91
async def delete (self , interaction : discord .Interaction , button : discord .ui .Button ):
92
92
try :
@@ -99,8 +99,8 @@ async def delete(self, interaction: discord.Interaction, button: discord.ui.Butt
99
99
await interaction .response .send_message (
100
100
embed = discord .Embed (
101
101
title = "Error" ,
102
- description = "You can only delete the images prompted by you" ,
103
- color = discord . Color . red ( ),
102
+ description = config . ui . error_messages [ "delete_unauthorized" ] ,
103
+ color = int ( config . ui . colors . error , 16 ),
104
104
),
105
105
ephemeral = True ,
106
106
)
@@ -114,7 +114,7 @@ async def delete(self, interaction: discord.Interaction, button: discord.ui.Butt
114
114
embed = discord .Embed (
115
115
title = "Error Deleting the Image" ,
116
116
description = f"{ e } " ,
117
- color = discord . Color . red ( ),
117
+ color = int ( config . ui . colors . error , 16 ),
118
118
),
119
119
ephemeral = True ,
120
120
)
@@ -124,7 +124,7 @@ async def delete(self, interaction: discord.Interaction, button: discord.ui.Butt
124
124
label = "Bookmark" ,
125
125
style = discord .ButtonStyle .secondary ,
126
126
custom_id = "bookmark-button" ,
127
- emoji = "<:save:1187101389822902344 >" ,
127
+ emoji = f "<:save:{ config . bot . emojis [ 'save_emoji_id' ] } >" ,
128
128
)
129
129
async def bookmark (
130
130
self , interaction : discord .Interaction , button : discord .ui .Button
@@ -137,7 +137,7 @@ async def bookmark(
137
137
138
138
embed : discord .Embed = discord .Embed (
139
139
description = f"**Prompt : { prompt } **" ,
140
- color = discord . Color . og_blurple ( ),
140
+ color = int ( config . ui . colors . success , 16 ),
141
141
)
142
142
embed .add_field (
143
143
name = "" ,
@@ -152,7 +152,7 @@ async def bookmark(
152
152
embed = discord .Embed (
153
153
title = "Image Bookmarked" ,
154
154
description = "The image has been bookmarked and sent to your DMs" ,
155
- color = discord . Color . blurple ( ),
155
+ color = int ( config . ui . colors . success , 16 ),
156
156
),
157
157
ephemeral = True ,
158
158
)
@@ -164,7 +164,7 @@ async def bookmark(
164
164
embed = discord .Embed (
165
165
title = "Error Bookmarking the Image" ,
166
166
description = f"{ e } " ,
167
- color = discord . Color . red ( ),
167
+ color = int ( config . ui . colors . error , 16 ),
168
168
),
169
169
ephemeral = True ,
170
170
)
@@ -174,17 +174,23 @@ async def bookmark(
174
174
class Imagine (commands .Cog ):
175
175
def __init__ (self , bot ) -> None :
176
176
self .bot = bot
177
+ self .command_config = config .commands ["pollinate" ]
177
178
178
179
async def cog_load (self ) -> None :
179
180
await self .bot .wait_until_ready ()
180
181
self .bot .add_view (ImagineButtonView ())
181
182
182
183
@app_commands .command (name = "pollinate" , description = "Generate AI Images" )
183
184
@app_commands .choices (
184
- model = [app_commands .Choice (name = choice , value = choice ) for choice in MODELS ],
185
+ model = [
186
+ app_commands .Choice (name = choice , value = choice ) for choice in config .MODELS
187
+ ],
185
188
)
186
189
@app_commands .guild_only ()
187
- @app_commands .checks .cooldown (1 , 10 )
190
+ @app_commands .checks .cooldown (
191
+ config .commands ["pollinate" ].cooldown .rate ,
192
+ config .commands ["pollinate" ].cooldown .seconds ,
193
+ )
188
194
@app_commands .describe (
189
195
prompt = "Prompt of the Image you want want to generate" ,
190
196
height = "Height of the Image" ,
@@ -200,22 +206,22 @@ async def imagine_command(
200
206
self ,
201
207
interaction : discord .Interaction ,
202
208
prompt : str ,
203
- width : int = 1000 ,
204
- height : int = 1000 ,
205
- model : app_commands .Choice [str ] = MODELS [0 ],
206
- enhance : bool | None = None ,
207
- safe : bool = False ,
208
- cached : bool = False ,
209
- nologo : bool = False ,
210
- private : bool = False ,
209
+ width : int = config . commands [ "pollinate" ]. default_width ,
210
+ height : int = config . commands [ "pollinate" ]. default_height ,
211
+ model : app_commands .Choice [str ] = config . MODELS [0 ],
212
+ enhance : bool | None = config . image_generation . defaults . enhance ,
213
+ safe : bool = config . image_generation . defaults . safe ,
214
+ cached : bool = config . image_generation . defaults . cached ,
215
+ nologo : bool = config . image_generation . defaults . nologo ,
216
+ private : bool = config . image_generation . defaults . private ,
211
217
) -> None :
212
218
validate_dimensions (width , height )
213
219
validate_prompt (prompt )
214
220
215
221
await interaction .response .defer (thinking = True , ephemeral = private )
216
222
217
223
try :
218
- model = model .value
224
+ model = model .value if model else None
219
225
except Exception :
220
226
pass
221
227
@@ -250,7 +256,9 @@ async def imagine_command_error(
250
256
embed : discord .Embed = await generate_error_message (
251
257
interaction ,
252
258
error ,
253
- cooldown_configuration = ["- 1 time every 10 seconds" ],
259
+ cooldown_configuration = [
260
+ f"- { self .command_config .cooldown .rate } time every { self .command_config .cooldown .seconds } seconds" ,
261
+ ],
254
262
)
255
263
return await interaction .response .send_message (embed = embed , ephemeral = True )
256
264
@@ -277,7 +285,9 @@ async def imagine_command_error(
277
285
278
286
else :
279
287
await send_error_embed (
280
- interaction , "An unexprected error occurred" , f"```\n { str (error )} \n ```"
288
+ interaction ,
289
+ "An unexpected error occurred" ,
290
+ f"```\n { str (error )} \n ```" ,
281
291
)
282
292
283
293
0 commit comments