-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
306 lines (295 loc) · 16.9 KB
/
main.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
token="ТОКЕН БОТА"
from mcstatus import MinecraftServer
import discord
import requests,json,time,asyncio
from math import floor
import math
from datetime import datetime
import os,random
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import urllib.request
client = discord.Client()
inr=[]
tfcoords=[1100,100]
def get_updates(resp):
for player in resp['players']:
t=open(f"oplayers/{player['name']}.dat","w")
t.write(f"{player['world']}\n{player['x']}\nidk\n{player['z']}\n{player['yaw']}")
t.close()
'''
Одна из недоделок
def radd(client,radius, resp):
global inr
me={}
for player in resp['players']:
if player['name']=="#########":
me=player
break
if me=={}:
return
for player in resp['players']:
if player['name']==me['name']:
continue
if player['world']!=me['world'] and player['name'] in inr:
inr.remove(player['name'])
return f"`{player['name']}` покинул ваш радиус"
if player['world']!=me['world']:
continue
if player['x']-me['x']>100 and player['z']-me['z']>100 and player['name'] in inr:
inr.remove(player['name'])
return f"`{player['name']}` покинул ваш радиус "
if player['x'] in range(me['x']-100,me['x']+100) and player['z'] in range(me['z']-100,me['z']+100):
if player['name'] in inr:
return
inr.append(player['name'])
return f"`{player['name']}` в вашем радиусе"
'''
def sometext(link,yaw,pcx,pcz,cx,cz,plr,world,players):
if plr==None:
return {"err":False,"offline":True}
urllib.request.urlretrieve(link,f'tmp/{cx}_{cz}_{world}.png')
marker = Image.open("marker.png")
marker=marker.rotate(yaw)
img = Image.open(f'tmp/{cx}_{cz}_{world}.png')
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("Minecraft.otf", 10)
shadowcolor="black"
for player in players:
if plr['world']!=player['world']:
continue
text=player['name']
mark=marker.rotate(player['yaw'])
pcx=player['x']-cx*512
pcz=player['z']-cz*512
draw.text((pcx+10-1, pcz-1), text, font=font, fill=shadowcolor)
draw.text((pcx+10+1, pcz-1), text, font=font, fill=shadowcolor)
draw.text((pcx+10, pcz-1-1), text, font=font, fill=shadowcolor)
draw.text((pcx+10, pcz+1-1), text, font=font, fill=shadowcolor)
draw.text((pcx+10, pcz-1),text,font=font,fill="white")
img.paste(marker,(pcx,pcz),mark)
table=['a','b','c','d','e','f','g','h','i','g','k','l','m','n','o','p','q','r','a','t','u','v','w','x','y','z']
name=random.choice(table)+random.choice(table)+random.choice(table)+random.choice(table)+random.choice(table)+random.choice(table)+random.choice(table)+random.choice(table)+random.choice(table)+random.choice(table)
img.save(f"tmp/{cx}_{cz}_{world}_edited.png", "PNG")
return {"err":False,"text":f"`{plr['name']}` X: `{plr['x']}` Z: `{plr['z']}` Yaw: `{plr['yaw']}`","file":f"tmp/{cx}_{cz}_{world}_edited.png"}
def getmap(message):
try:
resp=json.loads(requests.get("https://map.reworlds.su/tiles/players.json", timeout=5).text)
except:
return {"err":True,"code":"RESP_ERR"}
for player in resp['players']:
if player['name']==message.content.split(" ")[1]:
chunkx=floor(player['x']/512)
chunkz=floor(player['z']/512)
yaw=player['yaw']
pcx=player['x']-chunkx*512
pcz=player['z']-chunkz*512
link=f"https://map.reworlds.su/tiles/{player['world']}/3/{chunkx}_{chunkz}.png"
return sometext(link,yaw,pcx,pcz,chunkx,chunkz,player,player['world'],resp['players'])
return
'''
Еще одна недоделка
async def radcord(client):
await client.wait_until_ready()
radius=client.get_user(######)
try:
resp=json.loads(requests.get("https://map.reworlds.su/tiles/players.json",timeout=5).text)
except:
print("Ошибка! Время: "+str(time.time()))
get_updates(resp)
mess=radd(client, radius, resp)
if mess!=None:
await radius.send(mess)
await asyncio.sleep(1)
'''
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=".help"))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('.tps'):
sname=''
tps={}
if message.content.split(" ")[1]=='1':
sname="Survival"
tps=json.loads(requests.get("https://api.reworlds.su/server/metrics?server=1").text)['last_entries']
elif message.content.split(" ")[1]=="2":
sname="Creative"
tps=json.loads(requests.get("https://api.reworlds.su/server/metrics?server=2").text)['last_entries']
else:
await message.channel.send(f"{message.author.mention}, Ты меня тут не путай! Не знаю я такого сервера!")
max=json.loads(requests.get("https://api.reworlds.su/server/metrics?server=1").text)['max_online']
players=json.loads(requests.get("https://map.reworlds.su/tiles/players.json").text)
online=0
for player in players['players']:
online+=1
bc=0x00ff00
if tps[0]['tps']<15:
bc=0xffff00
elif tps[0]['tps']<10:
bc=0xff0000
embedVar = discord.Embed(title="RevolutionWorlds TPS", description=f"Сервер {sname}, online {online}, Вызвано {message.author.mention}\n(онлайн) сколько сек назад\ntps", color=bc)
tpsa="{:.2f}".format(tps[0]['tps'])
embedVar.add_field(name=f"(`{tps[0]['online']}`) `{int(time.time()-tps[0]['time'])}`s", value=f"`{tpsa}`", inline=False)
tpsb="{:.2f}".format(tps[1]['tps'])
embedVar.add_field(name=f"(`{tps[1]['online']}`) `{int(time.time()-tps[1]['time'])}`s", value=f"`{tpsb}`", inline=False)
tpsc="{:.2f}".format(tps[2]['tps'])
embedVar.add_field(name=f"(`{tps[2]['online']}`) `{int(time.time()-tps[2]['time'])}`s", value=f"`{tpsc}`", inline=False)
embedVar.set_thumbnail(url="https://raw.githubusercontent.com/ROBGUI09/ROBGUI09/main/b534c131aa930c76dc6d6fc4c41145b6.webp")
embedVar.set_footer(text="сделано на коленке за 3 часа ночи\nбез любви - ROBGUI#3137")
await message.channel.send(embed=embedVar)
if message.content.startswith(".records"):
resp=json.loads(requests.get("https://api.reworlds.su/server/metrics?server=1").text)
embedVar = discord.Embed(title="Рекорды сервера", description=f"Сервер Survival, Вызвано {message.author.mention}", color=0x00ff00)
tpsa="{:.2f}".format(resp['max_entry']['tps'])
tpsb="{:.2f}".format(resp['max_day_entry']['tps'])
embedVar.add_field(name=f"Рекорд онлайна", value=f"Онлайн: `{resp['max_entry']['online']}` TPS: `{tpsa}`", inline=False)
embedVar.add_field(name=f"Рекорд онлайна за сегодня", value=f"Онлайн: `{resp['max_day_entry']['online']}` TPS: `{tpsb}`", inline=False)
embedVar.set_thumbnail(url="https://raw.githubusercontent.com/ROBGUI09/ROBGUI09/main/b534c131aa930c76dc6d6fc4c41145b6.webp")
embedVar.set_footer(text="сделано на коленке за 3 часа ночи\nбез любви - ROBGUI#3137")
await message.channel.send(embed=embedVar)
if message.content.startswith(".ping"):
ip=message.content.split(" ")[1]
server = MinecraftServer.lookup(ip)
try:
status = server.status()
except:
embedVar = discord.Embed(title=f"{ip} status", description=f"Ping: ∞, Вызвано {message.author.mention}", color=0xff0000)
embedVar.add_field(name="Ошибка!", value=f"Сервер не существует", inline=False)
await message.channel.send(embed=embedVar)
return
embedVar = discord.Embed(title=f"{ip} status", description=f"Ping: {status.latency}, Вызвано {message.author.mention}", color=0x00ff00)
embedVar.add_field(name="MOTD", value=f"{status.description}", inline=False)
cm=status.description.replace("§1","").replace("§2","").replace("§3","").replace("§4","").replace("§5","").replace("§6","").replace("§7","").replace("§8","").replace("§c","").replace("§e","").replace("§a","").replace("§b","").replace("§d","").replace("§f","").replace("§0","").replace("§m","").replace("§l","").replace("§o","").replace("§k","").replace("§r","").replace("§R","").replace("§L","").replace("§n","")
embedVar.add_field(name="ClearMOTD", value=f"{cm}", inline=False)
embedVar.add_field(name="Players", value=f"{status.players.online}", inline=False)
try:
embedVar.add_field(name="Query", value=f"{status.query}", inline=False)
except:
embedVar.add_field(name="Query", value=f"Cервер отключил query", inline=False)
embedVar.set_thumbnail(url="https://raw.githubusercontent.com/ROBGUI09/ROBGUI09/main/b534c131aa930c76dc6d6fc4c41145b6.webp")
embedVar.set_footer(text="сделано на коленке за 3 часа ночи\nбез любви - ROBGUI#3137")
await message.channel.send(embed=embedVar)
if message.content.startswith(".list"):
resp=json.loads(requests.get("https://map.reworlds.su/tiles/players.json").text)
pls=''
for i in resp['players']:
world=''
yaw="{:.2f}".format(i['yaw'])
if i['world']=="world":
if i['x'] in range(-100,100) and i['z'] in range(-100,100):
world="<:spawn:880149491016138812>"
else:
world="<:world:879849723618549831>"
if i['world']=="world_nether":
if i['x'] in range(-100,100) and i['z'] in range(-100,100):
world="<:nether_hub:880142881225080912>"
elif i['x']>100 and i['z'] in range(-4,4):
world="<:black:880157605492838450>"
else:
world="<:world_nether:879849392415342612>"
if i['world']=="world_the_end":
if i['x'] in range(-150,150) and i['z'] in range(-150,150):
world="<:end_main:880144288837664859>"
elif i['x'] in range(1100-150,1100+150) and i['z'] in range(100-150,100+150):
world="<:tf:880143064998481941>"
else:
world="<:world_the_end:879849539291471872>"
pls+=f"`{i['name']}` {world} X: `{i['x']}` Z: `{i['z']}` Yaw: `{yaw}`\n"
if len(pls)>1900:
await message.channel.send(pls)
pls=''
await message.channel.send(pls)
if message.content.startswith(".player"):
fm=''
resp=json.loads(requests.get("https://map.reworlds.su/tiles/players.json").text)
tpl={}
for player in resp['players']:
if player['name']==message.content.split(" ")[1]:
tpl=player
break
if tpl=={}:
embedVar = discord.Embed(title=f"Ошибка", description=f"Вызвана {message.author.mention}", color=0xff0000)
embedVar.add_field(name=f"А ты уверен что он онлайн?", value="Юзай .oplayer пжлст", inline=False)
embedVar.set_footer(text="ДОНАТЕРЫ МОГУТ СКРЫТЬСЯ\nбывают баги с тем что простые игроки тоже не видны\nсделано на коленке за 3 часа ночи\nбез любви - ROBGUI#3137")
await message.channel.send(embed=embedVar)
return
embedVar = discord.Embed(title=f"Данные о {tpl['name']}", description=f"{fm}Координаты игрока:", color=0x00ff00)
embedVar.add_field(name=f"Мир: `{tpl['world']}`", value=f"X: `{tpl['x']}`, Z: `{tpl['z']}` Yaw: `{tpl['yaw']}`", inline=False)
embedVar.set_thumbnail(url="https://raw.githubusercontent.com/ROBGUI09/ROBGUI09/main/b534c131aa930c76dc6d6fc4c41145b6.webp")
embedVar.set_footer(text="сделано на коленке за 3 часа ночи\nбез любви - ROBGUI#3137")
await message.channel.send(embed=embedVar)
if message.content.startswith(".oplayer"):
fm=''
msg=message.content.split(" ")
try:
resp=open(f"oplayers/{msg[1]}.dat","r").readlines()
except:
await message.channel.send("я хз о ком ты говоришь")
return
rep=json.loads(requests.get("https://map.reworlds.su/tiles/players.json").text)
for player in rep['players']:
if player['name']==message.content.split(" ")[1]:
await message.channel.send("Игрок онлайн!")
return
x=resp[1].rstrip("\n")
z=resp[3].rstrip("\n")
i={"world":resp[0].rstrip("\n")}
try:
yaw="{:.2f}".format(float(resp[4]))
except IndexError:
yaw="???"
world=''
if i['world']=="world":
if x in range(-100,100) and z in range(-100,100):
world="<:spawn:880149491016138812>"
else:
world="<:world:879849723618549831>"
if i['world']=="world_nether":
if x in range(-100,100) and z in range(-100,100):
world="<:nether_hub:880142881225080912>"
elif x>100 and z in range(-4,4):
world="<:black:880157605492838450>"
else:
world="<:world_nether:879849392415342612>"
if i['world']=="world_the_end":
if x in range(-150,150) and z in range(-150,150):
world="<:end_main:880144288837664859>"
elif x in range(1100-150,1100+150) and z in range(100-150,100+150):
world="<:tf:88014306499841941>"
else:
world="<:world_the_end:879849539291471872>"
name=message.content.split(" ")[1]
embedVar = discord.Embed(title=f"Данные о {name}", description=f"{fm}Вызвано {message.author.mention}, Координаты игрока:", color=0x00ff00)
embedVar.add_field(name=f"Мир: {world}", value=f"X: `{x}`, Z: `{z}` Yaw: `{yaw}`", inline=False)
embedVar.set_thumbnail(url="https://raw.githubusercontent.com/ROBGUI09/ROBGUI09/main/b534c131aa930c76dc6d6fc4c41145b6.webp")
embedVar.set_footer(text="сделано на коленке за 3 часа ночи\nбез любви - ROBGUI#3137")
await message.channel.send(embed=embedVar)
if message.content.startswith(".emoji"):
print(message.content)
if message.content.startswith(".help"):
embedVar = discord.Embed(title=f"Команды", description=f"Команды бота, Вызвано {message.author.mention}", color=0x00ff00)
embedVar.add_field(name=f".help", value=f"Вывести этот список", inline=False)
embedVar.add_field(name=f".oplayer (игрок)", value=f"Получить место выхода игрока на сервере*", inline=False)
embedVar.add_field(name=f".player (игрок)", value=f"Получить местоположение игрока на сервере*", inline=False)
embedVar.add_field(name=f".list", value=f"Список игроков сервера*", inline=False)
embedVar.add_field(name=f".ping (сервер)", value=f"Получить данные о сервере", inline=False)
embedVar.add_field(name=f".records", value=f"Рекорды сервера*", inline=False)
embedVar.add_field(name=f".tps 1(выживание)|2(креатив)", value=f"TPS сервера*", inline=False)
embedVar.add_field(name=f".map (игрок)", value=f"**НОВИНКА** показать игрока и ближайших к нему игрков на карте сервера*", inline=False)
embedVar.set_footer(text="сделано на коленке за 3 часа ночи\nбез любви - ROBGUI#3137\n* Подразумевает сервер RewolutionWorlds")
await message.channel.send(embed=embedVar)
if message.content.startswith(".map"):
data=getmap(message)
if data['err']:
await message.channel.send(f"Ошибка! Код ошибки:`{data['code']}`. Сообщите об этом ROBGUI#3137")
elif data==None:
await message.channel.send("чел офлайн но мне лень щас это фсе оформлять")
else:
await message.channel.send(content=data['text'],file=discord.File(data['file']))
#client.loop.create_task(radcord(client))
client.run(token)