This repository has been archived by the owner on Feb 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
chat_members.py
executable file
·55 lines (36 loc) · 2.07 KB
/
chat_members.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
import random
from handler.base_plugin import CommandPlugin
class MembersPlugin(CommandPlugin):
__slots__ = ("show_offline", "emojis")
def __init__(self, *commands, prefixes=None, strict=False, show_offline=False):
"""Answers with users in conference. Doesn't show users offline if `show_offline` is False."""
if not commands:
commands = ("члены", "кто тут")
super().__init__(*commands, prefixes=prefixes, strict=strict)
self.show_offline = show_offline
self.emojis = ['😏', '😄', '😠', '😆', '🤐', '😝', '🤔', '😎', '😐', '🙁',
'😨', '🤔', '😠', '😝', '😘', '😗', '😙', '😙', '😟']
self.set_description()
def set_description(self):
example = self.command_example()
self.description = [f"Состав беседы",
f"Вывод списка пользователей в конференции.",
f"{example} - показать список."]
async def process_message(self, msg):
if msg.is_multichat:
all_users = await msg.api.messages.getChatUsers(chat_id=msg.chat_id, fields='name,online')
users = ""
for user in all_users:
random.seed(user['id'])
emoji = random.choice(self.emojis) + " "
if self.show_offline:
users += f"{emoji} [id{user['id']}|{user['first_name']} {user['last_name']}] " \
f"{' - онлайн' if user['online'] else ''}\n"
elif user.get('online'):
users += f"{emoji} [id{user['id']}|{user['first_name']} {user['last_name']}]\n"
if self.show_offline:
await msg.answer(f'👽 Состав беседы:\n' + users)
else:
await msg.answer(f'👽 Сейчас в беседе:\n' + users)
else:
await msg.answer("Эту команду можно использовать только в беседе.")