Add log system

This commit is contained in:
trueold89 2023-11-02 23:12:36 +03:00
parent 2d39ff4a2d
commit d951b22056
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
4 changed files with 82 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3
# -- coding: utf-8 --
import func, telebot, os
import func, telebot, os, log
from db import PATH
from lang import LANG as msg
@ -159,5 +159,6 @@ def unknown(message):
else:
bot.reply_to(message,str(msg.get('adeny')))
func.qbt()
# func.qbt()
log.start()
bot.polling()

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3
# -- coding: utf-8 --
import db, os
import db, os, log
from db import *
from lang import LANG as msg
@ -27,6 +27,7 @@ def u_auth(id,passwd):
if passwd == os.environ['PASS']:
list.append(id)
db.write(list,AUTH_FILE)
log.auth(id)
return msg.get('sucauth')
else:
return msg.get('wrauth')
@ -49,6 +50,7 @@ def add_dir(id,dir,path):
dict = {}
dict.setdefault(dir,path)
db.write(dict,DIR_FILE)
log.add(id,dir,path)
return str(msg.get('fsa')).format(dir)
else:
return msg.get('adeny')
@ -62,6 +64,7 @@ def del_dir(id,dir):
if dir in dict:
del dict[dir]
db.write(dict,DIR_FILE)
log.rm(id,dir)
return str(msg.get('frm')).format(dir)
else:
return str(msg.get('fne')).format(dir)
@ -74,6 +77,7 @@ def magnet(id,link,dir):
path = dict[dir]
command = f'''qbt torrent add url "{link}" -f "{path}"'''
os.system(f"bash -c '{command}'")
log.addmagnet(id,link)
return msg.get('add')
else:
return msg.get('adeny')
@ -85,6 +89,7 @@ def file(id,file,dir):
command = f'''qbt torrent add file "{file}" -f {path}'''
os.system(f"bash -c '{command}'")
os.remove(file)
log.addfile(id,file)
return msg.get('add')
else:
return msg.get('adeny')

View File

@ -24,7 +24,15 @@ RU = {
'ntorr': 'Неверное расширение файла',
'sendm': 'Отправте Magnet-ссылку',
'sendf': 'Отправте .torrent файл',
'adeny': 'Этот бот запривачен, гнида, блять'
'adeny': 'Этот бот запривачен, гнида, блять',
# Logs
'l_create': "Log Файл '{}' создан",
'l_start': 'Бот готов к работе',
'l_auth': "Пользователь '{}' успешно авторизировался",
'l_add': "Пользователь '{}' добавил папку '{}' по пути '{}'",
'l_rm': "Пользователь '{}' удалил папку '{}'",
'l_file': "Пользователь '{}' добавил в очередь файл '{}'",
'l_magnet': "Пользователь '{}' добавил в очередь ссылку '{}'"
}
# English
@ -46,7 +54,15 @@ ENG = {
'ntorr': 'Incorrect file extension',
'sendm': 'Send Magnet link',
'sendf': 'Send .torrent file',
'adeny': "You do not have access, first authorize '/login <password>'"
'adeny': "You do not have access, first authorize '/login <password>'",
# Logs
'l_create': "Log File '{}' created",
'l_start': 'Bot is up and running',
'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"
}
for i in langs:

55
bot/log.py Normal file
View File

@ -0,0 +1,55 @@
#!/usr/bin/python3
# -- coding: utf-8 --
import os, uuid
from datetime import datetime
from lang import LANG as msg
from db import PATH
def dt():
date = datetime.now().date()
time = datetime.now().time()
str = f'{date} | {time.strftime("%H:%M:%S")}'
return str
DEFAULT = f'{dt()} LOG: '
ID = str(uuid.uuid1())[0:7]
FILE = f'{ID}.txt'
def file(log):
if os.path.exists(f'{PATH}logs') == False:
os.mkdir(f'{PATH}logs')
with open(f'{PATH}logs/{FILE}','a') as logfile:
logfile.write(f'{log}\n')
logfile.close()
def start():
log1 = DEFAULT + str(msg.get('l_create').format(FILE))
log2 = DEFAULT + str(msg.get('l_start'))
file(log2)
print(f'{log1}\n{log2}')
def auth(id):
log = DEFAULT + str(msg.get('l_auth').format(id))
file(log)
print(log)
def add(id,folder,path):
log = DEFAULT + str(msg.get('l_add').format(id,folder,path))
file(log)
print(log)
def rm(id,folder):
log = DEFAULT + str(msg.get('l_rm').format(id,folder))
file(log)
print(log)
def addfile(id,filename):
log = DEFAULT + str(msg.get('l_file').format(id,filename[9:]))
file(log)
print(log)
def addmagnet(id,link):
log = DEFAULT + str(msg.get('l_magnet').format(id,link))
file(log)
print(log)