+ Add create acc thread
This commit is contained in:
parent
297186ae8a
commit
412c2f2736
@ -41,6 +41,12 @@ class CM_BOT_HAL:
|
||||
result = self.db.query(query, query_params)
|
||||
return result[0] if len(result) else None
|
||||
|
||||
def get_all_available_acc(self):
|
||||
query = "SELECT username, password, link FROM acc WHERE status = %s ORDER BY username ASC"
|
||||
query_params = ['']
|
||||
result = self.db.query(query, query_params)
|
||||
return result
|
||||
|
||||
def get_max_username(self, prefix: str):
|
||||
query = "SELECT username FROM acc WHERE username LIKE %s ORDER BY username DESC LIMIT 1"
|
||||
query_params = [f'{prefix}%']
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import logging
|
||||
import threading, logging, time
|
||||
|
||||
from telegram import ForceReply, Update
|
||||
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters
|
||||
@ -12,6 +12,8 @@ logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
creating_acc_now = False
|
||||
|
||||
async def menu_cmd_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
menu = [
|
||||
'MENU',
|
||||
@ -22,6 +24,10 @@ async def menu_cmd_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -
|
||||
await update.message.reply_text('\n'.join(menu))
|
||||
|
||||
async def get_acc_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
while creating_acc_now == True:
|
||||
await update.message.reply_text('CM account creation is running, queuing ...')
|
||||
time.sleep(60)
|
||||
creating_acc_now = True
|
||||
await update.message.reply_text('Start Getting CM Account ...')
|
||||
try:
|
||||
bot = CM_BOT_HAL()
|
||||
@ -34,6 +40,8 @@ async def get_acc_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
|
||||
await update.message.reply_text('\n'.join(msg))
|
||||
except Exception as e:
|
||||
await update.message.reply_text(f'Error: {e}')
|
||||
finally:
|
||||
creating_acc_now = False
|
||||
|
||||
async def set_security_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
if len(context.args) == 0 or len(context.args) > 1:
|
||||
@ -67,6 +75,20 @@ async def insert_to_user_table_handler(update: Update, context: ContextTypes.DEF
|
||||
)
|
||||
await update.message.reply_text(f'Done insert {f_username} into user table.')
|
||||
|
||||
def monitor_amount_of_available_acc():
|
||||
max_available = 20
|
||||
while True:
|
||||
bot = CM_BOT_HAL()
|
||||
available_size = len(bot.get_all_available_acc())
|
||||
print(available_size)
|
||||
|
||||
if available_size <= max_available:
|
||||
for i in range(available_size, max_available):
|
||||
bot.create_new_acc()
|
||||
time.sleep(10 * 60)
|
||||
del bot
|
||||
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Start the bot."""
|
||||
@ -80,6 +102,7 @@ def main() -> None:
|
||||
|
||||
# Start the Telegram bot
|
||||
print("Starting Telegram bot...")
|
||||
threading.Thread(target=monitor_amount_of_available_acc, args=()).start()
|
||||
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user