Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-*- Coding: utf-8 -*-
- import telebot
- from pathlib import Path
- import os
- import random
- bottoken = '794241937:AAFMSkYblndvGWBpOXjfoO5pzNp59UqMblE'
- bot = telebot.TeleBot(bottoken)
- okay = ['okay', 'ok', 'k', 'yes', 'yep']
- admins = [667754854]
- @bot.message_handler(commands=['order'])
- def ordercommand(message):
- if message.chat.type == 'private':
- try:
- open(str(message.chat.id) + '.txt', "r").close()
- except FileNotFoundError:
- try:
- usrnm1 = open(str(message.chat.id) + '.txt', "w")
- usrnm1.write('@' + str(message.chat.username) + '\n')
- usrnm1.close()
- except:
- print('ERROR : Error while creating new File!')
- else:
- bot.reply_to(message, "Your're Data will be stored in our Servers for ordering other products. Is that ok?")
- else:
- try:
- os.remove(str(message.chat.id) + '.txt')
- except:
- print('ERROR : Error in ordercommand()')
- else:
- try:
- usrnm = open(str(message.chat.id) + '.txt', "w")
- usrnm.write('@' + str(message.chat.username) + '\n')
- usrnm.close()
- except Exception as e:
- print('ERROR : Error while creating new File!')
- print('ERROR : ' + e)
- else:
- bot.reply_to(message, 'You are now going to the order process. Is that ok?')
- bot.register_next_step_handler(message, order)
- def order(message):
- global okay
- if message.text == 'okay': #To do: Make a custom button
- bot.send_message(message.chat.id, 'Please enter the Product ID.')
- bot.register_next_step_handler(message, save_id)
- else:
- bot.reply_to(message, "Sorry, I didn't understand you.")
- def save_id(message):
- file = open(str(message.chat.id) + '.txt', "a")
- file.write(str(message.chat.id) + '\n')
- try:
- print(int(message.text))
- except:
- bot.reply_to(message, 'ID Should be a number!')
- else:
- file.write(str(message.text) + '\n')
- file.close()
- bot.send_message(message.chat.id, "Now send the picture of the product. Make sure it's a png or jpg file.")
- bot.register_next_step_handler(message, picture_handler)
- def picture_handler(message):
- fileID = message.photo[-1].file_id # get the file id (seems has 3 sizes?) [-1] means the last one
- file_info = bot.get_file(fileID) # get file info
- downloaded_file = bot.download_file(file_info.file_path) # download file data?
- print(file_info)
- fname = os.path.splitext(os.path.basename(file_info.file_path))[0]
- with open(str(message.chat.id) + "_1.png", 'wb') as new_file: # create file on a path?
- new_file.write(downloaded_file)
- bot.send_message(message.chat.id, 'Send me another one!')
- bot.register_next_step_handler(message, picture_handler_2)
- def picture_handler_2(message):
- fileID = message.photo[-1].file_id # get the file id (seems has 3 sizes?) [-1] means the last one
- file_info = bot.get_file(fileID) # get file info
- downloaded_file = bot.download_file(file_info.file_path) # download file data?
- print(file_info)
- fname = os.path.splitext(os.path.basename(file_info.file_path))[0]
- with open(str(message.chat.id) + "_2.png", 'wb') as new_file: # create file on a path?
- new_file.write(downloaded_file)
- bot.send_message(message.chat.id, "Now send me you're phone number.")
- bot.register_next_step_handler(message, phonenumber)
- def phonenumber(message):
- pn = open(str(message.chat.id) + '.txt', "a")
- pn.write(str(message.text) + '\n')
- pn.close()
- bot.send_message(message.chat.id, 'Now send me the shipping adress.')
- bot.register_next_step_handler(message, adress)
- def adress(message):
- global admins
- global srandom
- bot.send_message(message.chat.id, "Thank you! you're information is beeing sent to an admin.")
- sa = open(str(message.chat.id) + '.txt', "a")
- sa.write(str(message.text) + '\n')
- rnd_admin = random.choice(admins)
- sndfile = open(str(message.chat.id) + '.txt', "r")
- send = sndfile.read()
- sndfile.close()
- bot.send_message(rnd_admin, send)
- bot.send_photo(rnd_admin, str(message.chat.id) + '_1.png')
- bot.send_photo(rnd_admin, str(message.chat.id) + '_2.png')
- #Reordering
- #---------------------------------------------------------------------
- @bot.message_handler(commands=['reorder'])
- def reorder(message):
- try:
- open(str(message.chat.id) + '.txt', "r").close()
- except FileNotFoundError:
- bot.send_message(message.chat.id, "You have never ordered before!")
- else:
- bot.send_message(message.chat.id, "Now send me the one picture. Make sure it's a jpg or png file.")
- bot.register_next_step_handler(message, picture_handler_re)
- def picture_handler_re(message):
- fileID = message.photo[-1].file_id # get the file id (seems has 3 sizes?) [-1] means the last one
- file_info = bot.get_file(fileID) # get file info
- downloaded_file = bot.download_file(file_info.file_path) # download file data?
- print(file_info)
- fname = os.path.splitext(os.path.basename(file_info.file_path))[0]
- with open(str(message.chat.id) + "_1.png", 'wb') as new_file: # create file on a path?
- new_file.write(downloaded_file)
- bot.send_message(message.chat.id, 'Send me another one!')
- bot.register_next_step_handler(message, picture_handler_2_re)
- def picture_handler_2_re(message):
- global admins
- global srandom
- fileID = message.photo[-1].file_id # get the file id (seems has 3 sizes?) [-1] means the last one
- file_info = bot.get_file(fileID) # get file info
- downloaded_file = bot.download_file(file_info.file_path) # download file data?
- print(file_info)
- fname = os.path.splitext(os.path.basename(file_info.file_path))[0]
- with open(str(message.chat.id) + "_2.png", 'wb') as new_file: # create file on a path?
- new_file.write(downloaded_file)
- bot.send_message(message.chat.id, "Thank you! you're information is beeing sent to an admin.")
- try:
- rnd_admin = random.choice(admins)
- sndfile = open(str(message.chat.id) + '.txt', "r")
- send = sndfile.read()
- bot.send_message(rnd_admin, send)
- sndfile.close()
- except Exception as e:
- print('ERROR : ' + e)
- bot.polling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement