Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import logging
- import aiohttp
- import sqlite3
- from datetime import timedelta
- from aiogram import Bot
- from aiogram.dispatcher import Dispatcher
- from aiogram.utils.executor import start_polling
- GROUP_ID = -1001325612941 # Ваш ID группы
- API_TOKEN = '557867522:AAFU-7Ct0wHSiSEotIyJSfxeeaFxq_d0LWQ'
- PROXY_URL = 'http://147.135.210.114:54566' # Or 'socks5://...'
- conn = sqlite3.connect("ban_dict.db")
- cursor = conn.cursor()
- try:
- cursor.execute("""CREATE TABLE albums
- (id text)
- """)
- except Exception:
- pass
- # If authentication is required in your proxy then uncomment next line and change login/password for it
- # PROXY_AUTH = aiohttp.BasicAuth(login='login', password='password')
- # And add `proxy_auth=PROXY_AUTH` argument in line 25, like this:
- # >>> bot = Bot(token=API_TOKEN, loop=loop, proxy=PROXY_URL, proxy_auth=PROXY_AUTH)
- # Also you can use Socks5 proxy but you need manually install aiosocksy package.
- # Get my ip URL
- GET_IP_URL = 'http://bot.whatismyipaddress.com/'
- logging.basicConfig(level=logging.INFO)
- loop = asyncio.get_event_loop()
- bbot = Bot(token=API_TOKEN, loop=loop, proxy=PROXY_URL)
- dp = Dispatcher(bbot)
- async def fetch(url, proxy=None, proxy_auth=None):
- async with aiohttp.ClientSession() as session:
- async with session.get(url, proxy=proxy, proxy_auth=proxy_auth) as response:
- return await response.text()
- @dp.message_handler(func=lambda message: message.entities is not None and message.chat.id == GROUP_ID)
- async def cmd_start( message):
- #message: types.Message,
- for entity in message.entities:
- message_id = message.message_id
- if message.from_user.username == None:
- username = message.from_user.first_name
- else:
- username = "@"+message.from_user.username
- time = timedelta(days=31)
- if entity.type in ["url", "text_link"]:
- userid=message.from_user.id
- #print(userid)
- chat_member = await bbot.get_chat_member(message.chat.id, userid)
- #print(chat_member.status)
- if (chat_member.status == "administrator") or (chat_member.status == "creator"):
- pass
- else:
- sql = "SELECT * FROM albums WHERE id=?"
- cursor.execute(sql, [(userid)])
- all_id = cursor.fetchone()
- #print(all_id)
- #await bbot.get_chat_member(message.chat.id, userid)
- #print(await bbot.get_chat_member(message.chat.id, userid))
- if str(userid) not in str(all_id):
- await bbot.send_message(text="%s, не надо сюда кидать рекламу)"% username, chat_id=message.chat.id)
- #print(message)
- #add_user(userid)
- cursor.execute("INSERT INTO albums VALUES ('%s')" % (userid))
- conn.commit()
- #ban_dict.update({message.from_user.id:'1'})
- else:
- sql = "DELETE FROM albums WHERE ('%s')" % (userid)
- cursor.execute(sql)
- conn.commit()
- await bbot.send_message(text="%s, я предупреждал)" % username, chat_id=message.chat.id)
- await bbot.kick_chat_member(message.chat.id, message.from_user.id, until_date=time)
- #del_user(userid)
- #del ban_dict[message.from_user.id]
- await bbot.delete_message(message.chat.id, message.message_id)
- else:
- return
- def add_user(userid):
- cursor.execute("INSERT INTO albums VALUES ('%s')"%(userid))
- conn.commit()
- def del_user(userid):
- sql = "DELETE FROM albums VALUES ('%s')"%(userid)
- cursor.execute(sql)
- conn.commit()
- def find_user(userid):
- sql = "SELECT * FROM albums WHERE id=?"
- cursor.execute(sql, [(userid)])
- if cursor.fetchall()==userid:
- return True
- else:
- return False
- if __name__ == '__main__':
- start_polling(dp, loop=loop, skip_updates=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement