Rifat Azad commited on
Commit
ef13acf
·
1 Parent(s): 7077459

new issues and requests commands

Browse files
Files changed (1) hide show
  1. pydvpl_bot.py +117 -41
pydvpl_bot.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import time
 
3
  import psutil
4
  import discord
5
  from dotenv import load_dotenv
@@ -30,6 +31,17 @@ UPDATE_INTERVAL = 60
30
 
31
  activity_start_time = 0
32
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  # DEFINES ------------------------------------------------------ END
35
 
@@ -59,10 +71,53 @@ class PyDVPLHelpCommand(DefaultHelpCommand):
59
 
60
  # Ensure the existence of folders
61
  def ensure_folders():
62
- if not os.path.exists("received_to_compress"):
63
- os.makedirs("received_to_compress")
64
- if not os.path.exists("received_to_decompress"):
65
- os.makedirs("received_to_decompress")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
 
68
  # HELPER ------------------------------------------------------ END
@@ -230,7 +285,7 @@ async def compress(ctx):
230
  return
231
 
232
  for attachment in attachments:
233
- file_path = os.path.join("received_to_compress", attachment.filename)
234
 
235
  # Check if the file is already in .dvpl format, if so, skip it
236
  if file_path.endswith(".dvpl"):
@@ -265,7 +320,7 @@ async def decompress(ctx):
265
  return
266
 
267
  for attachment in attachments:
268
- file_path = os.path.join("received_to_decompress", attachment.filename)
269
 
270
  # Check if the file is not in .dvpl format, if so, skip it
271
  if not file_path.endswith(".dvpl"):
@@ -324,46 +379,63 @@ async def invite(ctx):
324
  await ctx.message.delete()
325
 
326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  # UTILITY USER_CMD ------------------------------------------------------ END
328
 
329
 
330
  # UTILITY ADMIN_CMD ------------------------------------------------------ START
331
 
332
 
333
- @bot.command(help="Cleans all files in received_to_compress and received_to_decompress directories.")
334
- async def clean(ctx):
335
- # Check if the user invoking the command is authorized
336
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
337
  await ctx.send("You are not authorized to use this command.")
338
  await ctx.message.delete()
339
  return
340
 
341
- try:
342
- # Initialize counts for files cleaned
343
- compress_count = 0
344
- decompress_count = 0
345
-
346
- # Clean files in received_to_compress directory
347
- for filename in os.listdir("received_to_compress"):
348
- file_path = os.path.join("received_to_compress", filename)
349
- if os.path.isfile(file_path):
350
- os.remove(file_path)
351
- compress_count += 1
352
-
353
- # Clean files in received_to_decompress directory
354
- for filename in os.listdir("received_to_decompress"):
355
- file_path = os.path.join("received_to_decompress", filename)
356
- if os.path.isfile(file_path):
357
- os.remove(file_path)
358
- decompress_count += 1
359
-
360
- # Send message with the counts
361
- message = f"All files cleaned successfully. Compressed files cleaned: {compress_count}, Decompressed files cleaned: {decompress_count}."
362
- await ctx.send(message)
363
- await ctx.message.delete()
364
- except Exception as e:
365
- await ctx.send(f"An error occurred while cleaning files: {e}")
366
- await ctx.message.delete()
367
 
368
 
369
  # FUNCTION ------------------------------------------------------ SPLIT
@@ -626,7 +698,7 @@ async def stats(ctx):
626
  await ctx.message.delete()
627
 
628
 
629
- @bot.command(help="List all servers the bot is on with their IDs")
630
  async def list(ctx, list_type, *args):
631
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
632
  await ctx.send("You are not authorized to use this command.")
@@ -634,12 +706,16 @@ async def list(ctx, list_type, *args):
634
  return
635
 
636
  if list_type.lower() == 'servers':
637
- if len(args) < 1:
638
- servers_info = "\n".join([f"{server.name} - ID: {server.id}" for server in bot.guilds])
639
- await ctx.send(f"List of servers the bot is on:\n```{servers_info}```")
640
- await ctx.message.delete()
 
 
 
 
 
641
 
642
-
643
 
644
  # UTILITY ADMIN_CMD ------------------------------------------------------ END
645
 
 
1
  import os
2
  import time
3
+ import json
4
  import psutil
5
  import discord
6
  from dotenv import load_dotenv
 
31
 
32
  activity_start_time = 0
33
 
34
+ # Define folder paths
35
+ FEEDBACK_FOLDER = "feedback"
36
+
37
+ ISSUES_FOLDER = os.path.join(FEEDBACK_FOLDER, "issues")
38
+
39
+ REQUESTS_FOLDER = os.path.join(FEEDBACK_FOLDER, "requests")
40
+
41
+ COMPRESS_FOLDER= os.path.join("received_to_compress")
42
+
43
+ DECOMPRESS_FOLDER= os.path.join("received_to_decompress")
44
+
45
 
46
  # DEFINES ------------------------------------------------------ END
47
 
 
71
 
72
  # Ensure the existence of folders
73
  def ensure_folders():
