def filef(bot,update):
# get file id
file = bot.getFile(update.message.document.file_id)
# create a randon temp file name
tf = tempfile.mkstemp()
# download file
file.download(tf[1])
# read file content
try:
tfco = open(tf[1],"r")
tfc = tfco.read()
tfco.close()
except Exception as e:
# if it is not text file
bot.sendMessage(chat_id=update.message.chat_id,reply_to_message_id=update.message.message_id,text=" ?? Please send me a text file")
# get user name for author
try:
author = update.message.from_user.first_name + " " + update.message.from_user.last_name
except Exception:
author = "Anonymous user"
# call paste function
url = paste(tfc , author)
# replay the url to user
bot.sendMessage(chat_id=update.message.chat_id,reply_to_message_id=update.message.message_id,text=url)
评论列表
文章目录