telegram bot update
This commit is contained in:
parent
3d82429208
commit
258fd3ee22
1 changed files with 20 additions and 16 deletions
|
@ -21,7 +21,8 @@ import argparse
|
|||
|
||||
from musicpd import MPDClient
|
||||
|
||||
from telegram.ext import Updater, MessageHandler, Filters
|
||||
from telegram import Update
|
||||
from telegram.ext import Application, ContextTypes, MessageHandler, filters
|
||||
from mastodon import Mastodon, StreamListener
|
||||
|
||||
scriptpath = os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -349,7 +350,7 @@ def getposition(file):
|
|||
|
||||
|
||||
|
||||
def telegram_msg_parser(bot, update):
|
||||
async def telegram_msg_parser(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
print("Messaggio ricevuto")
|
||||
msg = update.message.text
|
||||
id = str(update.message.from_user.id)
|
||||
|
@ -361,30 +362,33 @@ def telegram_msg_parser(bot, update):
|
|||
#print (user)
|
||||
|
||||
if not urls:
|
||||
update.message.reply_text("Non ho trovato indirizzi validi...")
|
||||
await update.message.reply_text("Non ho trovato indirizzi validi...")
|
||||
return()
|
||||
|
||||
update.message.reply_text("Messaggio ricevuto. Elaboro...")
|
||||
await update.message.reply_text("Messaggio ricevuto. Elaboro...")
|
||||
|
||||
for url in urls:
|
||||
#update.message.reply_text("Scarico %s" %(url))
|
||||
# start the download
|
||||
dl = addurl(url, user)
|
||||
update.message.reply_text(dl)
|
||||
await update.message.reply_text(dl)
|
||||
|
||||
|
||||
def telegram_bot():
|
||||
print ("Bot avviato")
|
||||
# Create the EventHandler and pass it your bot's token.
|
||||
updater = Updater(TELEGRAM_TOKEN)
|
||||
# Get the dispatcher to register handlers
|
||||
dp = updater.dispatcher
|
||||
# parse message
|
||||
dp.add_handler(MessageHandler(Filters.text, telegram_msg_parser))
|
||||
# Start the Bot
|
||||
updater.start_polling()
|
||||
# Run the bot until you press Ctrl-C
|
||||
updater.idle()
|
||||
|
||||
application = Application.builder().token(TELEGRAM_TOKEN).build()
|
||||
# on non command i.e message - echo the message on Telegram
|
||||
application.add_handler(MessageHandler(filters.TEXT, telegram_msg_parser))
|
||||
# Run the bot until the user presses Ctrl-C
|
||||
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MastodonListener(StreamListener):
|
||||
|
@ -730,4 +734,4 @@ if __name__ == '__main__':
|
|||
elif args.command == 'plaympd':
|
||||
plaympd()
|
||||
else:
|
||||
parser.print_help()
|
||||
parser.print_help()
|
||||
|
|
Loading…
Reference in a new issue