Skip to content

Commit

Permalink
enhance logging, remove prints
Browse files Browse the repository at this point in the history
  • Loading branch information
aahnik committed Jun 11, 2021
1 parent 18d6f3b commit c217b79
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
13 changes: 8 additions & 5 deletions tgcf/bot/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""helper functions for the bot."""
import logging
from typing import List

from telethon import events
Expand Down Expand Up @@ -32,9 +33,8 @@ def get_args(text: str) -> str:
return ""

prefix, args = splitted
print(prefix)
args = args.strip()
print(args)
logging.info(f"Got command {prefix} with args {args}")
return args


Expand All @@ -55,10 +55,13 @@ def display_forwards(forwards: List[Forward]) -> str:
def remove_source(source, forwards: List[Forward]) -> List[Forward]:
"""Remove a source from forwards."""
for i, forward in enumerate(forwards):
print(forward)
print(type(forward.source))
print(type(source))
if forward.source == source:
del forwards[i]
return forwards
raise ValueError("The source does not exist")


def get_command_prefix():
if config.is_bot is None:
raise ValueError("config.is_bot is not set!")
return "/" if config.is_bot else "."
2 changes: 1 addition & 1 deletion tgcf/past.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def forward_job() -> None:
logging.info(f"slept for {CONFIG.past.delay} seconds")

except FloodWaitError as fwe:
print(f"Sleeping for {fwe}")
logging.info(f"Sleeping for {fwe}")
await asyncio.sleep(delay=fwe.seconds)
except Exception as err:
logging.exception(err)
6 changes: 3 additions & 3 deletions tgcf/plugins/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TgcfFilter(TgcfPlugin):
id_ = "filter"

def __init__(self, data: Dict[str, Any]) -> None:
print("tgcf filter data loaded")
self.filters = Filters(**data)
self.case_correct()
logging.info(self.filters)
Expand All @@ -47,8 +46,11 @@ def case_correct(self) -> None:
def modify(self, tm: TgcfMessage) -> TgcfMessage:

if self.users_safe(tm):
logging.info("Message passed users filter")
if self.files_safe(tm):
logging.info("Message passed files filter")
if self.text_safe(tm):
logging.info("Message passed text filter")
return tm

def text_safe(self, tm: TgcfMessage) -> bool:
Expand Down Expand Up @@ -76,7 +78,6 @@ def text_safe(self, tm: TgcfMessage) -> bool:
def users_safe(self, tm: TgcfMessage) -> bool:
flist = self.filters.users
sender = str(tm.sender_id)
logging.info(f"M message from sender id {sender}")
if sender in flist.blacklist:
return False
if not flist.whitelist:
Expand All @@ -87,7 +88,6 @@ def users_safe(self, tm: TgcfMessage) -> bool:
def files_safe(self, tm: TgcfMessage) -> bool:
flist = self.filters.files
fl_type = tm.file_type
print(fl_type)
if fl_type in flist.blacklist:
return False
if not flist.whitelist:
Expand Down
11 changes: 6 additions & 5 deletions tgcf/plugins/mark.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
import shutil
from typing import Any, Dict
Expand All @@ -18,21 +19,21 @@ class MarkConfig(BaseModel):

def download_image(url: str, filename: str = "image.png") -> bool:
if filename in os.listdir():
print("Image exists")
logging.info("Image for watermarking already exists.")
return True
try:
print("Downloading image ... ")
logging.info(f"Downloading image {url}")
response = requests.get(url, stream=True)
if response.status_code == 200:
print("Got file response")
logging.info("Got Response 200")
with open(filename, "wb") as file:
response.raw.decode_content = True
shutil.copyfileobj(response.raw, file)
except Exception as err:
print(err)
logging.error(err)
return False
else:
print("File created image")
logging.info("File created image")
return True


Expand Down

0 comments on commit c217b79

Please sign in to comment.