Esempio n. 1
0
def gitfetch(path):
    os.chdir(path)
    os.system("git remote add instabotgit https://github.com/kirillovmr/instabotgit")
    os.system("git fetch instabotgit master")
    os.system("git reset --hard FETCH_HEAD")
    os.system("git clean -df")
    print("\n{} Last version received.\n".format(now_time()))
    my_telegram.send_mess_tg(my_database.get_admin_tg(), "📡 Bot was updated")
Esempio n. 2
0
def stop(id, script, r=False, tg_notify=True):
    needRemove = True
    try:
        procs[id][script].kill()
    except KeyError:
        needRemove = False
    if not r:
        print("{} {}{} stopped (r)".format(now_time(), id, scripttonum(script)))
        if tg_notify:
            my_telegram.send_mess_tg(my_database.get_chat_ids_tg(id), "{} @{} bot stopped by request".format(scripttosmile(script.lower()), my_database.get_username_from_id(id)))
    if needRemove:
        running.remove(id * 10 + scripttonum(script))
Esempio n. 3
0
def checkrun():
    for num in running:
        id = removelastdigit(num)
        script = numtoscript(lastdigit(num))
        poll = procs[id][script].poll()
        if poll != None:
            running.remove(num)
            if poll == 10:
                text = "{} {}{} finished cycle".format(now_time(), id, scripttonum(script))
                print(text)
                start(id, script, tg_notify=False)
            elif poll == 11:
                text = "{} {}{} unfollowed everyone. Stopped.".format(now_time(), id, scripttonum(script))
                print(text)
                my_telegram.send_mess_tg(my_database.get_chat_ids_tg(id), "👤 {} bot finished unfollowing. Bot stopped".format(my_database.get_username_from_id(id)))
                my_database.update_db("follow_s", 0, id)
            elif poll == 12:
                try:
                    feedback_required[id]['count'] += 1
                    feedback_required[id]['last_time'] = time.time()
                    feedback_error_count = feedback_required[id]['count']
                    if feedback_error_count == 5 or feedback_error_count % 10 == 0:
                        # Telegram inline keyboard
                        inline_button1 = { "text": 'Stop {s} bot'.format(s=script), "callback_data": '/stop {} {}'.format(my_database.get_username_from_id(id), script) }
                        inline_keyboard = [[inline_button1]]
                        keyboard = { "inline_keyboard": inline_keyboard }
                        markup = json.JSONEncoder().encode(keyboard)

                        my_telegram.send_mess_tg(my_database.get_chat_ids_tg(id), "‼️ @{} {} bot returned 'feedback_required' {} times.".format(my_database.get_username_from_id(id), script, feedback_error_count), replyMarkup=markup)
                except KeyError:
                    feedback_required[id] = {}
                    feedback_required[id]['count'] = 1
                    feedback_required[id]['last_time'] = time.time()
                text = "Bot {}-'{}' returned 'feedback_required'. Restarting.".format(id, script.upper())
                print(now_time() + " " + text)
                start(id, script, tg_notify=False)
                # my_database.update_db("{}_s".format(script.lower()), 0, id)
                # running.remove(id * 10 + scripttonum(script))
            else:
                text = "{} Bot {}-'{}' was closed. Trying to restart...".format(now_time(), id, script.upper())
                print(text)
                # my_telegram.send_mess_tg(my_database.get_chat_ids_tg(id), text)
                start(id, script, restart_error=True)
Esempio n. 4
0
def check_commands():
    # Executing query
    q = ("SELECT * FROM server WHERE os='{}'".format(platform.lower()))
    db['cursor'].execute(q)

    # Going through status and start/stop appropriate bots
    commands = db['cursor']
    for command in commands:
        if command['restart'] == 1:
            print("MANAGER RESTARTING (r)")
            update_command_db('restart', 0, platform.lower())
            exit(99)
        if command['update1'] == 1:
            print("UPDATING BOT (r)")
            update_command_db('update1', 0, platform.lower())
            my_func.gitfetch(my_func.path())
            time.sleep(5)
        if command['server_restart'] == 1:
            print("RESTARTING SERVER (r)")
            update_command_db('server_restart', 0, platform.lower())
            my_telegram.send_mess_tg(get_admin_tg(), "⚠️ SERVER going to restart")
            os.system('reboot')
Esempio n. 5
0
def start(id, script, restart_manual=False, restart_error=False, tg_notify=True):
    # Making array 2d only once
    try:
        type(procs[id])
    except KeyError:
        procs[id] = dict() # making it 2d

    procs[id][script] = Popen(script_path(script, id), shell=True, stdout=openlog(id, script), stderr=PIPE)
    # procs[id][script] = call(script_path(script, id), shell=True)
    if procs[id][script].poll() == None:
        print("{} {}{} started: {}".format(now_time(), id, scripttonum(script), procs[id][script].pid))
        if tg_notify:
            if restart_manual:
                my_telegram.send_mess_tg(my_database.get_chat_ids_tg(id), "{} @{} bot was restarted by request".format(scripttosmile(script.lower()), my_database.get_username_from_id(id)))
            elif restart_error:
                my_telegram.send_mess_tg(my_database.get_chat_ids_tg(id), "{} @{} bot was restarted after error".format(scripttosmile(script.lower()), my_database.get_username_from_id(id)))
            else:
                my_telegram.send_mess_tg(my_database.get_chat_ids_tg(id), "{} @{} bot was started".format(scripttosmile(script.lower()), my_database.get_username_from_id(id)))
        running.append(id * 10 + scripttonum(script))
Esempio n. 6
0
import my_database
import my_telegram
import my_func
import time

my_telegram.send_mess_tg(my_database.get_admin_tg(),
                         "✅ Manager started on {}".format(my_func.platform()))

my_func.gitfetch(my_func.path())

not_notify = my_database.fill_not_notify_array()

# Set all actual values to 0 in database.
my_database.set_actual_zero()

while True:

    my_database.check_commands()

    # Get statuses from database and start/stop bots
    my_database.get_bots_status(not_notify=not_notify)

    # Check running scripts. If closed - trying to restart
    my_func.checkrun()

    # Print running scripts
    my_func.print_running_array()
    if len(not_notify):
        print("--/--/-- N notif: {}".format(not_notify))

    # Clears a feedback_required array if needed. Used to
Esempio n. 7
0
import my_telegram
import my_database
import json

my_telegram.send_mess_tg(my_database.get_admin_tg(), "✅ MANAGER STARTED")