Integrated Telegram bot

This commit is contained in:
itec 2020-04-04 21:49:50 +02:00
parent 7ccd224cab
commit d2376cff78
3 changed files with 43 additions and 54 deletions

8
pl_telegram.py Executable file
View file

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

View file

@ -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()

View file

@ -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")