Browse Source

Integrated Telegram bot

itec 4 years ago
parent
commit
d2376cff78
3 changed files with 43 additions and 54 deletions
  1. 8 0
      pl_telegram.py
  2. 0 53
      playlistalo-telegram.py
  3. 35 1
      playlistalo.py

+ 8 - 0
pl_telegram.py

@@ -0,0 +1,8 @@
+#!/usr/bin/env python3
+#esegue il bot Telegram
+
+import playlistalo
+
+if __name__ == '__main__':
+    playlistalo.telegram_bot()
+    

+ 0 - 53
playlistalo-telegram.py

@@ -1,53 +0,0 @@
-#!/usr/bin/env python3
-#Bot Telegram per aggiungere pezzi in playlist
-
-import os
-import validators
-from telegram.ext import Updater, MessageHandler, Filters
-import playlistalo
-
-
-def msg_parser(bot, update):
-    print("Messaggio ricevuto")
-    urlz = update.message.text
-    u = update.message.from_user
-    user = "t_" + "-".join([i for i in [str(u.id), u.username] if i])
-    #print (urlz)
-    #print (user)
-    
-    #update.message.reply_text("Ciao " + update.message.from_user.username)
-    update.message.reply_text("Messaggio ricevuto. Elaboro...")
-
-    for url in [s for s in urlz.splitlines() if s.strip() != ""]:
-        #update.message.reply_text("Scarico %s" %(url))
-        # start the download
-        dl = playlistalo.add(url, user)
-        update.message.reply_text(dl)
-
-
-
-
-
-
-
-def main():
-    print ("Bot avviato")
-
-    # Create the EventHandler and pass it your bot's token.
-    updater = Updater(os.environ['TELEGRAM_TOKEN'])
-
-    # Get the dispatcher to register handlers
-    dp = updater.dispatcher
-
-    # parse message
-    dp.add_handler(MessageHandler(Filters.text, msg_parser))
-
-    # Start the Bot
-    updater.start_polling()
-
-    # Run the bot until you press Ctrl-C
-    updater.idle()
-
-
-if __name__ == '__main__':
-    main()

+ 35 - 1
playlistalo.py

@@ -12,6 +12,8 @@ import json
 import time
 import subprocess
 import random
+from telegram.ext import Updater, MessageHandler, Filters
+
 
 scriptpath = os.path.dirname(os.path.realpath(__file__))
 
@@ -247,6 +249,38 @@ def getposition(file):
 
 
 
+
+def __msg_parser(bot, update):
+    print("Messaggio ricevuto")
+    urlz = update.message.text
+    u = update.message.from_user
+    user = "t_" + "-".join([i for i in [str(u.id), u.username] if i])
+    #print (urlz)
+    #print (user)
+    
+    #update.message.reply_text("Ciao " + update.message.from_user.username)
+    update.message.reply_text("Messaggio ricevuto. Elaboro...")
+
+    for url in [s for s in urlz.splitlines() if s.strip() != ""]:
+        #update.message.reply_text("Scarico %s" %(url))
+        # start the download
+        dl = playlistalo.add(url, user)
+        update.message.reply_text(dl)
+
+def telegram_bot():
+    print ("Bot avviato")
+    # Create the EventHandler and pass it your bot's token.
+    updater = Updater(os.environ['TELEGRAM_TOKEN'])
+    # Get the dispatcher to register handlers
+    dp = updater.dispatcher
+    # parse message
+    dp.add_handler(MessageHandler(Filters.text, __msg_parser))
+    # Start the Bot
+    updater.start_polling()
+    # Run the bot until you press Ctrl-C
+    updater.idle()
+
+
+
 if __name__ == '__main__':
     print ("This is a package, use other commands to run it")
-    getposition("playlist/Itec78/20200404145736|George Baker- Little Green Bag|4b1wt3-zpzQ.m4az")