-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (35 loc) · 1.54 KB
/
Copy pathmain.py
File metadata and controls
53 lines (35 loc) · 1.54 KB
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
from user_interaction import UserInteraction
from decouple import config
from telebot import TeleBot
API_KEY = config("API_KEY")
bot = TeleBot(API_KEY)
def is_admin(message):
chat_id = message.chat.id
user_id = message.from_user.id
member = bot.get_chat_member(chat_id, user_id)
# member.status может быть: "creator", "administrator", "member", "restricted", "left", "kicked"
if member.status in ["creator", "administrator"]:
return True
return False
@bot.message_handler(commands=['alertme'])
def link_user(message):
user_id = message.from_user.id
result_msg = UserInteraction.add_user(user_id)
bot.reply_to(message, f"@{message.from_user.username} {result_msg}")
@bot.message_handler(commands=['panic'])
def alert_users(message):
chat_id = message.chat.id
print(message.from_user.username + "активировал /panic")
if is_admin(message):
args = message.text.split(maxsplit=1)
panic_reason = args[1] if len(args) > 1 else ''
panic = UserInteraction.get_alert(panic_reason) if panic_reason else UserInteraction.get_alert()
bot.send_message(chat_id, panic, parse_mode="Markdown")
else:
bot.send_message(chat_id, "У вас недостаточно прав")
@bot.message_handler(commands=['unalert', 'unalertme'])
def unlink_user(message):
user_id = message.from_user.id
result_str = UserInteraction.remove_user(user_id)
bot.send_message(message.chat.id, result_str)
bot.polling(none_stop=True)