#!/usr/bin/python3 import asyncio import time import os import requests import discord from discord.ext import commands import config def login_required(fn): async def decorated_fn(ctx, *args): if str(ctx.author.id) not in config.allowed_users: await ctx.reply("Vous n'êtes pas autorisé à exécuter cette fonction.") return None return await fn(ctx, *args) return decorated_fn def check_status(service): """Renvoie le statut d'un service""" service_status = os.system(f"systemctl is-active --quiet {service}") if service_status == 0: return "✅ Running" return "❌ Stopped" bot = commands.Bot(command_prefix=config.command_prefix) @bot.event async def on_ready(): """On ready""" print("Connecté en tant que:") print(bot.user.name) print(bot.user.id) print("------") game = discord.Game(f"Disponible ✅ | {bot.command_prefix}help") await bot.change_presence(status=discord.Status.idle, activity=game) 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} for service in new_services_status.keys(): if new_services_status[service] != services_status[service]: 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 ) for discord_id in config.allowed_users: user = await bot.fetch_user(discord_id) await user.send(embed=embed) services_status = new_services_status await asyncio.sleep(300) @bot.command(name="status") @login_required async def status(ctx): """Renvoie le statut des différents services""" embed = discord.Embed(colour=discord.Colour.blue()) embed.set_author(name=time.strftime("%m-%d-%Y %H:%M")) for service in config.services: service_status = check_status(service) embed.add_field( name=service, value=service_status, inline=False ) await ctx.reply(embed=embed) bot.run(config.TOKEN)