74
+ for folder in [FEEDBACK_FOLDER, ISSUES_FOLDER, REQUESTS_FOLDER, COMPRESS_FOLDER, DECOMPRESS_FOLDER]:
75
+ if not os.path.exists(folder):
76
+ os.makedirs(folder)
77
+
78
+
79
+ # FUNCTION ------------------------------------------------------ SPLIT
80
+
81
+
82
+ async def list_feedback(ctx, folder_path, title):
83
+ files = os.listdir(folder_path)
84
+ feedback_embed = discord.Embed(title=title, color=discord.Color.blurple())
85
+ for file in files:
86
+ file_path = os.path.join(folder_path, file)
87
+ with open(file_path, "r") as f:
88
+ feedback_data = json.load(f)
89
+ for feedback in feedback_data:
90
+ author_name = feedback['author_name']
91
+ author_id = feedback['author_id']
92
+ timestamp = feedback['timestamp']
93
+ message = feedback['message']
94
+ feedback_embed.add_field(
95
+ name=f"Author: {author_name} (ID: {author_id})",
96
+ value=f"Timestamp: {timestamp}\nMessage: {message}",
97
+ inline=False
98
+ )
99
+ if feedback_embed.fields:
100
+ await ctx.send(embed=feedback_embed)
101
+ else:
102
+ await ctx.send("No feedback found.")
103
+ await ctx.message.delete()
104
+
105
+
106
+ # FUNCTION ------------------------------------------------------ SPLIT
107
+
108
+
109
+ async def clean_directory(ctx, directory):
110
+ try:
111
+ file_count = 0
112
+ for filename in os.listdir(directory):
113
+ file_path = os.path.join(directory, filename)
114
+ if os.path.isfile(file_path):
115
+ os.remove(file_path)
116
+ file_count += 1
117
+ await ctx.send(f"All files cleaned successfully in {directory}. Total files cleaned: {file_count}.")
118
+ except Exception as e:
119
+ await ctx.send(f"An error occurred while cleaning files: {e}")
120
+ await ctx.message.delete()
121
 
122
 
123
  # HELPER ------------------------------------------------------ END
 
285
  return
286
 
287
  for attachment in attachments:
288
+ file_path = os.path.join(COMPRESS_FOLDER, attachment.filename)
289
 
290
  # Check if the file is already in .dvpl format, if so, skip it
291
  if file_path.endswith(".dvpl"):
 
320
  return
321
 
322
  for attachment in attachments:
323
+ file_path = os.path.join(DECOMPRESS_FOLDER, attachment.filename)
324
 
325
  # Check if the file is not in .dvpl format, if so, skip it
326
  if not file_path.endswith(".dvpl"):
 
379
  await ctx.message.delete()
380
 
381
 
382
+ # FUNCTION ------------------------------------------------------ SPLIT
383
+
384
+
385
+ # Command: Feedback
386
+ @bot.command(help="Send feedback or report issues", usage="<requests/issues> <message>")
387
+ async def feedback(ctx, category: str, *, message: str):
388
+ if category.lower() not in ["requests", "issues"]:
389
+ await ctx.send("Invalid category. Please choose 'requests' or 'issues'.")
390
+ return
391
+
392
+ feedback_data = {
393
+ "author_id": ctx.author.id,
394
+ "author_name": ctx.author.name,
395
+ "timestamp": str(ctx.message.created_at),
396
+ "message": message
397
+ }
398
+
399
+ folder_path = REQUESTS_FOLDER if category.lower() == "requests" else ISSUES_FOLDER
400
+ file_path = os.path.join(folder_path, f"{category.lower()}.json")
401
+
402
+ try:
403
+ with open(file_path, "r") as f:
404
+ data = json.load(f)
405
+ except FileNotFoundError:
406
+ data = []
407
+
408
+ data.append(feedback_data)
409
+
410
+ with open(file_path, "w") as f:
411
+ json.dump(data, f, indent=4)
412
+
413
+ await ctx.send(f"Thank you for your {category.lower()}. It has been recorded.")
414
+
415
+
416
  # UTILITY USER_CMD ------------------------------------------------------ END
417
 
418
 
419
  # UTILITY ADMIN_CMD ------------------------------------------------------ START
420
 
421
 
422
+ @bot.command(help="Cleans files in specific directories")
423
+ async def clean(ctx, clean_mode):
 
424
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
425
  await ctx.send("You are not authorized to use this command.")
426
  await ctx.message.delete()
427
  return
428
 
429
+ if clean_mode.lower() == 'compress':
430
+ await clean_directory(ctx, COMPRESS_FOLDER)
431
+ elif clean_mode.lower() == 'decompress':
432
+ await clean_directory(ctx, DECOMPRESS_FOLDER)
433
+ elif clean_mode.lower() == 'issues':
434
+ await clean_directory(ctx, ISSUES_FOLDER)
435
+ elif clean_mode.lower() == 'requests':
436
+ await clean_directory(ctx, REQUESTS_FOLDER)
437
+ else:
438
+ await ctx.send("Invalid clean mode. Please choose 'received_to_compress', 'received_to_decompress', 'feedback_issues', or 'feedback_requests'.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
 
440
 
441
  # FUNCTION ------------------------------------------------------ SPLIT
 
698
  await ctx.message.delete()
699
 
700
 
701
+ @bot.command(help="List issues, requests, or servers")
702
  async def list(ctx, list_type, *args):
703
  if str(ctx.author.id) != AUTHORIZED_USER_ID:
704
  await ctx.send("You are not authorized to use this command.")
 
706
  return
707
 
708
  if list_type.lower() == 'servers':
709
+ servers_info = "\n".join([f"{server.name} - ID: {server.id}" for server in bot.guilds])
710
+ await ctx.send(f"List of servers the bot is on:\n```{servers_info}```")
711
+ await ctx.message.delete()
712
+ elif list_type.lower() == 'issues':
713
+ await list_feedback(ctx, ISSUES_FOLDER, "List of issues:")
714
+ elif list_type.lower() == 'requests':
715
+ await list_feedback(ctx, REQUESTS_FOLDER, "List of requests:")
716
+ else:
717
+ await ctx.send("Invalid list type. Please choose 'servers', 'issues', or 'requests'.")
718
 
 
719
 
720
  # UTILITY ADMIN_CMD ------------------------------------------------------ END
721