Exemplo n.º 1
0
 def __init__(self, user_id, token) -> None:
     self.user_id = user_id
     self.token = token
     self.IDB = InternalDB()
     self.GPL_config_path = path.join(
         config.get('modules_path', 'source/modules/'), 'GPL',
         'config.json')
Exemplo n.º 2
0
 def __init__(self, user_id) -> None:
     self.vk = BotAPI()
     self.IDB = InternalDB()
     self.user_id = user_id
     self.user = self.IDB.get_user(user_id)
     self.module_location = path.join(
         config.get('modules_path', 'source/modules'), 'GPL')
     self.module_config_location = path.join(self.module_location,
                                             'config.json')
Exemplo n.º 3
0
    def init(user_id: int, message: str) -> None:
        vk = BotAPI()
        IDB = InternalDB()
        user = IDB.get_user(user_id)

        vk.message_send(message=message,
                        user_id=user_id,
                        type_t=user['current_mode'])
        IDB.messages_increment(user['user_id'])

        logging.info('"{}" message from {} was handled using method {}'.format(
            message, user['user_id'], user['current_mode']))
Exemplo n.º 4
0
    def exit() -> None:
        try:
            logging.warning('Script stopping in progress...')

            IDB = InternalDB()
            IDB.status_cleaner_emergency()

            vk = BotAPI()
            for admin in config.get('admins', []).split(','):
                vk.message_send(getMessage('script_stopped'), user_id=admin)

            vk.disable_online()
        except Exception as e:
            logging.fatal(str(e))
Exemplo n.º 5
0
def processing():
    IDB = InternalDB()
    try:
        data = json.loads(request.data)
        if 'type' not in data.keys():
            return 'not vk'
        if data['type'] == 'confirmation':
            return config.get('group_special_string', '')
        elif data['type'] == 'message_new':
            if data.get('secret') == config.get('secret_key'):
                payload = None
                if data['object'].get('payload'):
                    payload = json.loads(data['object']['payload'])['button']
                StaticData.stack_messages.append({
                    'message':
                    data['object']['text'],
                    'user_id':
                    data['object']['from_id'],
                    'payload':
                    payload
                })
                StaticData.new_message_trigger.set()
                return 'ok'
            else:
                raise BaseException
        elif data['type'] == 'access_implementing':
            access = {}
            vk = BotAPI()
            if 'access_token' in data['data']:
                data = re.sub(r'(http)?https?://.*[#]', '', data['data'])
                for i in data.split('&'):
                    access[i.split('=')[0]] = i.split('=')[1]

                if re.match(r'[a-z0-9]{85}', access['access_token']) and int(
                        access['user_id']):
                    IDB.update_token(user_id=int(access['user_id']),
                                     token=access['access_token'])
                    vk.message_send(getMessage('access_token_getting_success'),
                                    int(access['user_id']))
                    return 'ok', 200
            if access.get('user_id'):
                vk.message_send(getMessage('access_token_getting_exception'),
                                user_id=int(access['user_id']))
            return getMessage('WEB_smth_went_wrong'), 500

    except:
        return getMessage('WEB_not_json'), 418
Exemplo n.º 6
0
 def check(user_id: int) -> bool:
     vk = BotAPI()
     IDB = InternalDB()
     user = IDB.get_user(user_id)
     if not user['token']:
         vk.message_send(getMessage('no_access_token'),
                         user_id=user_id,
                         keyboard=getKeyboard('settings'))
         IDB.status_changer(user_id=user_id, status=None)
         return False
     elif not UserAPI.is_token_valid(user['token']):
         vk.message_send(getMessage('token_expired'),
                         user_id=user_id,
                         keyboard=getKeyboard('settings'))
         IDB.status_changer(user_id=user_id, status=None)
         return False
     return True
Exemplo n.º 7
0
    def run(self):
        logging.info('Messages handler started')
        while True:
            try:
                vk = BotAPI()
                IDB = InternalDB()
                StaticData.new_message_trigger.wait()
                StaticData.new_message_trigger.clear()

                data = StaticData.stack_messages.pop(0)

                user_id = data['user_id']
                message = data['message']
                payload = data['payload']

                logging.info(f'Got "{message}" from {user_id}')

                CH = CommandsHandler(user_id)
                if message:
                    if not IDB.user_exists(user_id):
                        IDB.add_user(user_id)
                        ServiceInterface.start(user_id)
                        continue

                    data = IDB.get_user(user_id)
                    if data['status']:
                        if payload == '/back':
                            IDB.status_changer(user_id=user_id, status=None)
                            CH.back_comma()
                            continue
                        logging.info('Module "{}" request from {}'.format(
                            data['status'], user_id))

                        del IDB

                        # GPL
                        if 'GPL' in data['status'] and payload == '/GPL_run':
                            CH.gpl_run_comma()
                        elif 'GPL' in data['status']:
                            CH.gpl_run_comma(message)
                        continue

                    if payload:
                        logging.info(
                            f'Command "{payload}" request from {user_id}')
                        CH.identify_comma(payload)
                        continue

                    if len(message) > 100:
                        vk.message_send(
                            getMessage('max_message_length_note').format(
                                length=str(len(message))),
                            user_id=user_id)

                    MessageHandler.init(user_id, message[:100])
                else:
                    logging.warning("Bad message from {}".format(user_id))
                    vk.message_send(message=getMessage('text_unset'),
                                    user_id=user_id)
            except KeyboardInterrupt:
                _exit(0)
Exemplo n.º 8
0
 def __init__(self, user_id) -> None:
     self.user_id = user_id
     self.vk = BotAPI()
     self.IDB = InternalDB()
     self.user = self.IDB.get_user(self.user_id)
Exemplo n.º 9
0
from core import *

from source.other.ExitHandler import ExitHandler

# Exit routine
logging.info('Exit routine registered')
ExitHandler.register()

# Create DB TODO: Probably bad way. REFACTOR
from source.databases.InternalDB import InternalDB

InternalDB().create()

from source.modules.ModulesController import ModulesController

# Full-time work modules
ModulesController.full_time_modules_init()

# Main routine
logging.info('Initialization started')

from source.main.Main import Main
from source.vkapi.AlwaysOnline import AlwaysOnline

# Main Messages Handler
Main().start()

# Always Online
AlwaysOnline().start()

# Messages GET - Module routine initialization
Exemplo n.º 10
0
 def __init__(self, user_id: int) -> None:
     self.user_id = user_id
     self.vk = BotAPI()
     self.IDB = InternalDB()