lunarflu HF Staff commited on
Commit
518ee01
·
1 Parent(s): b9dc6ec

removing extra code, completely removing buttons, removing ratelimits / CD, replacing with reactions as test

Browse files
Files changed (1) hide show
  1. app.py +7 -271
app.py CHANGED
@@ -34,290 +34,24 @@ intents.message_content = True
34
 
35
  bot = commands.Bot(command_prefix='!', intents=intents)
36
 
37
- rate_limiter = RateLimiter(max_calls=10, period=60) # 10 calls per minute
38
 
39
- #buttons----------------------------------------------------------------------------------------------------------------------------------------------
40
- #new
41
- class ButtonView(discord.ui.View):
42
- def __init__(self, ctx, image_paths, stage_1_result_path):
43
- super().__init__()
44
- self.ctx = ctx
45
- self.image_paths = image_paths
46
- self.stage_1_result_path = stage_1_result_path
47
-
48
- async def on_timeout(self):
49
- for child in self.children:
50
- child.disabled = True
51
- self.stop()
52
-
53
- async def button_handler(self, index: int):
54
- await self.ctx.invoke(self.ctx.bot.get_command('dfif2'), index=index, stage_1_result_path=self.stage_1_result_path, image_paths=self.image_paths)
55
- self.stop()
56
-
57
- @discord.ui.button(label='Image 1', style=discord.ButtonStyle.blurple)
58
- async def image1_button(self, button: discord.ui.Button, interaction: discord.Interaction):
59
- await self.button_handler(0)
60
-
61
- @discord.ui.button(label='Image 2', style=discord.ButtonStyle.blurple)
62
- async def image2_button(self, button: discord.ui.Button, interaction: discord.Interaction):
63
- await self.button_handler(1)
64
-
65
- @discord.ui.button(label='Image 3', style=discord.ButtonStyle.blurple)
66
- async def image3_button(self, button: discord.ui.Button, interaction: discord.Interaction):
67
- await self.button_handler(2)
68
-
69
- @discord.ui.button(label='Image 4', style=discord.ButtonStyle.blurple)
70
- async def image4_button(self, button: discord.ui.Button, interaction: discord.Interaction):
71
- await self.button_handler(3)
72
-
73
- #new
74
- def create_button_row(ctx, image_paths, stage_1_result_path):
75
- view = ButtonView(ctx, image_paths, stage_1_result_path)
76
- return view
77
  #----------------------------------------------------------------------------------------------------------------------------------------------
78
 
79
  @bot.event
80
  async def on_ready():
81
  print('Logged on as', bot.user)
82
  bot.log_channel = bot.get_channel(1100458786826747945) # 1100458786826747945 = bot-test, 1107006391547342910 = lunarbot server
