Advertisement
Guest User

wela

a guest
Jul 25th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.37 KB | None | 0 0
  1. import telegram, json
  2. from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler, RegexHandler, ConversationHandler
  3. import os
  4. from os import system
  5. from time import strftime
  6. from telegram import Chat
  7. import bittrex
  8.  
  9. def registerKS():
  10.     bot.sendMessage(chat_id=update.message.chat_id, text="Please enter your API Key")
  11.     AKey = update.message.text
  12.  
  13. def choose():
  14.     results = bot.sendMessage(chat_id=update.message.chat_id, text="Test", reply_markup={"keyboard":[["Account"], ["Balance"], ["VolT"], ["PercT"]]})
  15.     return results
  16.  
  17. def checkid():
  18.     iduser = update.message.from_user.id
  19.     iduser = str(iduser)
  20.     path = os.path.dirname(os.path.abspath(__file__))+"/Datab/Users.json"
  21.     fl = json.loads(open(path).read())
  22.     for user in fl:
  23.         if user==iduser:
  24.             if fl[user]["activate"]==1:
  25.                 return True
  26.     return False
  27.  
  28. def menu(bot, update):
  29.     unlocked = checkid()
  30.     idu = update.message.from_user.id
  31.     idu = str(idu)
  32.     boolkey = checker("Key", idu)
  33.     boolsec = checker("Secret", idu)
  34.     if(not(boolkey) or not(boolsec)):
  35.         bot.sendMessage("You still have to register your API Key and Secret.")
  36.         registerKS()
  37.         menu()
  38.     if unlocked:
  39.         choice = choose()
  40.         if choice=="Account":
  41.             Account()
  42.         else if choice=="Balance":
  43.         else if choice=="VolT":
  44.         else if choice=="PercT":
  45.     menu(bot, update)
  46.  
  47. def activate(bot, update):
  48.     idchat = update.message.chat_id
  49.     if idchat==-183997848:
  50.         path = os.path.dirname(os.path.abspath(__file__))+"/Datab/Users.json"
  51.         fl = json.loads(open(path).read())
  52.         stringa = update.message.text
  53.         stringa = stringa.replace("/activate ", "")
  54.         if fl[stringa]["activate"]==1:
  55.             bot.sendMessage(chat_id=-183997848, text="Account already activated.")
  56.         else:
  57.             fl[stringa]["activate"] = 1
  58.             bot.sendMessage(chat_id=-183997848, text="Account now activated.")
  59.         with open(path, "w") as flw:
  60.             flw.write(json.dumps(fl))
  61.     return
  62.  
  63. def add_user(idu):
  64.     path = os.path.dirname(os.path.abspath(__file__))
  65.     fl = json.loads(open(path+"/Datab/Users.json").read())
  66.     fl[str(idu)] = {"activate":0}
  67.     with open(path+"/Datab/Users.json", "w") as flw:
  68.         flw.write(json.dumps(fl))
  69.  
  70. def checker(tipo, data):
  71.     path = os.path.dirname(os.path.abspath(__file__))+"/Datab/Users.json"
  72.     fl = json.loads(open(path).read())
  73.     if tipo=="ID":
  74.         for user in fl:
  75.             if user==data:
  76.                 return True
  77.         return False
  78.     elif tipo=="activate":
  79.         for user in fl:
  80.             if user==data:
  81.                 return fl[user]["activate"]
  82.     elif tipo=="Key":
  83.         for user in fl:
  84.             if user==data:
  85.                 for entry in fl[user]:
  86.                     if entry=="Key":
  87.                         return True
  88.         return False
  89.     elif tipo=="Secret":
  90.         for user in fl:
  91.             if user==data:
  92.                 for entry in fl[user]:
  93.                     if entry=="Secret":
  94.                         return True
  95.         return False
  96.  
  97. def start(bot, update):
  98.     unlocked = False
  99.     user = update.message.from_user.username
  100.     nick = update.message.from_user.first_name
  101.     idu = update.message.from_user.id
  102.     check_id = checker("ID", str(idu))
  103.     if not(check_id):
  104.         update.message.reply_text("Welcome to the Paprikat TradingBot!",parse_mode="markdown")
  105.         bot.sendMessage(chat_id=update.message.chat_id, text="I see you're a new user! Contact @Knight_mare for the account activation.")
  106.         add_user(idu)
  107.         bot.sendMessage(chat_id=-183997848, text="Activation Request:\n\n@%s\n%s\nID =  %s"%(user, nick, str(idu)))
  108.         return
  109.     check_status = checker("activate", str(idu))
  110.     if check_id and check_status!=1:
  111.         bot.sendMessage(chat_id=update.message.chat_id, text="Your account is not ready yet. Contact @Knight_mare for activation.")
  112.     else:
  113.         bot.sendMessage(chat_id=update.message.chat_id, text="Your account is activated and ready to use.")
  114.         unlocked = True
  115.     return
  116.  
  117. def help(bot, update):
  118.     bot.sendMessage(chat_id=update.message.chat_id,text="At the moment the command is under work.")
  119.     return
  120.  
  121. def status(bot, update):
  122.     #idu = update.message.from_user.id
  123.     # ##try:
  124.     #     nick = update.message.new_chat_member['first_name']
  125.     #     text = "Welcome KuriGoha-- Aehm, " + nick + "! uwu"
  126.     #     update.message.reply_text(text, quote=False)
  127.     #     print(strftime("%H:%M:%S -"), '%s joined a group! ID#(%s)' % (nick, idu))
  128.     #     return
  129.     # except:
  130.     #     pass
  131.     # try:
  132.     #     nick = update.message.left_chat_member['first_name']
  133.     #     text = "Sayonara " + nick + " o/"
  134.     #     update.message.reply_text(text, quote=False)
  135.     #     print(strftime("%H:%M:%S -"), '%s joined a group! ID#(%s)' % (nick, idu))
  136.     #     return
  137.     # ##except:
  138.         pass
  139.  
  140. def register(bot, update):
  141.     if update.message.chat.type== Chat.PRIVATE:
  142.         idchat = update.message.chat_id
  143.         add_user(idu)
  144.     return
  145.  
  146. def getid(bot, update):
  147.     idchat = update.message.chat_id
  148.     bot.sendMessage(chat_id=idchat,text=idchat)
  149.     return
  150.  
  151. def hint(bot, update):
  152.     if update.message.chat.type == Chat.PRIVATE:
  153.         while True:
  154.             lmao = update.message.text
  155.             if lmao.replace(" ","") == "/hint":
  156.                 lmao = update.message.text
  157.                 bot.sendMessage(chat_id=update.message.chat_id, text="Write now your suggestion.")
  158.                 while lmao.replace(" ","") == "/hint" and lmao!="Write now your suggestion.":
  159.                     lmao = update.message.text
  160.                 hint = update.message.text
  161.                 bot.sendMessage(chat_id=update.message.chat_id, text="Your suggestion is being sent.")
  162.                 break
  163.             else:
  164.                 hint = lmao.replace("/hint ","")
  165.                 bot.sendMessage(chat_id=update.message.chat_id,text="Your suggestion is being sent.")
  166.                 break
  167.         bot.sendMessage(chat_id= -183997848,text=("@"+update.message.from_user.username + " says: " + hint))
  168.     return
  169.  
  170.  
  171. # def trying(bot, update):
  172. #     results = bot.sendMessage(chat_id=update.message.chat_id, text="Test", reply_markup={"keyboard":[["Test1"], ["Test2"], ["Test3"], ["Test4"]]})
  173. #     return results
  174.  
  175. def reader(bot, update):
  176.     user = update.message.from_user.username
  177.     cont = update.message.text
  178.     idg = update.message.chat.id
  179.     idu = update.message.from_user.id
  180.     return
  181.  
  182. def main():
  183.     updater = Updater("276224501:AAFuPg3olIKu1qrgZXe_g8qsCXiWAJhEnGg")
  184.     dp = updater.dispatcher
  185.     dp.add_handler(CommandHandler("start", start))
  186.     dp.add_handler(CommandHandler("activate", activate))
  187.     dp.add_handler(CommandHandler("menu", menu))
  188.     # dp.add_handler(CommandHandler("trying", trying))
  189.     dp.add_handler(CommandHandler("help", help))
  190.     dp.add_handler(CommandHandler("hint", hint))
  191.     dp.add_handler(CommandHandler("getid", getid))
  192.     dp.add_handler(MessageHandler(Filters.text, reader))
  193.     dp.add_handler(MessageHandler(Filters.status_update, status))
  194.     updater.start_polling()
  195.     updater.idle()
  196.  
  197. if __name__ == '__main__':
  198.     system("cls")
  199.     print("Press CTRL+C to close the bot.")
  200.     main()
  201.     print(strftime("%H:%M:%S -"),"Bot has closed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement