Logs now show the user's name, not just the id
This commit is contained in:
parent
e0345df54e
commit
ecff3ccf38
15
bot/bot.py
15
bot/bot.py
|
@ -31,8 +31,9 @@ def home():
|
|||
@bot.message_handler(commands=['login'])
|
||||
def login(message):
|
||||
id = message.from_user.id
|
||||
name = message.from_user.first_name
|
||||
passwd = message.text.replace('/login ', '')
|
||||
f = str(func.u_auth(id,passwd))
|
||||
f = str(func.u_auth(name,id,passwd))
|
||||
if f == str(msg.get('sucauth')) or f == str(msg.get('alauth')):
|
||||
bot.reply_to(message,f,reply_markup=home())
|
||||
else:
|
||||
|
@ -62,11 +63,12 @@ def folder_menu():
|
|||
@bot.message_handler(commands=['add'])
|
||||
def add(message):
|
||||
id = message.from_user.id
|
||||
name = message.from_user.first_name
|
||||
txt = message.text.split(' ', 2)
|
||||
if len(txt) == 3:
|
||||
key = txt[1]
|
||||
path = txt[2]
|
||||
f = str(func.add_dir(id,key,path))
|
||||
f = str(func.add_dir(name,id,key,path))
|
||||
else:
|
||||
f = str(msg.get('aerr'))
|
||||
bot.reply_to(message,f,reply_markup=home())
|
||||
|
@ -75,8 +77,9 @@ def add(message):
|
|||
@bot.message_handler(commands=['del'])
|
||||
def rm(message):
|
||||
id = message.from_user.id
|
||||
name = message.from_user.first_name
|
||||
folder = message.text.replace('/del ', '')
|
||||
f = func.del_dir(id,folder)
|
||||
f = func.del_dir(name,id,folder)
|
||||
bot.reply_to(message,str(f),reply_markup=home())
|
||||
|
||||
# Magnet
|
||||
|
@ -113,6 +116,7 @@ def file(message):
|
|||
@bot.message_handler(content_types=['document'])
|
||||
def download(message):
|
||||
id = message.from_user.id
|
||||
name = message.from_user.first_name
|
||||
if func.auth_check(id):
|
||||
global type, dir, folder_list
|
||||
if dir != None and type == 'file':
|
||||
|
@ -123,7 +127,7 @@ def download(message):
|
|||
file_name = os.path.join(PATH, message.document.file_name)
|
||||
with open(file_name, 'wb') as dl:
|
||||
dl.write(file)
|
||||
f = str(func.file(id,file_name,dir))
|
||||
f = str(func.file(name,id,file_name,dir))
|
||||
dir, type, folder_list = None,None,[]
|
||||
bot.reply_to(message,f)
|
||||
else:
|
||||
|
@ -146,13 +150,14 @@ def dirchoose(message):
|
|||
def unknown(message):
|
||||
global type, dir, folder_list
|
||||
id = message.from_user.id
|
||||
name = message.from_user.first_name
|
||||
if func.auth_check(id):
|
||||
txt = message.text
|
||||
if txt in folder_list:
|
||||
dirchoose(message)
|
||||
return None
|
||||
if dir != None and type == 'magnet':
|
||||
f = str(func.magnet(id,txt,dir))
|
||||
f = str(func.magnet(name,id,txt,dir))
|
||||
dir, type, folder_list = None,None,[]
|
||||
bot.reply_to(message,f)
|
||||
bot.reply_to(message,str(msg.get('type')),reply_markup=home())
|
||||
|
|
20
bot/func.py
20
bot/func.py
|
@ -19,7 +19,7 @@ def qbt():
|
|||
os.system(f"bash -c '{command}'")
|
||||
output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
|
||||
def u_auth(id,passwd):
|
||||
def u_auth(name,id,passwd):
|
||||
list = []
|
||||
if db.check('obj',AUTH_FILE):
|
||||
list = db.read(AUTH_FILE)
|
||||
|
@ -29,7 +29,7 @@ def u_auth(id,passwd):
|
|||
if passwd == os.environ['PASS']:
|
||||
list.append(id)
|
||||
db.write(list,AUTH_FILE)
|
||||
log.auth(id)
|
||||
log.auth(name,id)
|
||||
return msg.get('sucauth')
|
||||
else:
|
||||
return msg.get('wrauth')
|
||||
|
@ -42,7 +42,7 @@ def auth_check(id):
|
|||
if id in list:
|
||||
return True
|
||||
|
||||
def add_dir(id,dir,path):
|
||||
def add_dir(name,id,dir,path):
|
||||
if auth_check(id):
|
||||
if os.path.exists(path) == False:
|
||||
return str(msg.get('pne')).format(path)
|
||||
|
@ -52,12 +52,12 @@ def add_dir(id,dir,path):
|
|||
dict = {}
|
||||
dict.setdefault(dir,path)
|
||||
db.write(dict,DIR_FILE)
|
||||
log.add(id,dir,path)
|
||||
log.add(name,id,dir,path)
|
||||
return str(msg.get('fsa')).format(dir)
|
||||
else:
|
||||
return msg.get('adeny')
|
||||
|
||||
def del_dir(id,dir):
|
||||
def del_dir(name,id,dir):
|
||||
if auth_check(id):
|
||||
if db.check('obj',DIR_FILE):
|
||||
dict = db.read(DIR_FILE)
|
||||
|
@ -66,32 +66,32 @@ def del_dir(id,dir):
|
|||
if dir in dict:
|
||||
del dict[dir]
|
||||
db.write(dict,DIR_FILE)
|
||||
log.rm(id,dir)
|
||||
log.rm(name,id,dir)
|
||||
return str(msg.get('frm')).format(dir)
|
||||
else:
|
||||
return str(msg.get('fne')).format(dir)
|
||||
else:
|
||||
return msg.get('adeny')
|
||||
|
||||
def magnet(id,link,dir):
|
||||
def magnet(name,id,link,dir):
|
||||
if auth_check(id):
|
||||
dict = db.read(DIR_FILE)
|
||||
path = dict[dir]
|
||||
command = f'''qbt torrent add url "{link}" -f "{path}"'''
|
||||
os.system(f"bash -c '{command}'")
|
||||
log.addmagnet(id,link)
|
||||
log.addmagnet(name,id,link)
|
||||
return msg.get('add')
|
||||
else:
|
||||
return msg.get('adeny')
|
||||
|
||||
def file(id,file,dir):
|
||||
def file(name,id,file,dir):
|
||||
if auth_check(id):
|
||||
dict = db.read(DIR_FILE)
|
||||
path = dict[dir]
|
||||
command = f'''qbt torrent add file "{file}" -f {path}'''
|
||||
os.system(f"bash -c '{command}'")
|
||||
os.remove(file)
|
||||
log.addfile(id,file)
|
||||
log.addfile(name,id,file)
|
||||
return msg.get('add')
|
||||
else:
|
||||
return msg.get('adeny')
|
||||
|
|
20
bot/lang.py
20
bot/lang.py
|
@ -28,11 +28,11 @@ RU = {
|
|||
# Logs
|
||||
'l_create': "Log Файл '{}' создан",
|
||||
'l_start': 'Запуск бота...',
|
||||
'l_auth': "Пользователь '{}' успешно авторизировался",
|
||||
'l_add': "Пользователь '{}' добавил папку '{}' по пути '{}'",
|
||||
'l_rm': "Пользователь '{}' удалил папку '{}'",
|
||||
'l_file': "Пользователь '{}' добавил в очередь файл '{}'",
|
||||
'l_magnet': "Пользователь '{}' добавил в очередь ссылку '{}'",
|
||||
'l_auth': "Пользователь '{} ({})' успешно авторизировался",
|
||||
'l_add': "Пользователь '{} ({})' добавил папку '{}' по пути '{}'",
|
||||
'l_rm': "Пользователь '{} ({})' удалил папку '{}'",
|
||||
'l_file': "Пользователь '{} ({})' добавил в очередь файл '{}'",
|
||||
'l_magnet': "Пользователь '{} ({})' добавил в очередь ссылку '{}'",
|
||||
'l_errqbt': "Ошибка подключения к qBitTorrent",
|
||||
'l_errtele': "Ошибка подключения к Telegram API, проверьте ваш токен",
|
||||
}
|
||||
|
@ -60,11 +60,11 @@ ENG = {
|
|||
# Logs
|
||||
'l_create': "Log File '{}' created",
|
||||
'l_start': 'Start bot polling...',
|
||||
'l_auth': "User '{}' successfully authorized",
|
||||
'l_add': "User '{}' added a folder '{}' with the path '{}'",
|
||||
'l_rm': "User '{}' deleted '{}' folder",
|
||||
'l_file': "User '{}' added file '{}' to the queue",
|
||||
'l_magnet': "User '{}' added the link '{}' to the queue",
|
||||
'l_auth': "User '{} ({})' successfully authorized",
|
||||
'l_add': "User '{} ({})' added a folder '{}' with the path '{}'",
|
||||
'l_rm': "User '{} ({})' deleted '{}' folder",
|
||||
'l_file': "User '{} ({})' added file '{}' to the queue",
|
||||
'l_magnet': "User '{} ({})' added the link '{}' to the queue",
|
||||
'l_errqbt': "Error connecting to qBitTorrent",
|
||||
'l_errtele': "Error connecting to Telegram API, check your token"
|
||||
}
|
||||
|
|
20
bot/log.py
20
bot/log.py
|
@ -29,28 +29,28 @@ def start():
|
|||
file(log2)
|
||||
print(f'{log1}\n{log2}')
|
||||
|
||||
def auth(id):
|
||||
log = DEFAULT + str(msg.get('l_auth').format(id))
|
||||
def auth(name,id):
|
||||
log = DEFAULT + str(msg.get('l_auth').format(name,id))
|
||||
file(log)
|
||||
print(log)
|
||||
|
||||
def add(id,folder,path):
|
||||
log = DEFAULT + str(msg.get('l_add').format(id,folder,path))
|
||||
def add(name,id,folder,path):
|
||||
log = DEFAULT + str(msg.get('l_add').format(name,id,folder,path))
|
||||
file(log)
|
||||
print(log)
|
||||
|
||||
def rm(id,folder):
|
||||
log = DEFAULT + str(msg.get('l_rm').format(id,folder))
|
||||
def rm(name,id,folder):
|
||||
log = DEFAULT + str(msg.get('l_rm').format(name,id,folder))
|
||||
file(log)
|
||||
print(log)
|
||||
|
||||
def addfile(id,filename):
|
||||
log = DEFAULT + str(msg.get('l_file').format(id,filename[9:]))
|
||||
def addfile(name,id,filename):
|
||||
log = DEFAULT + str(msg.get('l_file').format(name,id,filename[9:]))
|
||||
file(log)
|
||||
print(log)
|
||||
|
||||
def addmagnet(id,link):
|
||||
log = DEFAULT + str(msg.get('l_magnet').format(id,link))
|
||||
def addmagnet(name,id,link):
|
||||
log = DEFAULT + str(msg.get('l_magnet').format(name,id,link))
|
||||
file(log)
|
||||
print(log)
|
||||
|
||||
|
|
Reference in New Issue