# Path: utils/config_file.py
# CONF_FILE  = 'config/hcbpy.conf'
# def touch(fname, times=None):
#     def __init__(self, key, val, comment):
# def get_all_data(filename=CONF_FILE):
# def get_field(field_name, filename=CONF_FILE):
# def init_field(key, val="none", filename=CONF_FILE):
# def has(field_name, filename=CONF_FILE):
# def get_lines(filename):
# def get_comment(field_name, filename=CONF_FILE):
# def set_field(field_name, value, filename=CONF_FILE):
# class ConfigEntry:
# 
# Path: vk_api/api.py
# 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/api.py
# class Message:
# 
#     class MessageAttachment:
#         attachment_value = None
#         attachment_type = None
# 
#         def __init__(self, type, value):
#             self.attachment_type = type
#             self.attachment_value = value
# 
#     mid = None # ID of message
#     flag = None # message flags (See VK Long pool docs)
#     pid = None # peer id (Sender id)
#     ts = None # timestamp
#     sub = None # subject of message (if private dialog - " ... ", if chat - chat title)
#     body = None # test of message
#     extra = None # extra fields (forwarded messages, etc)
#     attachments = None
# 
#     # get specific message flag (See VK Long pool docs)
#     def msgFlag(self, i, f):
#         return (f & i) > 0
# 
#     # check is message not incoming
#     def is_out(self):
#         return self.msgFlag(self.flag, 2)
# 
#     def is_loopback(self, account=None):
#         if account is None:
#             account = bot_header.CURRENT_ACCOUNT
#         return  self.pid == account.user_id
# 
#     # check is message sent from chat
#     def is_chat(self):
#         return self.pid >= 2000000000
# 
#     # init
#     def __init__(self, mid=None, flag=None, pid=None, ts=None, sub=None, body=None, extra=None):
#         self.mid = mid
#         self.flag = flag
#         self.pid = pid
#         self.ts = ts
#         self.sub = sub
#         self.body = body
#         self.extra = extra
#         if extra is not None:
#             self.attachments = self.parse_attachments()
# 
#     # get message from long pool response
#     def from_long_pool(self, resp):
#         mid = resp[1]
#         flag = resp[2]
#         pid = resp[3]
#         ts = resp[4]
#         sub = resp[5]
#         body = resp[6]
#         extra = resp[7]
#         return Message(mid=mid, flag=flag, pid=pid, ts=ts, sub=sub, body=body, extra=extra)
# 
#     def parse_attachments(self):
#         # print(self.extra)
#         # initialize empty list
#         result = []
# 
#         # checking for attachments
#         if not "attach1_type" in self.extra:
#             return result
# 
#         # if message has attachs, start parsing
#         # parse attachment
#         i = 1
#         print("id: %s" % i)
#         # get attach by number
#         while "attach%s_type" % i in self.extra:
#             attach_type = self.extra["attach%s_type" % str(i)]
#             attach_val = self.extra["attach%s" % str(i)]
#             if attach_type == "doc":
#                 if "attach%s_kind" % str(i):
#                     if self.extra["attach%s_kind" % str(i)] == "audiomsg":
#                         attach_type = "amessage"
#             print("Got id %s with data %s" % (attach_type, attach_val))
#             result.append(Message.MessageAttachment(attach_type, attach_val))
#             i+=1
#         return result
# 
# 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']
# 
# Path: vk_api/api.py
# def vapi(method, params=''):
#     return api_request(get_api(account=bot_header.CURRENT_ACCOUNT), method, params)


import inspect
import os
import random
import sys
import mpm_manager
import bot_header
from time import sleep
from utils import config_file
from vk_api.api import get_api
from vk_api.api import Message
from vk_api.api import api_request
from vk_api.api import vapi
    else:
        bot_header.LP_MESSAGES_SENT += 1

    # Printing message to std out
    if message.is_loopback():
        sep = "<->"
    elif message.is_out():
        sep = "->"
    else:
        sep = "<-"

    fpid = False
    fpid = config_file.get_field(FORMAT_PID_STR) != "0"

    if fpid:
        u = vapi("users.get", "user_ids=%s" % message.pid)[0]
        lp_thread_ins.print("%s [%s]: %s" % (sep, "%s %s" % (u["first_name"], u["last_name"]), message.body))
    else:
        lp_thread_ins.print("%s [%s]: %s" % (sep, str(message.pid), message.body))

    #

    response_to_user = on_message_received(message, lp_thread_ins)
    if response_to_user is not None:
        send_response(lp_thread_ins, message, response_to_user)


def send_response(lp_thread_ins, message, response_to_user):
    # send response to vk_api user
    # getting api instance

