22import discord
33from discord import app_commands
44from discord .ext import commands
5+ import traceback
56
6- from constants import MODELS
7+ from config import config
78from utils .image_gen_utils import generate_image , validate_dimensions , validate_prompt
89from utils .embed_utils import generate_pollinate_embed , generate_error_message
910from utils .pollinate_utils import parse_url
1011from utils .error_handler import send_error_embed
1112from exceptions import DimensionTooSmallError , PromptTooLongError , APIError
12- import traceback
1313
1414
1515class ImagineButtonView (discord .ui .View ):
@@ -20,7 +20,7 @@ def __init__(self) -> None:
2020 label = "Regenerate" ,
2121 style = discord .ButtonStyle .secondary ,
2222 custom_id = "regenerate-button" ,
23- emoji = "<:redo:1187101382101180456 >" ,
23+ emoji = f "<:redo:{ config . bot . emojis [ 'redo_emoji_id' ] } >" ,
2424 )
2525 async def regenerate (
2626 self , interaction : discord .Interaction , button : discord .ui .Button
@@ -29,7 +29,7 @@ async def regenerate(
2929 embed = discord .Embed (
3030 title = "Regenerating Your Image" ,
3131 description = "Please wait while we generate your image" ,
32- color = discord . Color . blurple ( ),
32+ color = int ( config . ui . colors . success , 16 ),
3333 ),
3434 ephemeral = True ,
3535 )
@@ -49,7 +49,7 @@ async def regenerate(
4949 embed = discord .Embed (
5050 title = "Couldn't Generate the Requested Image 😔" ,
5151 description = f"```\n { e .message } \n ```" ,
52- color = discord . Color . red ( ),
52+ color = int ( config . ui . colors . error , 16 ),
5353 ),
5454 ephemeral = True ,
5555 )
@@ -60,7 +60,7 @@ async def regenerate(
6060 embed = discord .Embed (
6161 title = "Error" ,
6262 description = f"Error generating image : { e } " ,
63- color = discord . Color . red ( ),
63+ color = int ( config . ui . colors . error , 16 ),
6464 ),
6565 ephemeral = True ,
6666 )
@@ -86,7 +86,7 @@ async def regenerate(
8686 @discord .ui .button (
8787 style = discord .ButtonStyle .red ,
8888 custom_id = "delete-button" ,
89- emoji = "<:delete:1187102382312652800 >" ,
89+ emoji = f "<:delete:{ config . bot . emojis [ 'delete_emoji_id' ] } >" ,
9090 )
9191 async def delete (self , interaction : discord .Interaction , button : discord .ui .Button ):
9292 try :
@@ -99,8 +99,8 @@ async def delete(self, interaction: discord.Interaction, button: discord.ui.Butt
9999 await interaction .response .send_message (
100100 embed = discord .Embed (
101101 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 ),
104104 ),
105105 ephemeral = True ,
106106 )
@@ -114,7 +114,7 @@ async def delete(self, interaction: discord.Interaction, button: discord.ui.Butt
114114 embed = discord .Embed (
115115 title = "Error Deleting the Image" ,
116116 description = f"{ e } " ,
117- color = discord . Color . red ( ),
117+ color = int ( config . ui . colors . error , 16 ),
118118 ),
119119 ephemeral = True ,
120120 )
@@ -124,7 +124,7 @@ async def delete(self, interaction: discord.Interaction, button: discord.ui.Butt
124124 label = "Bookmark" ,
125125 style = discord .ButtonStyle .secondary ,
126126 custom_id = "bookmark-button" ,
127- emoji = "<:save:1187101389822902344 >" ,
127+ emoji = f "<:save:{ config . bot . emojis [ 'save_emoji_id' ] } >" ,
128128 )
129129 async def bookmark (
130130 self , interaction : discord .Interaction , button : discord .ui .Button
@@ -137,7 +137,7 @@ async def bookmark(
137137
138138 embed : discord .Embed = discord .Embed (
139139 description = f"**Prompt : { prompt } **" ,
140- color = discord . Color . og_blurple ( ),
140+ color = int ( config . ui . colors . success , 16 ),
141141 )
142142 embed .add_field (
143143 name = "" ,
@@ -152,7 +152,7 @@ async def bookmark(
152152 embed = discord .Embed (
153153 title = "Image Bookmarked" ,
154154 description = "The image has been bookmarked and sent to your DMs" ,
155- color = discord . Color . blurple ( ),
155+ color = int ( config . ui . colors . success , 16 ),
156156 ),
157157 ephemeral = True ,
158158 )
@@ -164,7 +164,7 @@ async def bookmark(
164164 embed = discord .Embed (
165165 title = "Error Bookmarking the Image" ,
166166 description = f"{ e } " ,
167- color = discord . Color . red ( ),
167+ color = int ( config . ui . colors . error , 16 ),
168168 ),
169169 ephemeral = True ,
170170 )
@@ -174,17 +174,23 @@ async def bookmark(
174174class Imagine (commands .Cog ):
175175 def __init__ (self , bot ) -> None :
176176 self .bot = bot
177+ self .command_config = config .commands ["pollinate" ]
177178
178179 async def cog_load (self ) -> None :
179180 await self .bot .wait_until_ready ()
180181 self .bot .add_view (ImagineButtonView ())
181182
182183 @app_commands .command (name = "pollinate" , description = "Generate AI Images" )
183184 @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+ ],
185188 )
186189 @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+ )
188194 @app_commands .describe (
189195 prompt = "Prompt of the Image you want want to generate" ,
190196 height = "Height of the Image" ,
@@ -200,22 +206,22 @@ async def imagine_command(
200206 self ,
201207 interaction : discord .Interaction ,
202208 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 ,
211217 ) -> None :
212218 validate_dimensions (width , height )
213219 validate_prompt (prompt )
214220
215221 await interaction .response .defer (thinking = True , ephemeral = private )
216222
217223 try :
218- model = model .value
224+ model = model .value if model else None
219225 except Exception :
220226 pass
221227
@@ -250,7 +256,9 @@ async def imagine_command_error(
250256 embed : discord .Embed = await generate_error_message (
251257 interaction ,
252258 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+ ],
254262 )
255263 return await interaction .response .send_message (embed = embed , ephemeral = True )
256264
@@ -277,7 +285,9 @@ async def imagine_command_error(
277285
278286 else :
279287 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 ```" ,
281291 )
282292
283293
0 commit comments