Add temperature and uptime
This commit is contained in:
parent
db76ea2f8d
commit
ae9bbfa67a
60
main.py
60
main.py
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
@ -27,6 +28,13 @@ def check_status(service):
|
||||
return "✅ Running"
|
||||
return "❌ Stopped"
|
||||
|
||||
def get_temperature():
|
||||
try:
|
||||
return json.loads(subprocess.check_output(["sensors", "-Aj"]))
|
||||
except subprocess.CalledProcessError as err:
|
||||
return {}
|
||||
|
||||
|
||||
bot = commands.Bot(command_prefix=config.command_prefix)
|
||||
|
||||
|
||||
@ -41,6 +49,27 @@ async def on_ready():
|
||||
game = discord.Game(f"Disponible ✅ | {bot.command_prefix}help")
|
||||
await bot.change_presence(status=discord.Status.idle, activity=game)
|
||||
|
||||
embed = discord.Embed(colour=discord.Colour.blue())
|
||||
embed.set_author(name=time.strftime("%m-%d-%Y %H:%M"))
|
||||
embed.add_field(
|
||||
name="Redémarrage", value="Le bot est à nouveau en ligne"
|
||||
)
|
||||
temperature = get_temperature()
|
||||
for key1 in temperature.keys():
|
||||
for key2 in temperature[key1].keys():
|
||||
for key3 in temperature[key1][key2].keys():
|
||||
if "input" in key3:
|
||||
embed.add_field(
|
||||
name=f"Temp: {key1} > {key2} > {key3}", value=str(temperature[key1][key2][key3])
|
||||
)
|
||||
|
||||
embed.add_field(
|
||||
name="Uptime", value=subprocess.check_output(["uptime", "-p"]).decode("utf-8")
|
||||
)
|
||||
for discord_id in config.allowed_users:
|
||||
user = await bot.fetch_user(discord_id)
|
||||
await user.send(embed=embed)
|
||||
|
||||
services_status = {service:check_status(service) for service in config.services}
|
||||
while True:
|
||||
new_services_status = {service:check_status(service) for service in config.services}
|
||||
@ -50,7 +79,7 @@ async def on_ready():
|
||||
embed = discord.Embed(colour=discord.Colour.blue())
|
||||
embed.set_author(name=time.strftime("%m-%d-%Y %H:%M"))
|
||||
embed.add_field(
|
||||
name=service, value=new_services_status[service], inline=False
|
||||
name=service, value=new_services_status[service], inline=True
|
||||
)
|
||||
for discord_id in config.allowed_users:
|
||||
user = await bot.fetch_user(discord_id)
|
||||
@ -137,4 +166,33 @@ async def logs(ctx, *args):
|
||||
with open(os.path.join(config.logs_dir, f"{args[0]}.txt"), "r") as fp:
|
||||
await ctx.reply(file=discord.File(fp, filename=f"{args[0]}.txt"))
|
||||
|
||||
|
||||
@bot.command(name="temperature")
|
||||
@login_required
|
||||
async def temperature(ctx):
|
||||
embed = discord.Embed(colour=discord.Colour.blue())
|
||||
embed.set_author(name=time.strftime("%m-%d-%Y %H:%M"))
|
||||
temperature = get_temperature()
|
||||
for key1 in temperature.keys():
|
||||
for key2 in temperature[key1].keys():
|
||||
for key3 in temperature[key1][key2].keys():
|
||||
if "input" in key3:
|
||||
embed.add_field(
|
||||
name=f"Temp: {key1} > {key2} > {key3}", value=str(temperature[key1][key2][key3])
|
||||
)
|
||||
|
||||
await ctx.reply(embed=embed)
|
||||
|
||||
|
||||
@bot.command(name="uptime")
|
||||
@login_required
|
||||
async def uptime(ctx):
|
||||
embed = discord.Embed(colour=discord.Colour.blue())
|
||||
embed.set_author(name=time.strftime("%m-%d-%Y %H:%M"))
|
||||
embed.add_field(
|
||||
name="Uptime", value=subprocess.check_output(["uptime", "-p"]).decode("utf-8")
|
||||
)
|
||||
|
||||
await ctx.reply(embed=embed)
|
||||
|
||||
bot.run(config.TOKEN)
|
||||
|
Loading…
Reference in New Issue
Block a user