Advertisement
ftimoteo

TypeError: 'in<string>' requires string as left operand, not

Nov 16th, 2016
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.44 KB | None | 0 0
  1. import threading
  2. import os
  3.  
  4. import telebot
  5. from ybot import YBot
  6. import dbmod # Module database
  7. import sshmod # Module ssh
  8.  
  9. ywbot = YBot() # Instance classe
  10. bot = ywbot.handler() # Instance telebot
  11. commands = bot.message_handler
  12. errors = {'notusername': 'Tente /cadastrar nomeusuario (sem espaços)',
  13.           'limitexceeded':'O limite de 250 pessoas cadastradas foi excedido!',
  14.           'notgroup': 'Desculpe mas eu não funciono nesse chat.',
  15.           'registered': 'Parece que você já está cadastrado.',
  16.           'notprivate': 'Só posso enviar sua senha em privado.',
  17.           'notregistered': 'Parece que você não está cadastrado.',
  18.           'notadmin': 'Você não é um administrador',
  19.           'delnoneusername': 'Você precisa enviar o username',
  20.           'notfounduser': 'Usuário não existe.',
  21.           'notehi': 'Arquivos ehi não cadastrados',
  22.           'notmasteradmin': 'Você não é um master admin.',
  23.           'notidadmin': 'Você precisa enviar o id do admin, sem espaços. Ex: 12345678',
  24.           'notisdigit': 'Você precisa enviar somente números sem espaços.'}
  25. sucess = {'registerok': '*Cadastro concluido! Fale comigo no privado para receber sua senha.(/senha)*',
  26.           'password': 'Sua senha é {}',
  27.           'deleteok': 'Usuário apagado!',
  28.           'savedfile': 'Arquivos cadastrados!',
  29.           'delfiles': 'Arquivos apagados!'}
  30.  
  31. @commands('/helpsv2')
  32. def helper(msg):
  33.     admins = ywbot.getAdmins()
  34.     adminsUserName = ''
  35.     for admin in admins:
  36.         if ywbot.getInfoUser(admin):
  37.             adminsUserName += '@'+ywbot.getInfoUser(admin).username+'\n'
  38.  
  39.     text = """
  40.        \n*Minhas funcionalidades são:*\
  41.        \n*# Para usuário*\
  42.        ```
  43.        \n/cadastrar nome\
  44.        \n/helpsv2\
  45.        \n/senha\
  46.        \n/ehi\
  47.        ```
  48.        \n*# Para admin*\
  49.        ```
  50.        \n/listar_usuarios(OFF)\
  51.        \n/apagar_usuario nome\
  52.        \n/limpar_expirados(OFF)\
  53.        \n/apagar_arquivos\
  54.        \n/addfile\
  55.        \n/cadastrar_admin\
  56.        \n/apagar_admin nome\
  57.        ```
  58.        \n*Administradores*\
  59.        \n{}\
  60.        \n_Desenvolvido por:_ @ftimoteo\
  61.        \n_Versão 2.1_""".format(adminsUserName)
  62.     bot.send_message(msg.chat.id, text, parse_mode='Markdown')
  63.  
  64. @commands('cadastrar')
  65. def register_user(msg):
  66.     userid = msg.from_user.id
  67.     text = msg.text.split(maxsplit=1)
  68.     if len(text) <= 1:
  69.         bot.reply_to(msg, errors['notusername'])
  70.     elif dbmod.count_logins() >= 250:
  71.         bot.reply_to(msg, errors['limitexceeded'])
  72.     elif msg.chat.id not in ywbot.getGroups():
  73.         bot.reply_to(msg, errors['notgroup'])
  74.     elif sshmod.user_exists(text[1]) or dbmod.registred_user(userid):
  75.         bot.reply_to(msg, errors['registered'])
  76.     else:
  77.         sshmod.register_user(text[1], msg)
  78.         ywbot.save_log('[+] User {} registred.'.format(text[1]))
  79.         bot.reply_to(msg, sucess['registerok'], parse_mode='Markdown')
  80.  
  81. @commands('senha')
  82. def my_password(msg):
  83.     if msg.chat.type != 'private':
  84.         return bot.send_message(msg.chat.id, errors['notprivate'])
  85.     password = dbmod.search_password(msg.from_user.id)
  86.     if password:
  87.         bot.send_message(msg.chat.id, sucess['password'].format(password))
  88.     else:
  89.         bot.send_message(msg.chat.id, errors['notregistered'])
  90.  
  91. @commands('apagar_usuario')
  92. def delete_user(msg):
  93.     username = (msg.text).split(maxsplit=1)
  94.     if msg.from_user.id not in ywbot.getAdmins():
  95.         bot.send_message(msg.chat.id, errors['notadmin'])
  96.     elif len(username) <= 1:
  97.         bot.send_message(msg.chat.id, errors['delnoneusername'])
  98.     else:
  99.         if sshmod.user_exists(username[1]):
  100.             sshmod.delete_user(username[1])
  101.         dbmod.delete_user(username[1])
  102.         ywbot.save_log('[-] User {} deleted from admin {}'.format(username[1],
  103.                                                                   msg.from_user.username))
  104.         bot.send_message(msg.chat.id, sucess['deleteok'])
  105.  
  106.  
  107. @commands('addfile')
  108. def add_files(msg):
  109.     if msg.from_user.id not in ywbot.getAdmins():
  110.         bot.send_message(msg.chat.id, errors['notadmin'])
  111.     else:
  112.         ywbot.setFiles(msg.chat.id, msg.reply_to_message.message_id)
  113.         ywbot.save_log('[+] News files saved')
  114.         bot.send_message(msg.chat.id, sucess['savedfile'])
  115.  
  116. @commands('ehi')
  117. def ehi(msg):
  118.     if not ywbot.getFiles():
  119.         bot.send_message(msg.chat.id, errors['notehi'])
  120.     else:
  121.         for from_chat_id, message_id in ywbot.getFiles():
  122.             bot.forward_message(msg.chat.id, from_chat_id, message_id)
  123.  
  124. @commands('apagar_arquivos')
  125. def delete_files(msg):
  126.     if msg.from_user.id not in ywbot.getAdmins():
  127.         bot.send_message(msg.chat.id, errors['notadmin'])
  128.     else:
  129.         ywbot.delFiles()
  130.         ywbot.save_log('[-] Files deleted from admin {}'.format(msg.from_user.id))
  131.         bot.send_message(msg.chat.id, sucess['delfiles'])
  132.  
  133.  
  134. @commands('cadastrar_admin')
  135. def register_admin(msg):
  136.     text = msg.text.split(maxsplit=1)
  137.     if msg.from_user.id not in ywbot.getMasterAdmin():
  138.         bot.send_message(msg.chat.id, errors['notmasteradmin'])
  139.     elif len(text) <= 1:
  140.         bot.send_message(msg.chat.id, errors['notidadmin'])
  141.     elif not text[1].isdigit():
  142.         bot.send_message(msg.chat.id, errors['notisdigit'])
  143.     else:
  144.         adminid = int(text[1])
  145.         ywbot.save_config(adminid)
  146.         ywbot.load_config()
  147.         ywbot.save_log('[+] Admin ID {} added from Master admin: {}'.format(adminid, msg.from_user.id))
  148.  
  149. @commands('apagar_admin')
  150. def delete_admin(msg):
  151.     text = msg.text.split(maxsplit=1)
  152.     if msg.from_user.id not in ywbot.getMasterAdmin():
  153.         bot.send_message(msg.chat.id, errors['notmasteradmin'])
  154.     elif len(text) <= 1:
  155.         bot.send_message(msg.chat.id, errors['notidadmin'])
  156.     elif not text[1].isdigit():
  157.         bot.send_message(msg.chat.id, errors['notisdigit'])
  158.     else:
  159.         adminid = int(text[1])
  160.         ywbot.del_config(adminid)
  161.         ywbot.load_config()
  162.         ywbot.save_log('[-] Admin ID {} deleted from Master admin {}'.format(adminid, msg.from_user.id))
  163.  
  164. def search_expired_users():
  165.     "Search expired users and delete"
  166.     pass
  167.  
  168.  
  169.  
  170. if __name__ == '__main__':
  171.     if 'TOKEN_BOT' not in os.environ:
  172.         print('Please declare a global variable named TOKEN_BOT on system')
  173.         exit()
  174.     ywbot.load_config()
  175.     bot.skip_pending = True
  176.     print('Working...')
  177.     bot.polling(none_stop=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement