diff --git a/.gitignore b/.gitignore index 4625173..19f81d2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ music_cache nuvola.py debug.log nuvola.txt -test.py \ No newline at end of file +test.py +package-lock.json +package.json +node_modules \ No newline at end of file diff --git a/index.py b/index.py index 4ad7681..30cfeb7 100644 --- a/index.py +++ b/index.py @@ -19,6 +19,7 @@ import urllib.parse import logging import deepl import spotipy +import pyshorteners from spotipy.oauth2 import SpotifyClientCredentials from youtube_search import YoutubeSearch from dotenv import load_dotenv @@ -270,5 +271,58 @@ def epicgames_step(message): send_img = bot.send_photo(message.chat.id, image_futuregames2) sent_msg = bot.send_message(message.chat.id, "๐ŸŽฎ Il gioco futuro รจ " + future_games2 + "\n\n" + result_description2) +#Command /shutdown +@bot.message_handler(commands=['shutdown']) +def shutdown(message): + text = message.text + sent_msg = bot.send_message(message.chat.id, "Sei sicuro di voler spegnere il pc?") + bot.register_next_step_handler(sent_msg, shutdown_step) -bot.polling() +def shutdown_step(message): + id = message.from_user.id + text = message.text + id_owner = os.getenv('USER_ID') + if id == id_owner: + + if text == "si" or text == "Si" or text == "y" or text == "Y" or text == "Yes" or text == "yes": + bot.send_message(message.chat.id, "Il computer รจ stato spento con successo!") + logging.info("Triggered Shutdown") + url = os.getenv("PASSWORD") + requests.get(url) + else: + bot.send_message(message.chat.id, "โš ๏ธ Hai annullato l'operazione!") + else: + bot.send_message(message.chat.id, "Eh volevi!") + +#Command /shortlink + +@bot.message_handler(commands=['shortlink']) +def shortlink(message): + text = message.text + sent_msg = bot.send_message(message.chat.id, "Inserisci il link:") + bot.register_next_step_handler(sent_msg, shortlink_step) + +def shortlink_step(message): + text = message.text + type_tiny = pyshorteners.Shortener() + short_url = type_tiny.tinyurl.short(text) + bot.send_message(message.chat.id, "Ecco a te lo shortlink: " + short_url) + +#Command /uptime +@bot.message_handler(commands=['uptime']) +def uptime(message): + logging.info("Triggered UPTIME") + sent_msg = bot.send_message(message.chat.id, "Manda il link del sito che vuoi controllare.") + bot.register_next_step_handler(sent_msg, uptime_step) + +def uptime_step(message): + text = message.text + url= text + status_code = urllib.request.urlopen(url).getcode() + website_is_up = status_code == 200 + if website_is_up == True: + bot.send_message(message.chat.id, "Il sito รจ online!") + else: + bot.send_message(message.chat.id, "Il sito non รจ online!") + +bot.polling() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 35f39e4..3a84882 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,4 +30,6 @@ youtube_search == 2.1.0 yt_dlp == 2022.5.18 -pytelegrambotapi == 4.5.1 \ No newline at end of file +pytelegrambotapi == 4.5.1 + +pyshorteners == 1.0.1 \ No newline at end of file