-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
89 lines (80 loc) · 4.07 KB
/
app.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import discord
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import has_permissions, BotMissingPermissions
from discord.ext import tasks, commands
## Config
token = 'xxxxxxxxxxxxxxx' # Token BOT
server_ip = 'xx.xx.xx.xx' # Addresse IP
server_port = 'xxxxx' # Port
mcOs = True #IF True = Minecraft Serve OR IF False = Source Server (like gmod,csgo...)
bot = commands.Bot(command_prefix='!!',intents = discord.Intents.default())
if mcOs:
from mcstatus import JavaServer
else:
from sourceserver.sourceserver import SourceServer
@bot.event
async def on_ready():
if not loop.is_running():
loop.start()
print('Ready')
## commands
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} commands")
except Exception as e:
print(e)
@tasks.loop(seconds=5)
async def loop():
try:
# 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:
# 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)
@bot.tree.command(name="serverinfo", description="Affiche les informations du serveur.")
async def serverinfo(interaction: discord.Interaction):
try:
# 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")
@bot.tree.command(name="ping", description="latence du bot")
async def serverinfo(interaction: discord.Interaction):
await interaction.response.send_message(f'Bot UP !\nLatence: {round(bot.latency, 1)}')
bot.run(token)
## Takeus 2023