Rifat Azad commited on
Commit
f2e3f46
·
1 Parent(s): fc6d7ac
Files changed (1) hide show
  1. logger.py +19 -35
logger.py CHANGED
@@ -1,43 +1,27 @@
1
  from fastapi import FastAPI
2
- import psutil
3
- import httpx
4
- import datetime
5
 
6
  app = FastAPI()
7
 
8
- @app.get("/")
9
- async def read_root():
10
- # Get system uptime
11
- boot_time = datetime.fromtimestamp(psutil.boot_time())
12
- current_time = datetime.now()
13
- uptime_delta = current_time - boot_time
14
- uptime_seconds = uptime_delta.total_seconds()
15
 
16
- # Convert uptime to days, hours, minutes, seconds
17
- uptime_days, remainder = divmod(uptime_seconds, 86400)
18
- uptime_hours, remainder = divmod(remainder, 3600)
19
- uptime_minutes, uptime_seconds = divmod(remainder, 60)
20
 
21
- # Get system vitals
22
- cpu_percent = psutil.cpu_percent()
23
- memory_percent = psutil.virtual_memory().percent
 
24
 
25
- # Measure latency to google.com
26
- async with httpx.AsyncClient() as client:
27
- try:
28
- response = await client.get("https://www.discord.com")
29
- latency_ms = round(response.elapsed.total_seconds() * 1000) # Convert seconds to milliseconds and round
30
- except httpx.RequestError:
31
- latency_ms = "Error: Unable to connect to discord.com"
32
 
33
- return {
34
- "System Uptime": {
35
- "days": int(uptime_days),
36
- "hours": int(uptime_hours),
37
- "minutes": int(uptime_minutes),
38
- "seconds": int(uptime_seconds)
39
- },
40
- "CPU Usage": f"{cpu_percent}%",
41
- "Memory Usage": f"{memory_percent}%",
42
- "Latency to Google": f"{latency_ms} ms"
43
- }
 
1
  from fastapi import FastAPI
2
+ import discord
3
+ import os
 
4
 
5
  app = FastAPI()
6
 
7
+ # Initialize a Discord client
8
+ client = discord.Client()
 
 
 
 
 
9
 
10
+ # Discord bot token
11
+ BOT_TOKEN = os.getenv('DISCORD_TOKEN')
 
 
12
 
13
+ # Event to handle when the bot is ready
14
+ @client.event
15
+ async def on_ready():
16
+ print(f'We have logged in as {client.user}')
17
 
18
+ # Endpoint to get the status of the Discord bot
19
+ @app.get("/")
20
+ async def get_bot_status():
21
+ if client.is_ready():
22
+ return {"status": "Online"}
23
+ else:
24
+ return {"status": "Offline"}
25
 
26
+ # Start the Discord bot
27
+ client.run(BOT_TOKEN)