-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.py
72 lines (66 loc) · 2.04 KB
/
widget.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
from vkbottle.bot import Bot
from bot import bot as group_bot
import config
import data
bot = Bot(config.VK_WIDGET)
async def generate_code():
# виджет топ 5
users_count = await group_bot.api.messages.get_conversations()
users_count = users_count.count
top = await data.get_top()
users = await bot.api.users.get(user_ids=[user[0] for user in top])
names = [f"{user.first_name} {user.last_name[0]}." for user in users]
users = []
emojis = ["🥇", "🥈", "🥉"]
for i, user in enumerate(top):
refs = await data.get_ref_count(user[0])
level = await data.get_level(user[0])
users.append({
"top": emojis[i] if i < 3 else '🏅',
"id": user[0],
"score": "{:,}".format(user[1]).replace(",", " "),
"name": names[i],
"level": level,
"friends": refs
})
widget = {
"title": f"🏆 Топ 5 игроков (из {users_count})",
"title_url": "https://vk.me/soviet_clicker",
"more": "Играть",
"more_url": "https://vk.me/soviet_clicker",
"head": [{
"text": "Имя",
}, {
"text": "Баланс",
"align": "center"
},
{ "text": "Уровень",
"align": "center"
},
{
"text": "Пригласил",
"align": "right"
}],
"body": [
[{
"text": user['top'] + ' ' + user["name"],
"align": "left"
}, {
"text": str(user["score"]) + ' SG₽',
"align": "center"
},
{
"text": str(user["level"]),
"align": "center"
},
{
"text": str(user["friends"]),
"align": "right"
}
] for user in users
]
}
return f"return {widget};"
async def update():
code = await generate_code()
await bot.api.app_widgets.update(code=code, type="table")