83
-
84
- @bot.event
85
- async def on_message_edit(before, after):
86
- if before.author == bot.user:
87
- return
88
-
89
- if before.content != after.content:
90
- embed = Embed(color=Color.orange())
91
- embed.set_author(name=f"{before.author} ID: {before.author.id}", icon_url=before.author.avatar.url)
92
- embed.title = "Message Edited"
93
- embed.description = f"**Before:** {before.content or '*(empty message)*'}\n**After:** {after.content or '*(empty message)*'}"
94
- embed.add_field(name="Author Username", value=before.author.name, inline=True)
95
- embed.add_field(name="Channel", value=before.channel.mention, inline=True)
96
- #embed.add_field(name="Message Created On", value=before.created_at.strftime("%Y-%m-%d %H:%M:%S UTC"), inline=True)
97
- embed.add_field(name="Message Created On", value=convert_to_timezone(before.created_at, zurich_tz), inline=True)
98
- embed.add_field(name="Message ID", value=before.id, inline=True)
99
- embed.add_field(name="Message Jump URL", value=f"[Jump to message!](https://discord.com/channels/{before.guild.id}/{before.channel.id}/{before.id})", inline=True)
100
-
101
- if before.attachments:
102
- attachment_urls = "\n".join([attachment.url for attachment in before.attachments])
103
- embed.add_field(name="Attachments", value=attachment_urls, inline=False)
104
-
105
- #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
106
- embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
107
-
108
- await bot.log_channel.send(embed=embed)
109
-
110
- @bot.event
111
- async def on_message_delete(message):
112
- if message.author == bot.user:
113
- return
114
-
115
- embed = Embed(color=Color.red())
116
- embed.set_author(name=f"{message.author} ID: {message.author.id}", icon_url=message.author.avatar.url)
117
- embed.title = "Message Deleted"
118
- embed.description = message.content or "*(empty message)*"
119
- embed.add_field(name="Author Username", value=message.author.name, inline=True)
120
- embed.add_field(name="Channel", value=message.channel.mention, inline=True)
121
- #embed.add_field(name="Message Created On", value=message.created_at.strftime("%Y-%m-%d %H:%M:%S UTC"), inline=True)
122
- embed.add_field(name="Message Created On", value=convert_to_timezone(message.created_at, zurich_tz), inline=True)
123
- embed.add_field(name="Message ID", value=message.id, inline=True)
124
- embed.add_field(name="Message Jump URL", value=f"[Jump to message!](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})", inline=True)
125
-
126
- if message.attachments:
127
- attachment_urls = "\n".join([attachment.url for attachment in message.attachments])
128
- embed.add_field(name="Attachments", value=attachment_urls, inline=False)
129
-
130
- #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
131
- embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
132
-
133
- await bot.log_channel.send(embed=embed)
134
-
135
- @bot.event
136
- async def on_member_ban(guild, user):
137
- # User bans
138
- logs = await guild.audit_logs(limit=1, action=discord.AuditLogAction.ban).flatten()
139
- ban_entry = logs[0] if logs else None
140
-
141
- if ban_entry:
142
- reason = ban_entry.reason
143
- embed = Embed(description=f'User {user.name} ({user.mention}) was banned', color=Color.red())
144
- embed.add_field(name='Reason', value=reason, inline=False)
145
- else:
146
- embed = Embed(description=f'User {user.name} ({user.mention}) was banned', color=Color.red())
147
-
148
- await bot.log_channel.send(embed=embed)
149
-
150
- @bot.event
151
- async def on_member_ban(guild, user):
152
- # User kicks (temporary bans)
153
- logs = await guild.audit_logs(limit=1, action=discord.AuditLogAction.ban).flatten()
154
- kick_entry = next((log for log in logs if log.target == user), None)
155
-
156
- if kick_entry:
157
- reason = kick_entry.reason
158
- embed = Embed(description=f'User {user.name} ({user.mention}) was kicked', color=Color.red())
159
- embed.add_field(name='Reason', value=reason, inline=False)
160
- else:
161
- embed = Embed(description=f'User {user.name} ({user.mention}) was kicked', color=Color.red())
162
-
163
- await bot.log_channel.send(embed=embed)
164
-
165
-
166
- #new
167
- @bot.event
168
- async def on_voice_state_update(member, before, after):
169
- if before.channel != after.channel:
170
- # Moving members in voice chat
171
- embed = Embed(description=f'{member} moved in voice chat from {before.channel} to {after.channel}', color=Color.blue())
172
- await bot.log_channel.send(embed=embed)
173
-
174
- if before.mute != after.mute:
175
- # Muting members in voice chat
176
- embed = Embed(description=f'{member} was {"muted" if after.mute else "unmuted"} in voice chat', color=Color.orange())
177
- await bot.log_channel.send(embed=embed)
178
-
179
- if before.deaf != after.deaf:
180
- # Deafening members in voice chat
181
- embed = Embed(description=f'{member} was {"deafened" if after.deaf else "undeafened"} in voice chat', color=Color.orange())
182
- await bot.log_channel.send(embed=embed)
183
-
184
- @bot.event
185
- async def on_member_update(before, after):
186
- if before.nick == None and after.nick != None and after.nick != '':
187
- # User creates a nickname
188
- embed = Embed(description=f'{before} created the nickname {after.nick}', color=Color.blue())
189
- await bot.log_channel.send(embed=embed)
190
- elif before.nick != None and (after.nick == None or after.nick == ''):
191
- # User removes their nickname
192
- embed = Embed(description=f'{before} removed their nickname', color=Color.blue())
193
- await bot.log_channel.send(embed=embed)
194
- elif before.nick != after.nick:
195
- # User changes their nickname
196
- embed = Embed(description=f'{before} changed their nickname to {after.nick}', color=Color.blue())
197
- await bot.log_channel.send(embed=embed)
198
-
199
- @bot.event
200
- async def on_guild_channel_create(channel):
201
- # Channel creations
202
- embed = Embed(description=f'Channel #{channel.name} ({channel.mention}) was created', color=Color.green())
203
- await bot.log_channel.send(embed=embed)
204
-
205
- @bot.event
206
- async def on_guild_channel_delete(channel):
207
- # Channel deletions
208
- embed = Embed(description=f'Channel #{channel.name} ({channel.mention}) was deleted', color=Color.red())
209
- await bot.log_channel.send(embed=embed)
210
-
211
-
212
- @bot.event
213
- async def on_guild_role_create(role):
214
- # Creating roles
215
- embed = Embed(description=f'Role {role.mention} was created', color=Color.green())
216
- await bot.log_channel.send(embed=embed)
217
-
218
- @bot.event
219
- async def on_guild_role_delete(role):
220
- # Deleting roles
221
- embed = Embed(description=f'Role {role.name} ({role.mention}) was deleted', color=Color.red())
222
- await bot.log_channel.send(embed=embed)
223
-
224
- @bot.event
225
- async def on_guild_role_update(before, after):
226
- # Editing roles
227
- if before.name != after.name:
228
- embed = Embed(description=f'Role {before.mention} was renamed to {after.name}', color=Color.orange())
229
- await bot.log_channel.send(embed=embed)
230
-
231
- if before.permissions.kick_members != after.permissions.kick_members:
232
- # Changes involving the kick_members permission
233
- certain_role_id = 1108342563628404747 # alerts role- opt in
234
- certain_role = after.guild.get_role(certain_role_id)
235
- embed = Embed(description=f'Role {after.mention} had its kick_members permission {"enabled" if after.permissions.kick_members else "disabled"}', color=Color.red())
236
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
237
-
238
- if before.permissions.ban_members != after.permissions.ban_members:
239
- # Changes involving the ban_members permission
240
- certain_role_id = 1108342563628404747 # alerts role- opt in
241
- certain_role = after.guild.get_role(certain_role_id)
242
- embed = Embed(description=f'Role {after.mention} had its ban_members permission {"enabled" if after.permissions.ban_members else "disabled"}', color=Color.red())
243
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
244
-
245
- if before.permissions.administrator != after.permissions.administrator:
246
- # Changes involving the administrator permission
247
- certain_role_id = 1108342563628404747 # alerts role- opt in
248
- certain_role = after.guild.get_role(certain_role_id)
249
- embed = Embed(description=f'Role {after.mention} had its administrator permission {"enabled" if after.permissions.administrator else "disabled"}', color=Color.red())
250
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
251
-
252
- if before.permissions.manage_channels != after.permissions.manage_channels:
253
- # Changes involving the manage_channels permission
254
- certain_role_id = 1108342563628404747 # alerts role- opt in
255
- certain_role = after.guild.get_role(certain_role_id)
256
- embed = Embed(description=f'Role {after.mention} had its manage_channels permission {"enabled" if after.permissions.manage_channels else "disabled"}', color=Color.red())
257
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
258
-
259
- if before.permissions.manage_guild != after.permissions.manage_guild:
260
- # Changes involving the manage_guild permission
261
- certain_role_id = 1108342563628404747 # alerts role- opt in
262
- certain_role = after.guild.get_role(certain_role_id)
263
- embed = Embed(description=f'Role {after.mention} had its manage_guild permission {"enabled" if after.permissions.manage_guild else "disabled"}', color=Color.red())
264
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
265
-
266
- if before.permissions.manage_messages != after.permissions.manage_messages:
267
- # Changes involving the manage_messages permission
268
- certain_role_id = 1108342563628404747 # alerts role- opt in
269
- certain_role = after.guild.get_role(certain_role_id)
270
- embed = Embed(description=f'Role {after.mention} had its manage_messages permission {"enabled" if after.permissions.manage_messages else "disabled"}', color=Color.red())
271
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
272
-
273
- if before.permissions.manage_roles != after.permissions.manage_roles:
274
- # Changes involving the manage_roles permission
275
- certain_role_id = 1108342563628404747 # alerts role- opt in
276
- certain_role = after.guild.get_role(certain_role_id)
277
- embed = Embed(description=f'Role {after.mention} had its manage_roles permission {"enabled" if after.permissions.manage_roles else "disabled"}', color=Color.red())
278
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
279
-
280
- if before.permissions.manage_webhooks != after.permissions.manage_webhooks:
281
- # Changes involving the manage_webhooks permission
282
- certain_role_id = 1108342563628404747 # alerts role- opt in
283
- certain_role = after.guild.get_role(certain_role_id)
284
- embed = Embed(description=f'Role {after.mention} had its manage_webhooks permission {"enabled" if after.permissions.manage_webhooks else "disabled"}', color=Color.red())
285
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
286
-
287
- if before.permissions.manage_guild_expressions != after.permissions.manage_guild_expressions:
288
- # Changes involving the manage_guild_expressions permission
289
- certain_role_id = 1108342563628404747 # alerts role- opt in
290
- certain_role = after.guild.get_role(certain_role_id)
291
- embed = Embed(description=f'Role {after.mention} had its manage_guild_expressions permission {"enabled" if after.permissions.manage_guild_expressions else "disabled"}', color=Color.red())
292
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
293
-
294
- if before.permissions.manage_threads != after.permissions.manage_threads:
295
- # Changes involving the manage_threads permission
296
- certain_role_id = 1108342563628404747 # alerts role- opt in
297
- certain_role = after.guild.get_role(certain_role_id)
298
- embed = Embed(description=f'Role {after.mention} had its manage_threads permission {"enabled" if after.permissions.manage_threads else "disabled"}', color=Color.red())
299
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
300
-
301
- if before.permissions.moderate_members != after.permissions.moderate_members:
302
- # Changes involving the moderate_members permission
303
- certain_role_id = 1108342563628404747 # alerts role- opt in
304
- certain_role = after.guild.get_role(certain_role_id)
305
- embed = Embed(description=f'Role {after.mention} had its moderate_members permission {"enabled" if after.permissions.moderate_members else "disabled"}', color=Color.red())
306
- await bot.log_channel.send(content=certain_role.mention, embed=embed)
307
-
308
-
309
-
310
 
