-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_bot.py
46 lines (35 loc) · 1019 Bytes
/
run_bot.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
import random
import json
from telegram.ext import CommandHandler
from telegram import ParseMode
from loguru import logger
from config import bot_updater, data
from helpers import restricted, get_users_group
@restricted
def get_random_participant(bot, update):
'''
Get a random participant from the user.json file.
'''
chat_title = update.effective_chat.title
with open(f'{chat_title}.users.json') as user_file:
participants_list = json.load(user_file)
participant = random.choice(participants_list)
update.message.reply_text(
f'[{participant["full_name"]}](tg://user?id={participant["id"]})',
parse_mode=ParseMode.MARKDOWN
)
def bot():
'''
Initialize the bot.
'''
get_users_group(data['groups']['names'])
bot_updater.dispatcher.add_handler(
CommandHandler(
'sorteio',
get_random_participant
)
)
bot_updater.start_polling()
bot_updater.idle()
if __name__ == "__main__":
bot()