-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
140 lines (119 loc) · 5.4 KB
/
bot.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
### Lib ###
import nextcord
import datetime
from nextcord.ext import commands, tasks
from requests import get
### Config ###
BOT_TOKEN = '' #Required
SERVER_IP = '' #Required
SERVER_PORT = '' #Required
CONNECT = '' #Recommended
SERVER_NAME = '' #Recommended
STATUS_IMAGE = '' #Optional
SECONDS = 15 #Required
CHANNEL_ID = 1 #Required
MESSAGE_ID = 1 #Required
ERRORCOLOR = 0xff0000
DONECOLOR = 0x00ff2e
### Setup ###
class Bot(commands.Bot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
bot = Bot()
### Bot ###
@bot.event
async def on_ready():
await bot.change_presence(activity=nextcord.Activity(type=nextcord.ActivityType.playing, name='''💖 By Mat#3616 - github.com/itsmat'''))
print('\nBot Online - github.com/itsmat')
if SERVER_IP == '':
print('SERVER_IP MISSING')
if SERVER_PORT == '':
print('SERVER_PORT MISSING')
if CONNECT == '':
print('CONNECT MISSING')
if CHANNEL_ID == 1:
print('CHANNEL_ID MISSING')
if MESSAGE_ID == 1:
print('MESSAGE_ID MISSING')
@bot.slash_command(
name="status",
description="Server Status",
)
async def status(interaction: nextcord.Interaction):
try:
if SERVER_IP and SERVER_PORT != '':
filedynamic = get(f'http://{SERVER_IP}:{SERVER_PORT}/dynamic.json', timeout=10)
filedynamic = filedynamic.json()
playersonline = str(filedynamic["clients"])
playersmassimi = str(filedynamic["sv_maxclients"])
embed=nextcord.Embed(title="", description=f"**Connect:** `connect {CONNECT}`\n**Players:** {playersonline}/{playersmassimi}", color=DONECOLOR)
embed.set_author(name=F"{SERVER_NAME} Status", url="https://github.com/itsmat", icon_url=STATUS_IMAGE)
if STATUS_IMAGE != '':
embed.set_image(url=STATUS_IMAGE)
else:
pass
embed.set_footer(text="""💖 By Mat#3616 - github.com/itsmat""")
await interaction.send(embed=embed)
else:
if SERVER_IP == '':
print('SERVER_IP MISSING')
if SERVER_PORT == '':
print('SERVER_PORT MISSING')
if CONNECT == '':
print('CONNECT MISSING')
embed=nextcord.Embed(title="Error", description=f"Missing data", color=ERRORCOLOR)
embed.set_footer(text="""💖 By Mat#3616 - github.com/itsmat""")
await interaction.send(embed=embed)
except Exception as errore:
print(f'[/Status Error] {errore}')
@bot.slash_command(
name="createstatus",
description="Create Status Message",
)
async def createstatus(interaction: nextcord.Interaction):
embed=nextcord.Embed(title="Ok", description=f"Channel ID: `{interaction.channel.id}`", color=DONECOLOR)
embed.set_footer(text="""💖 By Mat#3616 - github.com/itsmat""")
await interaction.send(embed=embed)
@tasks.loop(seconds = SECONDS)
async def autostatus():
print("[AutoStatus] Searching for info...")
try:
await bot.wait_until_ready()
filedynamic = get(f'http://{SERVER_IP}:{SERVER_PORT}/dynamic.json', timeout=10)
fileplayers = get(f'http://{SERVER_IP}:{SERVER_PORT}/players.json', timeout=10)
canale = bot.get_channel(CHANNEL_ID)
messaggio = await canale.fetch_message(MESSAGE_ID)
if filedynamic.status_code == 200 or fileplayers.status_code == 200 :
filedynamic = filedynamic.json()
fileplayers = fileplayers.json()
embed=nextcord.Embed(color=DONECOLOR, timestamp = datetime.datetime.utcnow())
embed.add_field(name="IP Fivem", value=f"```connect {CONNECT}```", inline=False)
embed.add_field(name="Players", value='```ini\n[' + str(filedynamic["clients"]) + "/" + str(filedynamic["sv_maxclients"]) + ']\n```', inline=True)
embed.add_field(name="Status", value=f"""```fix
Online
```""", inline=True)
embed.set_author(name=SERVER_NAME, url="https://github.com/itsmat", icon_url=STATUS_IMAGE)
embed.set_thumbnail(url=STATUS_IMAGE)
embed.set_footer(text='''💖 By Mat#3616 - github.com/itsmat''', icon_url=STATUS_IMAGE)
try:
await messaggio.edit(embed=embed)
except Exception:
print("[AutoStatus] Message not editable, reset it")
else:
embed=nextcord.Embed(color=0x5a03fc, timestamp = datetime.datetime.utcnow())
embed.add_field(name="IP Fivem", value=f"```connect {CONNECT}```", inline=False)
embed.add_field(name="Players", value='```ini\n[Server Offline]\n```', inline=True)
embed.add_field(name="Status", value=f"""```fix
Offline
```""", inline=True)
embed.set_author(name=SERVER_NAME, url="https://github.com/itsmat", icon_url=STATUS_IMAGE)
embed.set_thumbnail(url=STATUS_IMAGE)
embed.set_footer(text='''💖 By Mat#3616 - github.com/itsmat''', icon_url=STATUS_IMAGE)
try:
await messaggio.edit(embed=embed)
except Exception:
print("[AutoStatus] Message not editable, reset it")
except Exception as errore:
print(f'[AutoStatus Error] {errore}')
autostatus.start()
bot.run(BOT_TOKEN)