diff --git a/.gitignore b/.gitignore
index 357a271..a3e25fd 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
.venv
.DS_Store
__pycache__
-log
+log.txt
session
temp
dev.*
diff --git a/README.md b/README.md
index 1bf16a1..389057b 100755
--- a/README.md
+++ b/README.md
@@ -57,14 +57,6 @@ A Telegram Bot to transfer files to OneDrive.
/clear
-
- /logs
-
-
-
- /logs $range
-
-
/autoDelete
@@ -176,8 +168,7 @@ If you don't follow these steps, the bot may not works.
- `/drive logout $index` to logout specified OneDrive account.
- `/links $message_link $range` to transfer sequential restricted content.
- `/url $file_url` to upload the file through url.
-- `/logs` to show all logs.
-- `/logs $range` to show the most recent logs for the specified page number.
+- `/logs` to send log file.
- `/logs clear` to clear logs.
- `/dir` to show current OneDrive directory.
- `/dir $remote_path` to set OneDrive directory.
@@ -191,7 +182,6 @@ The bot support files with extension `.t2o` as scripts. You can use them to auto
### Example
- `/links https://t.me/c/xxxxxxx/100 2` will transfer `https://t.me/c/xxxxxxx/100` and `https://t.me/c/xxxxxxx/101`.
- `/url https://example.com/file.txt` will upload `file.txt`. The headers of the file response must includes `Content-Length`.
-- `/logs 2` will show 2 pages of the most recent logs. Each page contains 50 lines of logs.
- In a file named `example.t2o`, write these lines for example:
```
[link]
diff --git a/modules/handlers/logs.py b/modules/handlers/logs.py
index e0487c8..9100458 100644
--- a/modules/handlers/logs.py
+++ b/modules/handlers/logs.py
@@ -16,61 +16,6 @@
from modules.res import logs_res
-class Tail_File_Page:
- def __init__(self, path, lines_per_page):
- self.pos = 0
- self.lines_per_page = lines_per_page
- self.file = open(path, "rb")
-
- def __enter__(self):
- return self
-
- def __exit__(self, exc_type, exc_val, exc_tb):
- self.file.close()
-
- def read_all(self):
- while True:
- string = ""
- for _ in range(self.lines_per_page):
- line = self.file.readline().decode()
- if line == "":
- break
- string += line
- if string == "":
- break
- yield string
-
- def read_pages(self, pages):
- self._seek_lines(pages * self.lines_per_page)
- while pages:
- pages -= 1
- string = self._read_lines(self.lines_per_page)
- if string == "":
- break
- yield string
-
- def _read_lines(self, lines_num):
- string = ""
- while lines_num:
- lines_num -= 1
- line = self.file.readline().decode()
- if line == "":
- break
- string += line
- return string
-
- def _seek_lines(self, lines_num):
- while lines_num:
- try:
- self.pos -= 1
- self.file.seek(self.pos, os.SEEK_END)
- if self.file.read(1) == b"\n":
- lines_num -= 1
- except:
- self.file.seek(0, os.SEEK_SET)
- break
-
-
@tg_bot.on(events.NewMessage(pattern="/logs", incoming=True, from_users=tg_user_name))
@check_in_group
@check_tg_login
@@ -83,12 +28,7 @@ async def logs_handler(event):
# /logs
if len(cmd) == 1:
- with Tail_File_Page(log_path, LOGS_LINES_PER_PAGE) as file:
- await event.respond("Outputting logs...")
- for logs in file.read_all():
- await event.respond(logs)
- await asyncio.sleep(1)
- await event.respond("Finished.")
+ await tg_bot.send_file(event.chat_id, log_path)
elif len(cmd) == 2:
sub_cmd = cmd[1]
@@ -100,20 +40,6 @@ async def logs_handler(event):
else:
await event.respond("Logs not found.")
- # /logs $range
- else:
- try:
- pages = int(sub_cmd)
- except ValueError:
- await event.reply("Logs page range should be integer.")
- raise events.StopPropagation
-
- with Tail_File_Page(log_path, LOGS_LINES_PER_PAGE) as file:
- await event.respond("Outputting logs...")
- for logs in file.read_pages(pages):
- await event.respond(logs)
- await asyncio.sleep(1)
- await event.respond("Finished.")
else:
await event.respond(logs_res)
raise events.StopPropagation
diff --git a/modules/log.py b/modules/log.py
index 337eb94..a3c2d8b 100644
--- a/modules/log.py
+++ b/modules/log.py
@@ -9,7 +9,7 @@
from traceback import print_exc
from io import StringIO
-log_path = "log"
+log_path = "log.txt"
def logger(message):
diff --git a/modules/res.py b/modules/res.py
index ecdee7c..c2c37dc 100644
--- a/modules/res.py
+++ b/modules/res.py
@@ -18,7 +18,7 @@
- /auth to authorize for Telegram and OneDrive.
- /clear to clear all history except status message.
- /autoDelete to toggle whether bot should auto delete message.
-- /logs to show all logs.
+- /logs to send log file.
- /drive to list all OneDrive accounts.
- /dir to show current OneDrive directory.
@@ -26,8 +26,6 @@
To transfer sequential restricted content.
```/url $file_url```
To upload file through url.
-```/logs $range```
-To show the most recent logs for the specified page number.
```/logs clear```
To clear logs.
```/drive add```
@@ -97,8 +95,6 @@
Usage:
```/logs```
-```/logs $range```
-
```/logs clear```
"""