Advertisement
nikitttttta

Untitled

Jun 11th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. import asyncio
  2. import logging
  3. import aiohttp
  4. import sqlite3
  5. from datetime import timedelta
  6. from aiogram import Bot
  7. from aiogram.dispatcher import Dispatcher
  8. from aiogram.utils.executor import start_polling
  9. GROUP_ID = -1001325612941 # Ваш ID группы
  10. API_TOKEN = '557867522:AAFU-7Ct0wHSiSEotIyJSfxeeaFxq_d0LWQ'
  11. PROXY_URL = 'http://147.135.210.114:54566' # Or 'socks5://...'
  12. conn = sqlite3.connect("ban_dict.db")
  13. cursor = conn.cursor()
  14. try:
  15. cursor.execute("""CREATE TABLE albums
  16. (id text)
  17. """)
  18. except Exception:
  19. pass
  20. # If authentication is required in your proxy then uncomment next line and change login/password for it
  21. # PROXY_AUTH = aiohttp.BasicAuth(login='login', password='password')
  22. # And add `proxy_auth=PROXY_AUTH` argument in line 25, like this:
  23. # >>> bot = Bot(token=API_TOKEN, loop=loop, proxy=PROXY_URL, proxy_auth=PROXY_AUTH)
  24. # Also you can use Socks5 proxy but you need manually install aiosocksy package.
  25.  
  26. # Get my ip URL
  27. GET_IP_URL = 'http://bot.whatismyipaddress.com/'
  28.  
  29. logging.basicConfig(level=logging.INFO)
  30.  
  31. loop = asyncio.get_event_loop()
  32. bbot = Bot(token=API_TOKEN, loop=loop, proxy=PROXY_URL)
  33. dp = Dispatcher(bbot)
  34.  
  35.  
  36. async def fetch(url, proxy=None, proxy_auth=None):
  37.  
  38. async with aiohttp.ClientSession() as session:
  39.  
  40. async with session.get(url, proxy=proxy, proxy_auth=proxy_auth) as response:
  41. return await response.text()
  42.  
  43.  
  44. @dp.message_handler(func=lambda message: message.entities is not None and message.chat.id == GROUP_ID)
  45.  
  46. async def cmd_start( message):
  47. #message: types.Message,
  48.  
  49.  
  50. for entity in message.entities:
  51. message_id = message.message_id
  52.  
  53.  
  54. if message.from_user.username == None:
  55. username = message.from_user.first_name
  56. else:
  57. username = "@"+message.from_user.username
  58. time = timedelta(days=31)
  59. if entity.type in ["url", "text_link"]:
  60. userid=message.from_user.id
  61. #print(userid)
  62. chat_member = await bbot.get_chat_member(message.chat.id, userid)
  63. #print(chat_member.status)
  64. if (chat_member.status == "administrator") or (chat_member.status == "creator"):
  65. pass
  66. else:
  67. sql = "SELECT * FROM albums WHERE id=?"
  68. cursor.execute(sql, [(userid)])
  69. all_id = cursor.fetchone()
  70. #print(all_id)
  71. #await bbot.get_chat_member(message.chat.id, userid)
  72. #print(await bbot.get_chat_member(message.chat.id, userid))
  73. if str(userid) not in str(all_id):
  74.  
  75. await bbot.send_message(text="%s, не надо сюда кидать рекламу)"% username, chat_id=message.chat.id)
  76. #print(message)
  77. #add_user(userid)
  78. cursor.execute("INSERT INTO albums VALUES ('%s')" % (userid))
  79. conn.commit()
  80. #ban_dict.update({message.from_user.id:'1'})
  81.  
  82. else:
  83.  
  84. sql = "DELETE FROM albums WHERE ('%s')" % (userid)
  85. cursor.execute(sql)
  86. conn.commit()
  87. await bbot.send_message(text="%s, я предупреждал)" % username, chat_id=message.chat.id)
  88. await bbot.kick_chat_member(message.chat.id, message.from_user.id, until_date=time)
  89. #del_user(userid)
  90.  
  91. #del ban_dict[message.from_user.id]
  92. await bbot.delete_message(message.chat.id, message.message_id)
  93. else:
  94.  
  95. return
  96.  
  97. def add_user(userid):
  98. cursor.execute("INSERT INTO albums VALUES ('%s')"%(userid))
  99. conn.commit()
  100.  
  101. def del_user(userid):
  102. sql = "DELETE FROM albums VALUES ('%s')"%(userid)
  103. cursor.execute(sql)
  104. conn.commit()
  105.  
  106. def find_user(userid):
  107. sql = "SELECT * FROM albums WHERE id=?"
  108. cursor.execute(sql, [(userid)])
  109. if cursor.fetchall()==userid:
  110. return True
  111. else:
  112. return False
  113.  
  114. if __name__ == '__main__':
  115. start_polling(dp, loop=loop, skip_updates=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement