def torrent_finished(): for i in qbittorrent_control.get_torrent_info(): if i.progress == 1 and \ db_management.read_completed_torrents(i.hash) is None \ and get_configs().notify: for j in get_configs().id: try: bot.chat(j).send(f"torrent {i.name} has " f"finished downloading!") except botogram.api.ChatUnavailableError: pass db_management.write_completed_torrents(i.hash)
def wrapper(*args, **kwargs): qbt_client = qbittorrentapi.Client( host=f'http://{get_configs().qbittorrent.ip}:' f'{get_configs().qbittorrent.port}', username=get_configs().qbittorrent.user, password=get_configs().qbittorrent.password) try: qbt_client.auth_log_in() except qbittorrentapi.LoginFailed as e: print(e) resp = func(qbt_client, *args, **kwargs) qbt_client.auth_log_out() return resp
def start_command(message, chat, shared) -> None: """Start the bot.""" if chat.id in get_configs().id: send_menu(message, chat, shared) else: btn = botogram.Buttons() btn[0].url("GitHub", "https://github.com/ch3p4ll3/QBittorrentBot/") chat.send("You are not authorized to use this bot.", attach=btn)
def stats_command(chat) -> None: if chat.id in get_configs().id: txt = f"""*============SYSTEM============* *CPU Usage: *{psutil.cpu_percent(interval=None)}% *CPU Temp: *{psutil.sensors_temperatures()['cpu_thermal'][0].current}°C *Free Memory: *{convert_size(psutil.virtual_memory().available)} \ of {convert_size(psutil.virtual_memory().total)} \ ({psutil.virtual_memory().percent}%) *Disks usage: *{convert_size(psutil.disk_usage('/mnt/usb').used)} \ of {convert_size(psutil.disk_usage('/mnt/usb').total)} \ ({psutil.disk_usage('/mnt/usb').percent}%)""" chat.send(txt, syntax="markdown") else: btn = botogram.Buttons() btn[0].url("GitHub", "https://github.com/ch3p4ll3/QBittorrentBot/") chat.send("You are not authorized to use this bot.", attach=btn)
#!/usr/local/bin/python3.7 import datetime import os import tempfile from math import log, floor import botogram import psutil import qbittorrent_control from json_validation import get_configs bot = botogram.create(get_configs().token) bot.about = "with this bot you can control QBittorrent from telegram" bot.owner = "@ch3p4ll3" @bot.prepare_memory def prepare_memory(shared) -> None: shared['status'] = "None" def convert_size(size_bytes) -> str: if size_bytes == 0: return "0B" size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") i = int(floor(log(size_bytes, 1024))) p = pow(1024, i) s = round(size_bytes / p, 2) return "%s %s" % (s, size_name[i])