SHARE
TWEET

Untitled

a guest Sep 24th, 2019 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from functools import wraps
  2. from utils import controller
  3. import MySQLdb
  4. import config
  5. import time
  6.  
  7. LIST_OF_ADMINS = [605363037,53451006,77582926,442991919,63346884,339380551,91141817]
  8.  
  9.  
  10. def restricted(func):
  11.     @wraps(func)
  12.     def wrapped(update, context):
  13.         user_id = update.effective_user.id
  14.         if user_id not in LIST_OF_ADMINS:
  15.             print("Unauthorized access denied for {}.".format(user_id))
  16.             return
  17.         return func(update, context)
  18.     return wrapped
  19. #CANCELLA COMANDI
  20. def cancellacomandi(func):
  21.     @wraps(func)
  22.     def wrapped(update, context):
  23.         bot = context.bot
  24.         if update.message.text is not None:
  25.           if update.message.text.startswith("/"):
  26.               bot.delete_message(update.message.chat_id, update.message.message_id)
  27.         return func(update, context)
  28.     return wrapped
  29. #OWNERBOT
  30. OWNER_LIST= [605363037]
  31.  
  32. def ownerbot(func):
  33.     @wraps(func)
  34.     def wrapped(update, context):
  35.        
  36.         if update.effective_user is not None:
  37.             user_id = update.effective_user.id
  38.             if user_id not in OWNER_LIST:
  39.                 print("Unauthorized access denied for {}.".format(user_id))
  40.                 return
  41.         else:
  42.             return False
  43.         return func(update, context)
  44.     return wrapped
  45. #COMANDI PRIVATI
  46. def private(fn):
  47.   def wrapper(*args,**kwargs):
  48.    
  49.     message = args[0].message
  50.     if message.chat.type == 'private':
  51.       return fn(*args,**kwargs)
  52.     else:
  53.       return False
  54.   return wrapper
  55. #SALVATAGGIO UTENTI
  56. def register_user(func):
  57.     @wraps(func)
  58.     def wrapped(update, context):
  59.         usersid = str(update.effective_user.id)
  60.        
  61.         db=MySQLdb.connect(
  62.    
  63.         config.database['server'],
  64.         config.database['user'],
  65.         config.database['password'],
  66.         config.database['name'])
  67.         db.autocommit(True)
  68.         db.set_character_set('utf8mb4')
  69.         cur=db.cursor()
  70.    
  71.         query = 'INSERT INTO utenti (user_id) VALUES (%s)'
  72.         cur.execute(query, [usersid])
  73.         cur.close()
  74.         db.close()
  75.         return func(update, context)
  76.     return wrapped
  77. #SALVATAGGIO UTENTI GIVEWAY
  78. def register_giveway(func):
  79.     @wraps(func)
  80.     def wrapped(update, context):
  81.         usersid = str(update.effective_user.username)
  82.         db=MySQLdb.connect(
  83.    
  84.         config.database['server'],
  85.         config.database['user'],
  86.         config.database['password'],
  87.         config.database['name'])
  88.         db.autocommit(True)
  89.         db.set_character_set('utf8mb4')
  90.         cur=db.cursor()
  91.    
  92.         query = 'INSERT IGNORE INTO giveaway (user_id) VALUES (%s)'
  93.         cur.execute(query,[usersid])
  94.         cur.close()
  95.         db.close()
  96.         return func(update, context)
  97.     return wrapped
  98. #DELETE A TEMPO
  99. def delete(func):
  100.     @wraps(func)
  101.     def wrapped(update, context, delay=10):
  102.         try:
  103.             bot = context.bot
  104.             try:
  105.                 message_id = update.message.message_id
  106.                 chat_id = update.chat_id
  107.             except AttributeError as e:
  108.                 message_id = update.message.message_id
  109.                 chat_id = update.message.chat_id
  110.             if delay > 10:
  111.                 time.sleep(delay)
  112.             return bot.delete_message(chat_id,message_id)
  113.         except Exception as e:
  114.             print(e)
  115.             return func(update, context)
  116.         return wrapped
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top