Rifat Azad commited on
Commit
14aed84
·
1 Parent(s): 8d92e23

new updates 2

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. pydvpl_bot.py +43 -3
Dockerfile CHANGED
@@ -2,7 +2,7 @@ FROM python:3.12-slim
2
 
3
  WORKDIR /code
4
 
5
- RUN pip install --no-cache-dir -U discord pydvpl fastapi uvicorn
6
 
7
  COPY ./pydvpl_bot.py /code
8
 
 
2
 
3
  WORKDIR /code
4
 
5
+ RUN pip install --no-cache-dir -U discord pydvpl fastapi uvicorn psutil
6
 
7
  COPY ./pydvpl_bot.py /code
8
 
pydvpl_bot.py CHANGED
@@ -1,9 +1,11 @@
1
  import os
 
 
2
  import discord
3
  from discord.ext import commands, tasks
4
- from pydvpl.dvpl import compress_dvpl, decompress_dvpl
5
  from discord.ext.commands import DefaultHelpCommand
6
- import time
 
7
 
8
  # Define the authorized user ID
9
  AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
@@ -189,7 +191,7 @@ async def ping(ctx):
189
  latency = round(bot.latency * 1000) # latency in milliseconds
190
  await ctx.send(f"Pong! Bot latency is {latency}ms.")
191
  await ctx.send(f"The command `ping` was executed by - {ctx.author.mention}")
192
-
193
 
194
 
195
  @bot.command(help="Cleans all files in received_to_compress and received_to_decompress directories.")
@@ -396,6 +398,44 @@ async def uptime(ctx):
396
  await ctx.message.delete()
397
 
398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  @bot.event
400
  async def on_disconnect():
401
  print('Bot disconnected from Discord. Attempting to reconnect...')
 
1
  import os
2
+ import time
3
+ import psutil
4
  import discord
5
  from discord.ext import commands, tasks
 
6
  from discord.ext.commands import DefaultHelpCommand
7
+ from pydvpl.dvpl import compress_dvpl, decompress_dvpl
8
+
9
 
10
  # Define the authorized user ID
11
  AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
 
191
  latency = round(bot.latency * 1000) # latency in milliseconds
192
  await ctx.send(f"Pong! Bot latency is {latency}ms.")
193
  await ctx.send(f"The command `ping` was executed by - {ctx.author.mention}")
194
+ await ctx.message.delete()
195
 
196
 
197
  @bot.command(help="Cleans all files in received_to_compress and received_to_decompress directories.")
 
398
  await ctx.message.delete()
399
 
400
 
401
+ @bot.command(help="Show statistics about bot's health and connection.")
402
+ async def stats(ctx):
403
+
404
+ if str(ctx.author.id) != AUTHORIZED_USER_ID:
405
+ await ctx.send("You are not authorized to use this command.")
406
+ await ctx.message.delete()
407
+ return
408
+
409
+ guild_count = len(bot.guilds)
410
+ member_count = len(set(bot.get_all_members()))
411
+
412
+ uptime_seconds = int(time.time() - activity_start_time)
413
+ uptime_minutes, uptime_seconds = divmod(uptime_seconds, 60)
414
+ uptime_hours, uptime_minutes = divmod(uptime_minutes, 60)
415
+ uptime_days, uptime_hours = divmod(uptime_hours, 24)
416
+
417
+ latency = round(bot.latency * 1000) # latency in milliseconds
418
+
419
+ # Get CPU usage
420
+ cpu_usage = psutil.cpu_percent(interval=None)
421
+
422
+ # Get memory usage
423
+ memory_usage = psutil.virtual_memory().percent
424
+
425
+ bot_mention = ctx.me.mention
426
+ stats_message = (
427
+ f"**{bot_mention}'s Statistics & Vitals -**\n\n"
428
+ f"Servers: {guild_count}\n"
429
+ f"Members: {member_count}\n"
430
+ f"Uptime: {uptime_days} days, {uptime_hours} hours, {uptime_minutes} minutes, {uptime_seconds} seconds\n"
431
+ f"Latency: {latency}ms\n"
432
+ f"CPU Usage: {cpu_usage}%\n"
433
+ f"Memory Usage: {memory_usage}%"
434
+ )
435
+ await ctx.send(stats_message)
436
+ await ctx.message.delete()
437
+
438
+
439
  @bot.event
440
  async def on_disconnect():
441
  print('Bot disconnected from Discord. Attempting to reconnect...')