# Path: vk_api/api.py
# def api_request(api, method, params=''):
#     ret = dict(api=api, ret = None)
#     if params:
#         a = "ret = api.%s(v='5.62', %s)" % (method, params)
#     else:
#         a = "ret = api.%s(v='5.62')" % (method)
# 
#     exec(a, ret)
# 
#     if 'error' in str(ret['ret']):
#         bot_header.API_REQUESTS += 1
#     else:
#         bot_header.FAILED_API_REQUESTS += 1
# 
# 
#     return ret['ret']
# 
# def get_api(lpt = None, account=None):
#     if lpt == None and account == None:
#         raise AttributeError("longpool thread or account is required")
#     if lpt is not None:
#         account = lpt.account
# 
#     return vk.API(vk.Session(access_token=account.token))


import threading
import bot_header
from time import sleep
from vk_api.api import api_request, get_api
class OnlineThread(threading.Thread):
    account = None
    enabled = True
    interval = 20

    def __init__(self, lpt=None, account=None, enabled=True, interval=30):
        super().__init__()

        if lpt == None and account == None:
            raise AttributeError("longpool thread or account is required")
        if lpt is not None:
            self.account = lpt.account
        elif account is not None:
            self.account = account
        self.enabled = enabled
        self.interval = interval


    def print(self, text):
        print('[::OTHD] [%s] %s' % (self.account.first_last(), text))

    def v(self, text):
        bot_header.v('[::OTHD] [%s] %s' % (self.account.first_last(), text))

    def w(self, text):
        bot_header.w('[::OTHD] [%s] %s' % (self.account.first_last(), text))

    def set_online(self, online):
        if online:
            method = "account.setOnline"

# Path: vk_api/api.py
# def api_request(api, method, params=''):
#     ret = dict(api=api, ret = None)
#     if params:
#         a = "ret = api.%s(v='5.62', %s)" % (method, params)
#     else:
#         a = "ret = api.%s(v='5.62')" % (method)
# 
#     exec(a, ret)
# 
#     if 'error' in str(ret['ret']):
#         bot_header.API_REQUESTS += 1
#     else:
#         bot_header.FAILED_API_REQUESTS += 1
# 
# 
#     return ret['ret']
# 
# def get_api(lpt = None, account=None):
#     if lpt == None and account == None:
#         raise AttributeError("longpool thread or account is required")
#     if lpt is not None:
#         account = lpt.account
# 
#     return vk.API(vk.Session(access_token=account.token))


# Path: vk_api/set_online.py
import threading
import bot_header
from time import sleep
from vk_api.api import api_request, get_api

class OnlineThread(threading.Thread):
    account = None
    enabled = True
    interval = 20

    def __init__(self, lpt=None, account=None, enabled=True, interval=30):
        super().__init__()

        if lpt == None and account == None:
            raise AttributeError("longpool thread or account is required")
        if lpt is not None:
            self.account = lpt.account
        elif account is not None:
            self.account = account
        self.enabled = enabled
        self.interval = interval


    def print(self, text):
        print('[::OTHD] [%s] %s' % (self.account.first_last(), text))

    def v(self, text):
        bot_header.v('[::OTHD] [%s] %s' % (self.account.first_last(), text))

    def w(self, text):
        bot_header.w('[::OTHD] [%s] %s' % (self.account.first_last(), text))

    def set_online(self, online):
        if online:
            method = "account.setOnline"

            response = api_request(get_api(account=self.account), method, "voip=0")