- removing the pterodactyl integration
- Integration of the source query
- Fixes
This commit is contained in:
Takeus committed 2023-01-26 20:02:29 +01:00
1 parent 008d01b650
commit d370f7ec33
1 file changed
+45 -85
+45 -85
View File
@@ -3,24 +3,19 @@ from discord import app_commands
from discord.ext import commands
from discord.ext.commands import has_permissions, BotMissingPermissions
from discord.ext import tasks, commands
from mcstatus import JavaServer
## Config
token = 'xxxxxxxxxxxxxxx' # Token BOT
server_ip = 'xx.xx.xx.xx' # Addresse IP
server_ip = 'xx.xx.xx.xx' # Addresse IP
server_port = 'xxxxx' # Port
bot_prefix = '!!' # Préfixe
mcOs = True #IF True = Minecraft Serve OR IF False = Source Server (like gmod,csgo...)
## Pterodactyl Config
ptero_enable = False
if ptero_enable:
ptero_link = 'https://ptero.example.fr' # FQDN De votre Pterodactyl
ptero_clientapi = '' # Clé API de votre compte Pterodactyl
ptero_serverid = '' # Identifiant (Abrégé) du serveur
discord_admins_id = [] # Identifiant (Discord) des utilisateurs pouvant interagir avec les commandes...
bot = commands.Bot(command_prefix='!!',intents = discord.Intents.default())
#bot = discord.Client()
bot = commands.Bot(command_prefix=bot_prefix,intents = discord.Intents.all())
if mcOs:
from mcstatus import JavaServer
else:
from sourceserver.sourceserver import SourceServer
@bot.event
async def on_ready():
@@ -37,12 +32,21 @@ async def on_ready():
@tasks.loop(seconds=5)
async def loop():
try:
server = JavaServer.lookup(str(server_ip+':'+server_port))
status = server.status()
if status.players.online == 0:
await bot.change_presence(activity=discord.Game(name="{}/{} Joueurs".format(status.players.online,status.players.max)),status=discord.Status.idle)
# minecraft server
if mcOs:
server = JavaServer.lookup(str(server_ip+':'+server_port))
status = server.status()
if status.players.online == 0:
await bot.change_presence(activity=discord.Game(name="{}/{} Joueurs".format(status.players.online,status.players.max)),status=discord.Status.idle)
else:
await bot.change_presence(activity=discord.Game(name="{}/{} Joueurs".format(status.players.online,status.players.max)),status=discord.Status.online)
else:
await bot.change_presence(activity=discord.Game(name="{}/{} Joueurs".format(status.players.online,status.players.max)),status=discord.Status.online)
# source server
srv = SourceServer(str(server_ip+':'+server_port))
if int(srv.info['players']) == 0:
await bot.change_presence(activity=discord.Game(name="{}/{} Joueurs".format(srv.info['players'],srv.info['max_players'])),status=discord.Status.idle)
else:
await bot.change_presence(activity=discord.Game(name="{}/{} Joueurs".format(srv.info['players'],srv.info['max_players'])),status=discord.Status.online)
except:
await bot.change_presence(activity=discord.Game(name="Serveur Hors-Ligne"),status=discord.Status.dnd)
@@ -50,17 +54,30 @@ async def loop():
@bot.tree.command(name="serverinfo", description="Affiche les informations du serveur.")
async def serverinfo(interaction: discord.Interaction):
try:
server = JavaServer.lookup(str(server_ip+':'+server_port))
status = server.status()
#await ctx.channel.send("__**Joueurs**__: {}/{}\n__**Latence**__: {} *ms*".format(status.players.online,status.players.max,server.ping()))
embed=discord.Embed(color=0xff8000)
embed.add_field(name='Joueurs', value=status.players.online, inline=True)
embed.add_field(name='Slots', value=status.players.max, inline=True)
embed.add_field(name='Latence', value=str(status.latency)+' ms', inline=True)
embed.add_field(name='Addresse', value=server_ip, inline=True)
embed.add_field(name='Port', value=server_port, inline=True)
embed.add_field(name='Version', value=status.version.name, inline=True)
await interaction.response.send_message(embed=embed)
# minecraft server
if mcOs:
server = JavaServer.lookup(str(server_ip+':'+server_port))
status = server.status()
#await ctx.channel.send("__**Joueurs**__: {}/{}\n__**Latence**__: {} *ms*".format(status.players.online,status.players.max,server.ping()))
embed=discord.Embed(color=0xff8000)
embed.add_field(name='Joueurs', value=status.players.online, inline=True)
embed.add_field(name='Slots', value=status.players.max, inline=True)
embed.add_field(name='Latence', value=str(status.latency)+' ms', inline=True)
embed.add_field(name='Addresse', value=server_ip, inline=True)
embed.add_field(name='Port', value=server_port, inline=True)
embed.add_field(name='Version', value=status.version.name, inline=True)
await interaction.response.send_message(embed=embed)
# source server
else:
srv = SourceServer(str(server_ip+':'+server_port))
embed=discord.Embed(title=srv.info['name'], color=0x0080ff)
embed.add_field(name='Joueurs', value=srv.info['players'], inline=True)
embed.add_field(name='Slots', value=srv.info['max_players'], inline=True)
embed.add_field(name='Latence', value=srv.ping(2), inline=True)
embed.add_field(name='Gamemode', value=srv.info['game'], inline=True)
embed.add_field(name='Map', value=srv.info['map'], inline=True)
embed.add_field(name='Version', value=srv.info['version'], inline=True)
await interaction.response.send_message(embed=embed)
except:
await interaction.response.send_message("Serveur Hors-Ligne")
@@ -68,62 +85,5 @@ async def serverinfo(interaction: discord.Interaction):
async def serverinfo(interaction: discord.Interaction):
await interaction.response.send_message(f'Bot UP !\nLatence: {round(bot.latency, 1)}')
if ptero_enable:
from pydactyl import PterodactylClient
api = PterodactylClient(ptero_link, ptero_clientapi)
#print(api.client.servers.get_server_utilization(ptero_serverid))
@bot.command()
async def sinfo(ctx):
if ctx.author.id in discord_admins_id:
infoserver = api.client.servers.get_server_utilization(ptero_serverid)
if infoserver['current_state'] == 'offline':
embed=discord.Embed(color=0xff0000)
embed.add_field(name='STATUS', value=infoserver['current_state'], inline=True)
embed.add_field(name='DISK', value=str(round(float(infoserver['resources']['disk_bytes'])/1024/1024))+' MO', inline=True)
else:
if infoserver['current_state'] == 'starting':
embed=discord.Embed(color=0xffff00)
else:
embed=discord.Embed(color=0x00ff00)
embed.add_field(name='STATUS', value=infoserver['current_state'], inline=True)
embed.add_field(name='CPU', value=str(round(infoserver['resources']['cpu_absolute']))+' %', inline=True)
embed.add_field(name='RAM', value=str(round(float(infoserver['resources']['memory_bytes'])/1024/1024))+' MO', inline=True)
embed.add_field(name='DISK', value=str(round(float(infoserver['resources']['disk_bytes'])/1024/1024))+' MO', inline=True)
await ctx.send(embed=embed)
else:
await ctx.channel.send("Vous n'avez pas l'autorisation d'utiliser cette commande.")
@bot.command()
async def power(ctx, arg):
if ctx.author.id in discord_admins_id:
if arg == 'start':
api.client.servers.send_power_action(ptero_serverid,'start')
await ctx.channel.send("Commande envoyé !")
elif arg == 'stop':
api.client.servers.send_power_action(ptero_serverid,'stop')
await ctx.channel.send("Commande envoyé !")
elif arg == 'kill':
api.client.servers.send_power_action(ptero_serverid,'kill')
await ctx.channel.send("Commande envoyé !")
else:
await ctx.channel.send("Argument invalide. Les options sont: **start, stop, kill**")
else:
await ctx.channel.send("Vous n'avez pas l'autorisation d'utiliser cette commande.")
@bot.command()
async def console(ctx, arg):
if ctx.author.id in discord_admins_id:
api.client.servers.send_console_command(ptero_serverid,arg)
await ctx.channel.send("Commande envoyé !")
else:
await ctx.channel.send("Vous n'avez pas l'autorisation d'utiliser cette commande.")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send('Cette commande nécéssite un Argument.')
bot.run(token)
## Takeus 2023