Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
aahnik committed Jun 11, 2021
1 parent 942d8e1 commit 7e51960
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 24 deletions.
15 changes: 6 additions & 9 deletions tgcf/bot/live_bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""A bot to controll settings for tgcf live mode."""

import logging

import yaml
from telethon import events

Expand Down Expand Up @@ -36,9 +38,7 @@ async def forward_command_handler(event):
raise ValueError(f"{notes}\n{display_forwards(config.CONFIG.forwards)}")

parsed_args = yaml.safe_load(args)
print(parsed_args)
forward = config.Forward(**parsed_args)
print(forward)
try:
remove_source(forward.source, config.CONFIG.forwards)
except:
Expand All @@ -49,7 +49,7 @@ async def forward_command_handler(event):
await event.respond("Success")
config.write_config(config.CONFIG)
except ValueError as err:
print(err)
logging.error(err)
await event.respond(str(err))

finally:
Expand All @@ -74,17 +74,14 @@ async def remove_command_handler(event):
raise ValueError(f"{notes}\n{display_forwards(config.CONFIG.forwards)}")

parsed_args = yaml.safe_load(args)
print(parsed_args)
source_to_remove = parsed_args.get("source")
print(source_to_remove)
config.CONFIG.forwards = remove_source(source_to_remove, config.CONFIG.forwards)
print(config.CONFIG.forwards)
config.from_to = config.load_from_to(event.client, config.CONFIG.forwards)

await event.respond("Success")
config.write_config(config.CONFIG)
except ValueError as err:
print(err)
logging.error(err)
await event.respond(str(err))

finally:
Expand Down Expand Up @@ -117,7 +114,7 @@ async def style_command_handler(event):

config.write_config(config.CONFIG)
except ValueError as err:
print(err)
logging.error(err)
await event.respond(str(err))

finally:
Expand All @@ -135,7 +132,7 @@ async def help_command_handler(event):


def get_events():
_ = get_command_prefix
_ = get_command_prefix()

command_events = {
"start": (start_command_handler, events.NewMessage(pattern=f"{_}start")),
Expand Down
7 changes: 2 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,9 +55,6 @@ 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
Expand Down
3 changes: 2 additions & 1 deletion tgcf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

import typer
from dotenv import load_dotenv
from pyfiglet import Figlet
from rich import traceback
from rich.logging import RichHandler
from pyfiglet import Figlet

from tgcf import __version__

load_dotenv(".env")
Expand Down
6 changes: 3 additions & 3 deletions tgcf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ def read_config() -> Config:
else:
config = Config()
except Exception as err:
print(err)
logging.exception(err)
sys.exit(1)
else:
logging.info(config.dict())
logging.info(config)
return config


Expand Down Expand Up @@ -181,5 +181,5 @@ async def _(peer):


from_to = {}
is_bot: bool
is_bot: Optional[bool] = None
logging.info("config.py got executed")
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)
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 7e51960

Please sign in to comment.