File size: 4,501 Bytes
bb6a34f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import discord
import json
import os
import requests
import time

intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)


@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))


@client.event
async def on_message(message):
    print(f'{message.author}: {message.content}')
    if message.author == client.user:
        return
    if message.content == '.hello':
        await message.channel.send('Hello!')
    if message.content == '.time':
        await message.channel.send(time.asctime(time.localtime(time.time())) + ' UTC')
    if message.content == '.quote':
        api = "https://v1.hitokoto.cn/"
        response = requests.get(api)
        json_data = json.loads(response.text)
        await message.channel.send(json_data['hitokoto'] + ' β€”β€”' + json_data['from'])
    if message.content == '.florrmap':
        # map_url_old = 'https://raw.githubusercontents.com/xcx0902/images/main/florr/map-5.3.png'
        map_url = 'https://raw.githubusercontents.com/xcx0902/images/main/florr/map24-4.13.png'
        await message.channel.send(map_url)
    if message.content == '.florrserver':
        await message.channel.send('Try to get server info from api...')
        answer = ''
        mpname = {
            0: 'Garden  ',
            1: 'Desert  ',
            2: 'Ocean   ',
            3: 'Jungle  ',
            4: 'Ant Hell',
            5: 'Sewers  '
        }
        for i in range(0, 6):
            answer += mpname[i] + ' '
            api = 'https://api.n.m28.io/endpoint/florrio-map-' + str(i) + '-green/findEach/'
            response = requests.get(api)
            json_data = json.loads(response.text)
            server_list = [('miami', 'US'), ('frankfurt', 'EU'), ('tokyo', 'AS')]
            for (id, region) in server_list:
                answer += '| ' + region + ': ' + json_data['servers']['vultr-' + id]['id'] + ' '
            answer += '\n'
        await message.channel.send('```' + answer + '```')
        await message.channel.send(
            'Try using the following code in the browser console to change the server:\n'
            '```javascript\ncp6.forceServerID(\'<serverid>\');\n```'
        )
    if message.content.startswith('.tetriouser'):
        username = message.content.split(' ')[1].lower()
        api = 'https://ch.tetr.io/api/users/' + username
        response = requests.get(api)
        json_data = json.loads(response.text)
        if json_data['success'] is False:
            await message.channel.send('User not found')
        else:
            await message.channel.send(
                'The following data may be cached, so it may not be accurate:'
            )
            json_data = json_data['data']['user']
            answer = ''
            answer += f'Username: {json_data["username"].upper()}\n'
            answer += f'ID: {json_data["_id"]}\n'
            answer += f'XP: {json_data["xp"]}\n'
            try:
                json_data = json_data['league']
                rank = '?' if json_data['rank'] == 'z' else json_data['rank']
                answer += f'League Rank: {rank.upper()}\n'
                answer += f'League Rating: {json_data["rating"]}\n'
                answer += f'League GW/GP: {json_data["gameswon"]}/{json_data["gamesplayed"]}'
                answer += f' ({json_data["gameswon"]/json_data["gamesplayed"]*100}%)\n'
                best_rank = '?' if json_data['bestrank'] == 'z' else json_data['bestrank']
                answer += f'League Best Rank: {best_rank.upper()}\n'
                answer += f'League APM: {json_data["apm"]}\n'
                answer += f'League PPS: {json_data["pps"]}\n'
                answer += f'League VS: {json_data["vs"]}\n'
                answer += f'League Percentile: {json_data["percentile"]}\n'
            except BaseException:
                pass
            await message.channel.send('```' + answer + '```')
    if message.content == '.help':
        await message.channel.send(
            '.hello : Say hello to the bot (You will get a hello back)\n'
            '.time : Show the date and time now\n'
            '.quote : Get a random quote from hitokoto\n'
            '.florrmap : Show the florr.io map\n'
            '.florrserver : Get florr.io server info\n'
            '.tetriouser <username> : Get tetr.io user info\n'
            '.help : Show this message'
        )


# print(os.getenv("TOKEN"))
client.run(os.getenv('TOKEN'))