mirror of
https://github.com/TakeusV1/gameserver_discordpy_bot.git
synced 2026-10-13 17:15:34 +02:00
Ptero UPDATE
Ptero Update
This commit is contained in:
1 parent
db5a09168c
commit
5aae14721e
2 files changed
+73
-7
No files matched your search
@@ -2,13 +2,14 @@
|
||||
|
||||
### Dépendances
|
||||
`pip3 install discord.py`<br>
|
||||
`pip3 install mcstatus`
|
||||
|
||||
`pip3 install mcstatus`<br>
|
||||
*optionnel*<br>
|
||||
`pip3 install py-dactyl`
|
||||
### Configuration
|
||||
Il faut modifier les lignes suivantes:<br>
|
||||
`token = 'xxxxxxxxxxxxxxx'`<br>
|
||||
`server_ip = 'xx.xx.xx.xx'`<br>
|
||||
`server_port = 'xxxxx'`
|
||||
`server_port = 'xxxxx'`<br>
|
||||
|
||||
### Mise en PROD
|
||||
On peut utiliser par exemple **PM2**:
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
import discord
|
||||
from asyncio import sleep
|
||||
from discord.ext import tasks, commands
|
||||
from mcstatus import JavaServer
|
||||
|
||||
## Config
|
||||
token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' # Token BOT
|
||||
token = 'xxxxxxxxxxxxxxxxx' # Token BOT
|
||||
server_ip = 'xx.xx.xx.xx' # Addresse IP
|
||||
server_port = 'xxxxx' # Port
|
||||
bot_prefix = '!!' # Préfixe
|
||||
|
||||
bot = discord.Client()
|
||||
## 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 = discord.Client()
|
||||
bot = commands.Bot(command_prefix=bot_prefix)
|
||||
|
||||
@bot.event
|
||||
@@ -42,12 +49,70 @@ async def info(ctx):
|
||||
|
||||
@bot.command()
|
||||
async def cmd(ctx):
|
||||
await ctx.channel.send(f"__**Liste des Commandes**__:\n {bot_prefix}info *(Affiche les informations du Serveur)*")
|
||||
await ctx.channel.send(f"__**Liste des Commandes Utilisateur**__:\n {bot_prefix}info *(Affiche les informations du Serveur.)*\n {bot_prefix}ping *(Permet de savoir si le BOT est en marche.)*")
|
||||
if ptero_enable:
|
||||
await ctx.channel.send(f"__**Liste des Commandes Administrateur**__:\n {bot_prefix}sinfo *(Affiche des informations poussées du Serveur.)*\n {bot_prefix}power *(Permet d'effectuer des actions sur le serveur)*\n {bot_prefix}console *(Permet d'executer des commandes sur le serveur)*")
|
||||
|
||||
@bot.command()
|
||||
async def ping(ctx):
|
||||
await ctx.channel.send(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 2022
|
||||
Reference in new issue
Block a user