Fix authorization on bot restart

Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
lzzy12 2019-10-10 21:44:06 +05:30
parent ce16f77b6d
commit c683c7732f
2 changed files with 8 additions and 3 deletions

View File

@ -45,7 +45,7 @@ with open('authorized_chats.txt', 'r+') as f:
lines = f.readlines()
for line in lines:
LOGGER.info(line.split())
AUTHORIZED_CHATS.append(line.split()[0])
AUTHORIZED_CHATS.append(int(line.split()[0]))
try:
BOT_TOKEN = getConfig('BOT_TOKEN')
parent_id = getConfig('GDRIVE_FOLDER_ID')

View File

@ -10,20 +10,25 @@ from telegram import Update
@run_async
def authorize(update: Update, context):
reply_message = update.message.reply_to_message
msg = ''
with open('authorized_chats.txt', 'a') as file:
if reply_message is None:
chat_id = update.effective_chat.id
if chat_id not in AUTHORIZED_CHATS:
file.write(f'{chat_id}\n')
AUTHORIZED_CHATS.append(chat_id)
sendMessage('Chat authorized', context, update)
msg = 'Chat authorized'
else:
sendMessage('Already authorized chat', context, update)
msg = 'Already authorized chat'
else:
user_id = reply_message.from_user.id
if user_id not in AUTHORIZED_CHATS:
file.write(f'{user_id}\n')
AUTHORIZED_CHATS.append(user_id)
msg = 'Person Authorized to use the bot!'
else:
msg = 'Person already authorized'
sendMessage(msg, context, update)
authorize_handler = CommandHandler(command='authorize', callback=authorize,