Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import discord
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
import time
|
6 |
+
|
7 |
+
intents = discord.Intents.default()
|
8 |
+
intents.message_content = True
|
9 |
+
|
10 |
+
client = discord.Client(intents=intents)
|
11 |
+
|
12 |
+
|
13 |
+
@client.event
|
14 |
+
async def on_ready():
|
15 |
+
print('We have logged in as {0.user}'.format(client))
|
16 |
+
|
17 |
+
|
18 |
+
@client.event
|
19 |
+
async def on_message(message):
|
20 |
+
print(f'{message.author}: {message.content}')
|
21 |
+
if message.author == client.user:
|
22 |
+
return
|
23 |
+
if message.content == '.hello':
|
24 |
+
await message.channel.send('Hello!')
|
25 |
+
if message.content == '.time':
|
26 |
+
await message.channel.send(time.asctime(time.localtime(time.time())) + ' UTC')
|
27 |
+
if message.content == '.quote':
|
28 |
+
api = "https://v1.hitokoto.cn/"
|
29 |
+
response = requests.get(api)
|
30 |
+
json_data = json.loads(response.text)
|
31 |
+
await message.channel.send(json_data['hitokoto'] + ' ——' + json_data['from'])
|
32 |
+
if message.content == '.florrmap':
|
33 |
+
# map_url_old = 'https://raw.githubusercontents.com/xcx0902/images/main/florr/map-5.3.png'
|
34 |
+
map_url = 'https://raw.githubusercontents.com/xcx0902/images/main/florr/map24-4.13.png'
|
35 |
+
await message.channel.send(map_url)
|
36 |
+
if message.content == '.florrserver':
|
37 |
+
await message.channel.send('Try to get server info from api...')
|
38 |
+
answer = ''
|
39 |
+
mpname = {
|
40 |
+
0: 'Garden ',
|
41 |
+
1: 'Desert ',
|
42 |
+
2: 'Ocean ',
|
43 |
+
3: 'Jungle ',
|
44 |
+
4: 'Ant Hell',
|
45 |
+
5: 'Sewers '
|
46 |
+
}
|
47 |
+
for i in range(0, 6):
|
48 |
+
answer += mpname[i] + ' '
|
49 |
+
api = 'https://api.n.m28.io/endpoint/florrio-map-' + str(i) + '-green/findEach/'
|
50 |
+
response = requests.get(api)
|
51 |
+
json_data = json.loads(response.text)
|
52 |
+
server_list = [('miami', 'US'), ('frankfurt', 'EU'), ('tokyo', 'AS')]
|
53 |
+
for (id, region) in server_list:
|
54 |
+
answer += '| ' + region + ': ' + json_data['servers']['vultr-' + id]['id'] + ' '
|
55 |
+
answer += '\n'
|
56 |
+
await message.channel.send('```' + answer + '```')
|
57 |
+
await message.channel.send(
|
58 |
+
'Try using the following code in the browser console to change the server:\n'
|
59 |
+
'```javascript\ncp6.forceServerID(\'<serverid>\');\n```'
|
60 |
+
)
|
61 |
+
if message.content.startswith('.tetriouser'):
|
62 |
+
username = message.content.split(' ')[1].lower()
|
63 |
+
api = 'https://ch.tetr.io/api/users/' + username
|
64 |
+
response = requests.get(api)
|
65 |
+
json_data = json.loads(response.text)
|
66 |
+
if json_data['success'] is False:
|
67 |
+
await message.channel.send('User not found')
|
68 |
+
else:
|
69 |
+
await message.channel.send(
|
70 |
+
'The following data may be cached, so it may not be accurate:'
|
71 |
+
)
|
72 |
+
json_data = json_data['data']['user']
|
73 |
+
answer = ''
|
74 |
+
answer += f'Username: {json_data["username"].upper()}\n'
|
75 |
+
answer += f'ID: {json_data["_id"]}\n'
|
76 |
+
answer += f'XP: {json_data["xp"]}\n'
|
77 |
+
try:
|
78 |
+
json_data = json_data['league']
|
79 |
+
rank = '?' if json_data['rank'] == 'z' else json_data['rank']
|
80 |
+
answer += f'League Rank: {rank.upper()}\n'
|
81 |
+
answer += f'League Rating: {json_data["rating"]}\n'
|
82 |
+
answer += f'League GW/GP: {json_data["gameswon"]}/{json_data["gamesplayed"]}'
|
83 |
+
answer += f' ({json_data["gameswon"]/json_data["gamesplayed"]*100}%)\n'
|
84 |
+
best_rank = '?' if json_data['bestrank'] == 'z' else json_data['bestrank']
|
85 |
+
answer += f'League Best Rank: {best_rank.upper()}\n'
|
86 |
+
answer += f'League APM: {json_data["apm"]}\n'
|
87 |
+
answer += f'League PPS: {json_data["pps"]}\n'
|
88 |
+
answer += f'League VS: {json_data["vs"]}\n'
|
89 |
+
answer += f'League Percentile: {json_data["percentile"]}\n'
|
90 |
+
except BaseException:
|
91 |
+
pass
|
92 |
+
await message.channel.send('```' + answer + '```')
|
93 |
+
if message.content == '.help':
|
94 |
+
await message.channel.send(
|
95 |
+
'.hello : Say hello to the bot (You will get a hello back)\n'
|
96 |
+
'.time : Show the date and time now\n'
|
97 |
+
'.quote : Get a random quote from hitokoto\n'
|
98 |
+
'.florrmap : Show the florr.io map\n'
|
99 |
+
'.florrserver : Get florr.io server info\n'
|
100 |
+
'.tetriouser <username> : Get tetr.io user info\n'
|
101 |
+
'.help : Show this message'
|
102 |
+
)
|
103 |
+
|
104 |
+
|
105 |
+
# print(os.getenv("TOKEN"))
|
106 |
+
client.run(os.getenv('TOKEN'))
|