Repository navigation
Expand file tree
/
Copy pathbot.py
More file actions
57 lines (47 loc) · 1.85 KB
/
Copy pathbot.py
File metadata and controls
57 lines (47 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import subprocess
import signal
import discord
from discord import app_commands
from dotenv import load_dotenv
import os
load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
factorio_process = None # process global
class MyClient(discord.Client):
def __init__(self):
super().__init__(intents=intents)
self.tree = app_commands.CommandTree(self)
async def on_ready(self):
await self.tree.sync()
print(f"Connecté en tant que {self.user} (slash commands prêtes)")
client = MyClient()
@client.tree.command(name="up", description="Lance le serveur Factorio")
async def up(interaction: discord.Interaction):
global factorio_process
if factorio_process is None:
await interaction.response.send_message("Serveur Factorio lancé")
factorio_process = subprocess.Popen([
"/opt/factorio/bin/x64/factorio",
"--start-server",
"newgame.zip"
])
else:
await interaction.response.send_message("Le serveur est déjà démarré")
@client.tree.command(name="down", description="Arrête le serveur Factorio")
async def down(interaction: discord.Interaction):
global factorio_process
if factorio_process:
await interaction.response.send_message("Tentative d'arrêt du serveur...")
factorio_process.send_signal(signal.SIGINT)
factorio_process.wait()
await interaction.followup.send("Serveur arrêté.")
factorio_process = None
else:
await interaction.response.send_message("Le serveur n'est pas en cours d'exécution.")
@client.tree.command(name="shutdown", description="Arrete la machine et en conséquence le bot et le serveur.")
async def shutdown(interaction:discord.Interaction):
subprocess.Popen(["shutdown", "now"])
# Ton token ici
TOKEN = os.getenv('PYTHON_TOKEN_BOT')
client.run(TOKEN)