311
 
312
-
313
-
314
  @bot.command()
315
- @commands.cooldown(1, 5, commands.BucketType.user)
316
  async def deepfloydif(ctx, *, prompt: str):
317
  try:
318
  prompt = prompt.strip()[:100] # Limit the prompt length to 100 characters
319
  prompt = re.sub(r'[^\w\s]', '', prompt) # Remove special characters
320
 
 
 
 
321
  with rate_limiter:
322
  number_of_images = 4
323
  current_time = int(time.time())
@@ -357,7 +91,10 @@ async def deepfloydif(ctx, *, prompt: str):
357
 
358
  await ctx.reply('Here is the combined image. Select an option quickly!')
359
  with open(combined_image_path, 'rb') as f:
360
- await ctx.send(file=discord.File(f, 'combined_image.png'), view=create_button_row(ctx, [first_png_path, second_png_path, third_png_path, fourth_png_path], stage_1_result_path))
 
 
 
361
 
362
  except Exception as e:
363
  print(f"Error: {e}")
@@ -366,7 +103,6 @@ async def deepfloydif(ctx, *, prompt: str):
366
  #new stage 2----------------------------------------------------------------------------------------------------------------------------------------------
367
  # Stage 2
368
  @bot.command()
369
- @commands.cooldown(1, 5, commands.BucketType.user)
370
  async def dfif2(ctx, index: int, stage_1_result_path, image_paths):
371
  try:
372
  image_path = image_paths[index]
 
34
 
35
  bot = commands.Bot(command_prefix='!', intents=intents)
36
 
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  #----------------------------------------------------------------------------------------------------------------------------------------------
39
 
40
  @bot.event
41
  async def on_ready():
42
  print('Logged on as', bot.user)
43
  bot.log_channel = bot.get_channel(1100458786826747945) # 1100458786826747945 = bot-test, 1107006391547342910 = lunarbot server
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
 
 
 
46
  @bot.command()
 
47
  async def deepfloydif(ctx, *, prompt: str):
48
  try:
49
  prompt = prompt.strip()[:100] # Limit the prompt length to 100 characters
50
  prompt = re.sub(r'[^\w\s]', '', prompt) # Remove special characters
51
 
52
+ def check_reaction(reaction, user):
53
+ return str(reaction.emoji) == '👍' and user == ctx.author
54
+
55
  with rate_limiter:
56
  number_of_images = 4
57
  current_time = int(time.time())
 
91
 
92
  await ctx.reply('Here is the combined image. Select an option quickly!')
93
  with open(combined_image_path, 'rb') as f:
94
+ await ctx.send(file=discord.File(f, 'combined_image.png'))
95
+
96
+ reaction, user = await bot.wait_for('reaction_add', check=check_reaction)
97
+ await ctx.send(f"{user.mention} reacted with a thumbs-up!")
98
 
99
  except Exception as e:
100
  print(f"Error: {e}")
 
103
  #new stage 2----------------------------------------------------------------------------------------------------------------------------------------------
104
  # Stage 2
105
  @bot.command()
 
106
  async def dfif2(ctx, index: int, stage_1_result_path, image_paths):
107
  try:
108
  image_path = image_paths[index]