# Path: utils/config_file.py
# CONF_FILE  = 'config/hcbpy.conf'
# def touch(fname, times=None):
#     def __init__(self, key, val, comment):
# def get_all_data(filename=CONF_FILE):
# def get_field(field_name, filename=CONF_FILE):
# def init_field(key, val="none", filename=CONF_FILE):
# def has(field_name, filename=CONF_FILE):
# def get_lines(filename):
# def get_comment(field_name, filename=CONF_FILE):
# def set_field(field_name, value, filename=CONF_FILE):
# class ConfigEntry:
# 
# Path: vk_api/api.py
# 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/api.py
# class Message:
# 
#     class MessageAttachment:
#         attachment_value = None
#         attachment_type = None
# 
#         def __init__(self, type, value):
#             self.attachment_type = type
#             self.attachment_value = value
# 
#     mid = None # ID of message
#     flag = None # message flags (See VK Long pool docs)
#     pid = None # peer id (Sender id)
#     ts = None # timestamp
#     sub = None # subject of message (if private dialog - " ... ", if chat - chat title)
#     body = None # test of message
#     extra = None # extra fields (forwarded messages, etc)
#     attachments = None
# 
#     # get specific message flag (See VK Long pool docs)
#     def msgFlag(self, i, f):
#         return (f & i) > 0
# 
#     # check is message not incoming
#     def is_out(self):
#         return self.msgFlag(self.flag, 2)
# 
#     def is_loopback(self, account=None):
#         if account is None:
#             account = bot_header.CURRENT_ACCOUNT
#         return  self.pid == account.user_id
# 
#     # check is message sent from chat
#     def is_chat(self):
#         return self.pid >= 2000000000
# 
#     # init
#     def __init__(self, mid=None, flag=None, pid=None, ts=None, sub=None, body=None, extra=None):
#         self.mid = mid
#         self.flag = flag
#         self.pid = pid
#         self.ts = ts
#         self.sub = sub
#         self.body = body
#         self.extra = extra
#         if extra is not None:
#             self.attachments = self.parse_attachments()
# 
#     # get message from long pool response
#     def from_long_pool(self, resp):
#         mid = resp[1]
#         flag = resp[2]
#         pid = resp[3]
#         ts = resp[4]
#         sub = resp[5]
#         body = resp[6]
#         extra = resp[7]
#         return Message(mid=mid, flag=flag, pid=pid, ts=ts, sub=sub, body=body, extra=extra)
# 
#     def parse_attachments(self):
#         # print(self.extra)
#         # initialize empty list
#         result = []
# 
#         # checking for attachments
#         if not "attach1_type" in self.extra:
#             return result
# 
#         # if message has attachs, start parsing
#         # parse attachment
#         i = 1
#         print("id: %s" % i)
#         # get attach by number
#         while "attach%s_type" % i in self.extra:
#             attach_type = self.extra["attach%s_type" % str(i)]
#             attach_val = self.extra["attach%s" % str(i)]
#             if attach_type == "doc":
#                 if "attach%s_kind" % str(i):
#                     if self.extra["attach%s_kind" % str(i)] == "audiomsg":
#                         attach_type = "amessage"
#             print("Got id %s with data %s" % (attach_type, attach_val))
#             result.append(Message.MessageAttachment(attach_type, attach_val))
#             i+=1
#         return result
# 
# 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']
# 
# Path: vk_api/api.py
# def vapi(method, params=''):
#     return api_request(get_api(account=bot_header.CURRENT_ACCOUNT), method, params)


# Path: long_pool_events/module_message_send.py
import inspect
import os
import random
import sys
import mpm_manager
import bot_header
from time import sleep
from utils import config_file
from vk_api.api import get_api
from vk_api.api import Message
from vk_api.api import api_request
from vk_api.api import vapi

    else:
        bot_header.LP_MESSAGES_SENT += 1

    # Printing message to std out
    if message.is_loopback():
        sep = "<->"
    elif message.is_out():
        sep = "->"
    else:
        sep = "<-"

    fpid = False
    fpid = config_file.get_field(FORMAT_PID_STR) != "0"

    if fpid:
        u = vapi("users.get", "user_ids=%s" % message.pid)[0]
        lp_thread_ins.print("%s [%s]: %s" % (sep, "%s %s" % (u["first_name"], u["last_name"]), message.body))
    else:
        lp_thread_ins.print("%s [%s]: %s" % (sep, str(message.pid), message.body))

    #

    response_to_user = on_message_received(message, lp_thread_ins)
    if response_to_user is not None:
        send_response(lp_thread_ins, message, response_to_user)


def send_response(lp_thread_ins, message, response_to_user):
    # send response to vk_api user
    # getting api instance

    api = get_api(lpt=lp_thread_ins)