diff --git a/__pycache__/config.cpython-312.pyc b/__pycache__/config.cpython-312.pyc index 8729b19..65a5666 100644 Binary files a/__pycache__/config.cpython-312.pyc and b/__pycache__/config.cpython-312.pyc differ diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index fd6a349..805abb5 100644 Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ diff --git a/app.log b/app.log new file mode 100644 index 0000000..3f77938 --- /dev/null +++ b/app.log @@ -0,0 +1,11 @@ +2024-02-12 22:56:37,219 - INFO - Start polling +2024-02-12 22:56:37,290 - INFO - Run polling for bot @ibuywork_bot id=6681002925 - 'IBuyWork' +2024-02-12 22:56:47,440 - INFO - Update id=502700407 is handled. Duration 468 ms by bot id=6681002925 +2024-02-12 22:56:50,888 - INFO - Update id=502700408 is handled. Duration 156 ms by bot id=6681002925 +2024-02-12 22:56:51,669 - INFO - Update id=502700409 is handled. Duration 218 ms by bot id=6681002925 +2024-02-12 22:56:52,423 - INFO - Update id=502700410 is handled. Duration 141 ms by bot id=6681002925 +2024-02-12 22:56:54,359 - INFO - Update id=502700411 is handled. Duration 171 ms by bot id=6681002925 +2024-02-12 22:57:10,185 - INFO - Update id=502700412 is handled. Duration 266 ms by bot id=6681002925 +2024-02-12 22:57:18,491 - INFO - Update id=502700413 is handled. Duration 125 ms by bot id=6681002925 +2024-02-12 22:57:19,646 - INFO - Update id=502700414 is handled. Duration 93 ms by bot id=6681002925 +2024-02-12 22:57:21,134 - INFO - Update id=502700415 is handled. Duration 250 ms by bot id=6681002925 diff --git a/app/__init__.py b/app/__init__.py index 1f5b0a2..a105cc2 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1 +1 @@ -from app import general_hd +from app import general_hd, upload_account2 diff --git a/app/__pycache__/__init__.cpython-312.pyc b/app/__pycache__/__init__.cpython-312.pyc index cf4fbe4..512abeb 100644 Binary files a/app/__pycache__/__init__.cpython-312.pyc and b/app/__pycache__/__init__.cpython-312.pyc differ diff --git a/app/__pycache__/general_hd.cpython-312.pyc b/app/__pycache__/general_hd.cpython-312.pyc index c6fc953..5900cfa 100644 Binary files a/app/__pycache__/general_hd.cpython-312.pyc and b/app/__pycache__/general_hd.cpython-312.pyc differ diff --git a/app/__pycache__/upload_account.cpython-312.pyc b/app/__pycache__/upload_account.cpython-312.pyc index 5060025..1f79270 100644 Binary files a/app/__pycache__/upload_account.cpython-312.pyc and b/app/__pycache__/upload_account.cpython-312.pyc differ diff --git a/app/__pycache__/upload_account2.cpython-312.pyc b/app/__pycache__/upload_account2.cpython-312.pyc index 6cda4d0..e9f8913 100644 Binary files a/app/__pycache__/upload_account2.cpython-312.pyc and b/app/__pycache__/upload_account2.cpython-312.pyc differ diff --git a/app/general_hd.py b/app/general_hd.py index c0c3339..51be301 100644 --- a/app/general_hd.py +++ b/app/general_hd.py @@ -17,10 +17,6 @@ - - - - @router.callback_query(Menu_callback.filter(F.menu == 'menu')) async def menu(call: CallbackQuery, callback_data: Menu_callback, state: FSMContext): try: diff --git a/app/posting/__pycache__/spam.cpython-312.pyc b/app/posting/__pycache__/spam.cpython-312.pyc index 7c98266..1fa5c09 100644 Binary files a/app/posting/__pycache__/spam.cpython-312.pyc and b/app/posting/__pycache__/spam.cpython-312.pyc differ diff --git a/app/posting/spam.py b/app/posting/spam.py index bb47d52..3171e26 100644 --- a/app/posting/spam.py +++ b/app/posting/spam.py @@ -6,7 +6,8 @@ from data import users, chats -from config import API_ID, API_HASH, PROXY, API_TOKEN +from config import API_ID, API_HASH, API_TOKEN +from app.upload_account2 import get_random_proxy async def join_and_send_message(client, link, text, user_id, account): try: @@ -27,9 +28,11 @@ async def join_and_send_message(client, link, text, user_id, account): if status == '🟒': await send(error=f'Π‘ΠΏΠ°ΠΌΠ±Π»ΠΎΠΊ: {account}', user_id=user_id) return + except UnboundLocalError as e: + pass except Exception as e: if status == '🟒': - await send(error=f'Ошибка ΠΏΡ€ΠΈ вступлСнии Π² Ρ‡Π°Ρ‚: {account}', user_id=user_id) + await send(error=f'Ошибка ΠΏΡ€ΠΈ вступлСнии Π² Ρ‡Π°Ρ‚: {e} \n\n {account}:{link}', user_id=user_id) return amount = send_messages + 1 @@ -44,12 +47,36 @@ async def join_and_send_message(client, link, text, user_id, account): try: await client.send_message(chat.id, text) + except errors.FloodWait as e: if status == '🟒': await send(error=f'Π‘ΠΏΠ°ΠΌΠ±Π»ΠΎΠΊ: {account}', user_id=user_id) return + except UnboundLocalError as e: pass + + except errors.SlowmodeWait as e: + if status == '🟒': + await send(error=f'SLOW_MODE: \n\n {account}:{link}', user_id=user_id) + return + + except errors.UserBannedInChannel as e: + if status == '🟒': + await send(error=f'USER_BANNED_IN_CHANNEL: \n\n {account}:{link}', user_id=user_id) + chats_link = await chats.get_chats(account) + chats_link.remove(link) + await chats.update_account_chats(account, chats_link) + return + + except errors.PeerIdInvalid as e: + if status == '🟒': + await send(error=f'НСвозмоТно Π²ΡΡ‚ΡƒΠΏΠΈΡ‚ΡŒ Π² Ρ‡Π°Ρ‚: \n\n {account}:{link}', user_id=user_id) + chats_link = await chats.get_chats(account) + chats_link.remove(link) + await chats.update_account_chats(account, chats_link) + return + except Exception as e: if status == '🟒': await send(error=f'Ошибка ΠΏΡ€ΠΈ вступлСнии Π² Ρ‡Π°Ρ‚: {e} \n\n {account}:{link}', user_id=user_id) @@ -59,7 +86,7 @@ async def join_and_send_message(client, link, text, user_id, account): await users.update_messages(user_id, amount) print(f"Π‘ΠΎΠΎΠ±Ρ‰Π΅Π½ΠΈΠ΅ ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½ΠΎ Π² Ρ‡Π°Ρ‚ {link}") except Exception as e: - print(f'Ошибка ΠΏΡ€ΠΈ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠ΅ сообщСния Π² Ρ‡Π°Ρ‚ {link}: {e}') + print(f'Ошибка ΠΏΡ€ΠΈ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠ΅ сообщСния Π² Ρ‡Π°Ρ‚ {link} Π½Π° Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π΅ {account}\n\n Ошибка:{e}') @@ -101,7 +128,8 @@ async def spamming(client, user_id, text, account): async def main(account_file, user_id, text, account): status = (await users.user_profile(user_id))[8] try: - async with Client(account_file, API_ID, API_HASH, proxy=PROXY) as client: + proxy = get_random_proxy() + async with Client(account_file, API_ID, API_HASH, proxy=proxy) as client: await spamming(client, user_id, text, account) except errors.Unauthorized as e: diff --git a/app/upload_account2.py b/app/upload_account2.py index 0bb065d..4f6b666 100644 --- a/app/upload_account2.py +++ b/app/upload_account2.py @@ -1,4 +1,4 @@ -import os +import os, random from aiogram import Router, F from aiogram.types import Message, CallbackQuery @@ -6,8 +6,8 @@ from aiogram.fsm.context import FSMContext from keyboards.client import Menu_callback, k_work_menu, cancel_upl, k_menu -from data import chats, users -from config import API_ID, API_HASH, PROXY +from data import chats, users, admin +from config import API_ID, API_HASH from pyrogram import Client, filters from pyrogram.errors import ( @@ -31,6 +31,32 @@ class Acc(StatesGroup): + + +def get_random_proxy(): + proxies = admin.get_proxies() + if proxies: + proxy = random.choice(proxies) + parts = proxy.split("@") + login_pass = parts[0].split(":") + login = login_pass[0] + password = login_pass[1] if len(login_pass) > 1 else "" + ip_port = parts[1].split(":") + ip = ":".join(ip_port[:-1]) + port = ip_port[-1] + + PROXY = { + "scheme": "socks5", + "hostname": ip, + "port": int(port), + "username": login, + "password": password + } + + return PROXY + + + @router.callback_query(Menu_callback.filter(F.menu == 'upl_acc_method_2')) async def update_account(call: CallbackQuery, callback_data: Menu_callback, state: FSMContext): await state.set_state(Acc.number) @@ -51,7 +77,8 @@ async def set_number(message: Message, state: FSMContext): path = f"app/posting/{user_id}/{filename[:-8]}" print('path', path) - client = Client(path, API_ID, API_HASH) + proxy = get_random_proxy() + client = Client(path, API_ID, API_HASH, proxy=proxy) await client.connect() try: code = await client.send_code(phone_number) diff --git a/app/work_menu/__pycache__/menu_wk.cpython-312.pyc b/app/work_menu/__pycache__/menu_wk.cpython-312.pyc index 9b3816a..fc0fd19 100644 Binary files a/app/work_menu/__pycache__/menu_wk.cpython-312.pyc and b/app/work_menu/__pycache__/menu_wk.cpython-312.pyc differ diff --git a/config.py b/config.py index 19afcb2..2ce285b 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,4 @@ from aiogram import Bot -from data.admin import get_proxy API_TOKEN = '6708966085:AAH8DAOulSOhLHjn6rlL40_MZjcAKekWs9g' @@ -13,26 +12,4 @@ API_HASH = '7033098f253c5266cc2311fc9a09fab9' -def parse_proxy_string(): - proxy_string = get_proxy() - parts = proxy_string.split("@") - login_pass = parts[0].split(":") - login = login_pass[0] - password = login_pass[1] if len(login_pass) > 1 else "" - ip_port = parts[1].split(":") - ip = ":".join(ip_port[:-1]) - port = ip_port[-1] - - return (login, password, ip, port) - -proxy = parse_proxy_string() - -PROXY = { - "scheme": "socks5", - "hostname": proxy[2], - "port": int(proxy[3]), - "username": proxy[0], - "password": proxy[1] -} - -bot = Bot(token=API_TOKEN, parse_mode='HTML') \ No newline at end of file +bot = Bot(token=API_TOKEN, parse_mode='HTML') diff --git a/data/__pycache__/admin.cpython-312.pyc b/data/__pycache__/admin.cpython-312.pyc index 915143f..41d5d52 100644 Binary files a/data/__pycache__/admin.cpython-312.pyc and b/data/__pycache__/admin.cpython-312.pyc differ diff --git a/data/__pycache__/chats.cpython-312.pyc b/data/__pycache__/chats.cpython-312.pyc index 7532cf2..0144ed1 100644 Binary files a/data/__pycache__/chats.cpython-312.pyc and b/data/__pycache__/chats.cpython-312.pyc differ diff --git a/data/admin.py b/data/admin.py index adac330..fc77e54 100644 --- a/data/admin.py +++ b/data/admin.py @@ -65,39 +65,52 @@ def add_proxy(proxy): print("Π‘ΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅ с SQLite Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΎ") -def get_proxy(): +def update_proxy(proxy): try: - sqlite_connection = sqlite3.connect('data/base/base.db') + sqlite_connection = sqlite3.connect("data/base/base.db") cursor = sqlite_connection.cursor() - sqlite_selection_query = "SELECT proxy FROM proxies;" - cursor.execute(sqlite_selection_query) - count = cursor.fetchone()[0] - - cursor.close() - return count + sqlite_selection_query = "UPDATE proxies SET proxy=? WHERE id=1;" + cursor.execute(sqlite_selection_query, (proxy,)) + sqlite_connection.commit() except sqlite3.Error as error: - print("Ошибка ΠΏΡ€ΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΈ ΠΊ SQLite", error) - return None - + print("НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π΄Π°Π½Π½Ρ‹Π΅ ΠΈΠ· Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹.", error) finally: if sqlite_connection: sqlite_connection.close() - print("Π‘ΠΎΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΠ΅ с SQLite Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΎ") -def update_proxy(proxy): - try: - sqlite_connection = sqlite3.connect("data/base/base.db") - cursor = sqlite_connection.cursor() - sqlite_selection_query = "UPDATE proxies SET proxy=? WHERE id=1;" - cursor.execute(sqlite_selection_query, (proxy,)) - sqlite_connection.commit() +def get_proxies(): + proxies = [] + + try: + connection = sqlite3.connect('data/base/base.db') + cursor = connection.cursor() + cursor.execute("SELECT proxy FROM proxies WHERE id=1;") + rows = cursor.fetchall() # ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ всС строки + for row in rows: + for proxy in row[0].split('\n'): + proxy = proxy.strip() + if proxy: + proxies.append(proxy) except sqlite3.Error as error: - print("НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π΄Π°Π½Π½Ρ‹Π΅ ΠΈΠ· Ρ‚Π°Π±Π»ΠΈΡ†Ρ‹.", error) + print("НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ прокси-сСрвСры ΠΈΠ· Π±Π°Π·Ρ‹ Π΄Π°Π½Π½Ρ‹Ρ….", error) + finally: - if sqlite_connection: - sqlite_connection.close() \ No newline at end of file + if connection: + try: + connection.close() + except sqlite3.Error as close_error: + print("Ошибка ΠΏΡ€ΠΈ Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΈΠΈ соСдинСния с Π±Π°Π·ΠΎΠΉ Π΄Π°Π½Π½Ρ‹Ρ….", close_error) + return proxies + +# pro = '''K3aT1rGA:SHCTiUED@166.1.143.161:64019 +# K3aT1rGA:SHCTiUED@166.1.145.76:63611 +# K3aT1rGA:SHCTiUED@166.1.146.244:63169 +# K3aT1rGA:SHCTiUED@166.1.147.12:63915 +# K3aT1rGA:SHCTiUED@166.1.148.233:63359 ''' +# update_proxy(pro) +# print(get_proxies()) \ No newline at end of file diff --git a/data/base/base.db b/data/base/base.db index e918ad1..c04f51b 100644 Binary files a/data/base/base.db and b/data/base/base.db differ diff --git a/data/chats.py b/data/chats.py index 3e6e732..e90b3cf 100644 --- a/data/chats.py +++ b/data/chats.py @@ -50,6 +50,26 @@ async def add_account(max_id, user_id, account_name, chats): print("Ошибка ΠΏΡ€ΠΈ Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΈΠΈ соСдинСния.", close_error) +async def update_account_chats(account_name, new_chats): + db = None + + try: + db = await aiosqlite.connect('data/base/base.db') + serialized_chats = pickle.dumps(new_chats) + update_query = "UPDATE accounts SET chats = ? WHERE account_name = ?;" + await db.execute(update_query, (serialized_chats, account_name)) + await db.commit() + print(f"Бписок Ρ‡Π°Ρ‚ΠΎΠ² для Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° {account_name} ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½.") + + except aiosqlite.Error as error: + print("НС ΡƒΠ΄Π°Π»ΠΎΡΡŒ ΠΎΠ±Π½ΠΎΠ²ΠΈΡ‚ΡŒ список Ρ‡Π°Ρ‚ΠΎΠ².", error) + finally: + if db: + try: + await db.close() + except aiosqlite.Error as close_error: + print("Ошибка ΠΏΡ€ΠΈ Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΈΠΈ соСдинСния.", close_error) + async def get_chats(acc): db = await aiosqlite.connect('data/base/base.db') diff --git a/main.py b/main.py index c9edb32..26f2f01 100644 --- a/main.py +++ b/main.py @@ -9,9 +9,10 @@ from config import bot - - async def start(): + # Настройка Π»ΠΎΠ³Π³Π΅Ρ€Π° для записи Π² Ρ„Π°ΠΉΠ» + logging.basicConfig(filename='app.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + dp = Dispatcher() dp.include_routers( @@ -31,7 +32,6 @@ async def start(): upload_account2.router, ) - logging.basicConfig(level=logging.INFO) await bot.delete_webhook(drop_pending_updates=True) await dp.start_polling(bot)