Rifat Azad commited on
Commit
834dc38
·
1 Parent(s): 73001f4

improvements 96

Browse files
Files changed (1) hide show
  1. pydvpl_bot.py +110 -0
pydvpl_bot.py CHANGED
@@ -84,6 +84,7 @@ async def compress(ctx):
84
 
85
  if not attachments:
86
  await ctx.send("No file attached.")
 
87
  return
88
 
89
  for attachment in attachments:
@@ -92,16 +93,19 @@ async def compress(ctx):
92
  # Check if the file is already in .dvpl format, if so, skip it
93
  if file_path.endswith(".dvpl"):
94
  await ctx.send(f"File {attachment.filename} is already in .dvpl format. Skipping.")
 
95
  continue
96
 
97
  await attachment.save(file_path)
98
  compressed_file_path = await compress_file(file_path)
99
  if compressed_file_path:
100
  await ctx.send(file=discord.File(compressed_file_path))
 
101
  os.remove(file_path) # Delete the original file
102
  os.remove(compressed_file_path) # Delete the compressed file
103
  else:
104
  await ctx.send("Failed to compress the file.")
 
105
 
106
 
107
  @bot.command(help="Decompresses attached files.")
@@ -110,6 +114,7 @@ async def decompress(ctx):
110
 
111
  if not attachments:
112
  await ctx.send("No file attached.")
 
113
  return
114
 
115
  for attachment in attachments:
@@ -118,22 +123,26 @@ async def decompress(ctx):
118
  # Check if the file is not in .dvpl format, if so, skip it
119
  if not file_path.endswith(".dvpl"):
120
  await ctx.send(f"File {attachment.filename} is not in .dvpl format. Skipping.")
 
121
  continue
122
 
123
  await attachment.save(file_path)
124
  decompressed_file_path = await decompress_file(file_path)
125
  if decompressed_file_path:
126
  await ctx.send(file=discord.File(decompressed_file_path))
 
127
  os.remove(file_path) # Delete the original file
128
  os.remove(decompressed_file_path) # Delete the decompressed file
129
  else:
130
  await ctx.send("Failed to decompress the file.")
 
131
 
132
 
133
  @bot.command(help="Pings to check bot's latency")
134
  async def ping(ctx):
135
  latency = round(bot.latency * 1000) # latency in milliseconds
136
  await ctx.send(f"Pong! Bot latency is {latency}ms.")
 
137
 
138
 
139
  @bot.command(help="Cleans all files in received_to_compress and received_to_decompress directories.")
@@ -141,6 +150,7 @@ async def clean(ctx):
141
  # Check if the user invoking the command is authorized
142
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
143
  await ctx.send("You are not authorized to use this command.")
 
144
  return
145
 
146
  try:
@@ -165,40 +175,49 @@ async def clean(ctx):
165
  # Send message with the counts
166
  message = f"All files cleaned successfully. Compressed files cleaned: {compress_count}, Decompressed files cleaned: {decompress_count}."
167
  await ctx.send(message)
 
168
  except Exception as e:
169
  await ctx.send(f"An error occurred while cleaning files: {e}")
 
170
 
171
 
172
  @bot.command(help="Set bot's presence to online")
173
  async def online(ctx):
174
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
175
  await ctx.send("You are not authorized to use this command.")
 
176
  return
177
  await bot.change_presence(activity=discord.Game(name=">>help for commands"))
178
  await ctx.send("Bot's presence set to online.")
 
179
 
180
 
181
  @bot.command(help="Set bot's presence to Do Not Disturb")
182
  async def dnd(ctx):
183
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
184
  await ctx.send("You are not authorized to use this command.")
 
185
  return
186
  await bot.change_presence(status=discord.Status.dnd)
187
  await ctx.send("Bot's presence set to Do Not Disturb.")
 
188
 
189
 
190
  @bot.command(help="Set bot's presence to offline")
191
  async def offline(ctx):
192
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
193
  await ctx.send("You are not authorized to use this command.")
 
194
  return
195
  await bot.change_presence(status=discord.Status.offline)
196
  await ctx.send("Bot's presence set to offline.")
 
197
 
198
  @bot.command(help="Set bot's activity")
199
  async def activity(ctx, activity_type, *, activity_text=None):
200
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
201
  await ctx.send("You are not authorized to use this command.")
 
202
  return
203
 
204
  if activity_type.lower() == 'listening':
@@ -209,14 +228,104 @@ async def activity(ctx, activity_type, *, activity_text=None):
209
  activity = discord.Activity(type=discord.ActivityType.playing, name=activity_text)
210
  else:
211
  await ctx.send('Invalid activity type. Please choose either "listening", "playing" or "watching".')
 
212
  return
213
 
214
  if not activity_text:
215
  await ctx.send('Please provide an activity text.')
 
216
  return
217
 
218
  await bot.change_presence(activity=activity)
219
  await ctx.send(f'Activity set to {activity_type} {activity_text}')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
 
221
 
222
  @bot.event
@@ -229,6 +338,7 @@ async def on_disconnect():
229
  async def on_command_error(ctx, error):
230
  if isinstance(error, commands.CommandNotFound):
231
  await ctx.send("Sorry, I couldn't find that command. Use `>>help` to see the list of available commands.")
 
232
  else:
233
  print(f'An error occurred: {error}')
234
 
 
84
 
85
  if not attachments:
86
  await ctx.send("No file attached.")
87
+ await ctx.message.delete()
88
  return
89
 
90
  for attachment in attachments:
 
93
  # Check if the file is already in .dvpl format, if so, skip it
94
  if file_path.endswith(".dvpl"):
95
  await ctx.send(f"File {attachment.filename} is already in .dvpl format. Skipping.")
96
+ await ctx.message.delete()
97
  continue
98
 
99
  await attachment.save(file_path)
100
  compressed_file_path = await compress_file(file_path)
101
  if compressed_file_path:
102
  await ctx.send(file=discord.File(compressed_file_path))
103
+ await ctx.message.delete()
104
  os.remove(file_path) # Delete the original file
105
  os.remove(compressed_file_path) # Delete the compressed file
106
  else:
107
  await ctx.send("Failed to compress the file.")
108
+ await ctx.message.delete()
109
 
110
 
111
  @bot.command(help="Decompresses attached files.")
 
114
 
115
  if not attachments:
116
  await ctx.send("No file attached.")
117
+ await ctx.message.delete()
118
  return
119
 
120
  for attachment in attachments:
 
123
  # Check if the file is not in .dvpl format, if so, skip it
124
  if not file_path.endswith(".dvpl"):
125
  await ctx.send(f"File {attachment.filename} is not in .dvpl format. Skipping.")
126
+ await ctx.message.delete()
127
  continue
128
 
129
  await attachment.save(file_path)
130
  decompressed_file_path = await decompress_file(file_path)
131
  if decompressed_file_path:
132
  await ctx.send(file=discord.File(decompressed_file_path))
133
+ await ctx.message.delete()
134
  os.remove(file_path) # Delete the original file
135
  os.remove(decompressed_file_path) # Delete the decompressed file
136
  else:
137
  await ctx.send("Failed to decompress the file.")
138
+ await ctx.message.delete()
139
 
140
 
141
  @bot.command(help="Pings to check bot's latency")
142
  async def ping(ctx):
143
  latency = round(bot.latency * 1000) # latency in milliseconds
144
  await ctx.send(f"Pong! Bot latency is {latency}ms.")
145
+ await ctx.message.delete()
146
 
147
 
148
  @bot.command(help="Cleans all files in received_to_compress and received_to_decompress directories.")
 
150
  # Check if the user invoking the command is authorized
151
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
152
  await ctx.send("You are not authorized to use this command.")
153
+ await ctx.message.delete()
154
  return
155
 
156
  try:
 
175
  # Send message with the counts
176
  message = f"All files cleaned successfully. Compressed files cleaned: {compress_count}, Decompressed files cleaned: {decompress_count}."
177
  await ctx.send(message)
178
+ await ctx.message.delete()
179
  except Exception as e:
180
  await ctx.send(f"An error occurred while cleaning files: {e}")
181
+ await ctx.message.delete()
182
 
183
 
184
  @bot.command(help="Set bot's presence to online")
185
  async def online(ctx):
186
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
187
  await ctx.send("You are not authorized to use this command.")
188
+ await ctx.message.delete()
189
  return
190
  await bot.change_presence(activity=discord.Game(name=">>help for commands"))
191
  await ctx.send("Bot's presence set to online.")
192
+ await ctx.message.delete()
193
 
194
 
195
  @bot.command(help="Set bot's presence to Do Not Disturb")
196
  async def dnd(ctx):
197
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
198
  await ctx.send("You are not authorized to use this command.")
199
+ await ctx.message.delete()
200
  return
201
  await bot.change_presence(status=discord.Status.dnd)
202
  await ctx.send("Bot's presence set to Do Not Disturb.")
203
+ await ctx.message.delete()
204
 
205
 
206
  @bot.command(help="Set bot's presence to offline")
207
  async def offline(ctx):
208
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
209
  await ctx.send("You are not authorized to use this command.")
210
+ await ctx.message.delete()
211
  return
212
  await bot.change_presence(status=discord.Status.offline)
213
  await ctx.send("Bot's presence set to offline.")
214
+ await ctx.message.delete()
215
 
216
  @bot.command(help="Set bot's activity")
217
  async def activity(ctx, activity_type, *, activity_text=None):
218
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
219
  await ctx.send("You are not authorized to use this command.")
220
+ await ctx.message.delete()
221
  return
222
 
223
  if activity_type.lower() == 'listening':
 
228
  activity = discord.Activity(type=discord.ActivityType.playing, name=activity_text)
229
  else:
230
  await ctx.send('Invalid activity type. Please choose either "listening", "playing" or "watching".')
231
+ await ctx.message.delete()
232
  return
233
 
234
  if not activity_text:
235
  await ctx.send('Please provide an activity text.')
236
+ await ctx.message.delete()
237
  return
238
 
239
  await bot.change_presence(activity=activity)
240
  await ctx.send(f'Activity set to {activity_type} {activity_text}')
241
+ await ctx.message.delete()
242
+
243
+
244
+ @bot.command(help="Send messages to specific channels or users")
245
+ async def say(ctx, destination_type, *args):
246
+ if str(ctx.author.id) != AUTHORIZED_USER_ID:
247
+ await ctx.send("You are not authorized to use this command.")
248
+ await ctx.message.delete()
249
+ return
250
+
251
+ if destination_type.lower() == 'channel':
252
+ if len(args) < 2:
253
+ await ctx.send("Usage: >>say channel <channel_id> <message>")
254
+ await ctx.message.delete()
255
+ return
256
+ try:
257
+ channel_id = int(args[0])
258
+ except ValueError:
259
+ await ctx.send("Channel ID must be a valid integer.")
260
+ await ctx.message.delete()
261
+ return
262
+ message = ' '.join(args[1:])
263
+ channel = bot.get_channel(channel_id)
264
+ if channel:
265
+ await channel.send(message)
266
+ await ctx.send(f"Message '{message}' sent to channel '{channel.name}'.")
267
+ await ctx.message.delete()
268
+ else:
269
+ await ctx.send("Channel not found.")
270
+ await ctx.message.delete()
271
+ elif destination_type.lower() == 'server':
272
+ if len(args) < 2:
273
+ await ctx.send("Usage: >>say server <server_id> <message>")
274
+ await ctx.message.delete()
275
+ return
276
+ try:
277
+ server_id = int(args[0])
278
+ except ValueError:
279
+ await ctx.send("Server ID must be a valid integer.")
280
+ await ctx.message.delete()
281
+ return
282
+ message = ' '.join(args[1:])
283
+ server = bot.get_guild(server_id)
284
+ if server:
285
+ announcement_channel = discord.utils.get(server.channels, name="important-announcements")
286
+ if announcement_channel:
287
+ await announcement_channel.send(message)
288
+ await ctx.send(f"Message '{message}' sent to server '{server.name}' in 'important-announcements' channel.")
289
+ await ctx.message.delete()
290
+ else:
291
+ announcements_channel = discord.utils.get(server.channels, name="announcements")
292
+ if announcements_channel:
293
+ await announcements_channel.send(message)
294
+ await ctx.send(f"Message '{message}' sent to server '{server.name}' in 'announcements' channel.")
295
+ await ctx.message.delete()
296
+ else:
297
+ await ctx.send("No announcement channels found in the server.")
298
+ await ctx.message.delete()
299
+ else:
300
+ await ctx.send("Server not found.")
301
+ await ctx.message.delete()
302
+ elif destination_type.lower() in ['user', 'dm']:
303
+ if len(args) < 2:
304
+ await ctx.send("Usage: >>say dm user <user_id> <message>")
305
+ await ctx.message.delete()
306
+ return
307
+ try:
308
+ user_id = int(args[0])
309
+ except ValueError:
310
+ await ctx.send("User ID must be a valid integer.")
311
+ await ctx.message.delete()
312
+ return
313
+ message = ' '.join(args[1:])
314
+ user = bot.get_user(user_id)
315
+ if user:
316
+ try:
317
+ await user.send(message)
318
+ await ctx.send(f"Message '{message}' sent to user '{user.display_name}'.")
319
+ await ctx.message.delete()
320
+ except discord.Forbidden:
321
+ await ctx.send(f"Couldn't send message to `{user.display_name}`. Their DMs are closed.")
322
+ await ctx.message.delete()
323
+ else:
324
+ await ctx.send("User not found.")
325
+ await ctx.message.delete()
326
+ else:
327
+ await ctx.send("Invalid destination type. Use either 'channel', 'server', or 'dm'.")
328
+ await ctx.message.delete()
329
 
330
 
331
  @bot.event
 
338
  async def on_command_error(ctx, error):
339
  if isinstance(error, commands.CommandNotFound):
340
  await ctx.send("Sorry, I couldn't find that command. Use `>>help` to see the list of available commands.")
341
+ await ctx.message.delete()
342
  else:
343
  print(f'An error occurred: {error}')
344