Exemplo n.º 1
0
class SettingsInterface:

    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)

    def preview(self):
        if not self.user['token'] or not UserAPI.is_token_valid(self.user['token']):
            token = '⛔'
            self.IDB.update_token(self.user_id, '')
        else:
            token = '✅'
        self.vk.message_send(getMessage('settings_welcome').format(token=token, sub=self.user["subtype"]), self.user_id,
                             getKeyboard('settings'))

    def about(self) -> None:
        from source.static.StaticData import StaticData
        self.vk.message_send(
            getMessage('about_welcome').format(version=StaticData.version),
            self.user_id)

    def access_token(self) -> None:
        self.vk.message_send(
            getMessage('access_token_welcome').format(access_getter_url=config.get('access_getter_url', 'INVALID')),
            self.user_id, JSONWorker.keyboard_handler('default'))
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
0
class GPLInterface:
    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')

    def preview(self):
        self.vk.message_send(getMessage('gpl_description',
                                        location=self.module_config_location),
                             user_id=self.user_id,
                             keyboard=getKeyboard('gpl'))

    def run(self, victim_id, user_id) -> None:
        if not AccessToken.check(user_id):
            return

        if not victim_id:
            self.vk.message_send(getMessage(
                'gpl_give_me_link', location=self.module_config_location),
                                 user_id=user_id)
            self.IDB.status_changer(user_id=user_id, status="GPL_P_G")
            return

        victim_id = UserAPI.get_id_from_url(self.user['token'], victim_id)

        if victim_id == "BadID":
            self.vk.message_send(getMessage(
                'gpl_incorrect_link', location=self.module_config_location),
                                 user_id=user_id,
                                 keyboard=JSONWorker.keyboard_handler('gpl'))
            self.IDB.status_changer(user_id=user_id, status=None)
            return

        elif not UserAPI.user_exists(user_id=user_id,
                                     token=self.user['token']):
            self.vk.message_send(getMessage(
                'gpl_invalid_account', location=self.module_config_location),
                                 user_id=user_id,
                                 keyboard=JSONWorker.keyboard_handler('gpl'))
            self.IDB.status_changer(user_id=user_id, status=None)
            return

        elif UserAPI.user_broken(self.user['token'], victim_id):
            self.vk.message_send(getMessage(
                'gpl_closed_account', location=self.module_config_location),
                                 user_id=user_id,
                                 keyboard=JSONWorker.keyboard_handler('gpl'))
            self.IDB.status_changer(user_id=user_id, status=None)
            return

        MC = ModulesController(user_id, self.user['token'])
        thread = Thread(target=MC.gpl_execute, args=(victim_id, ))
        thread.start()
Exemplo n.º 6
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.º 7
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.º 8
0
class ChangeTextModeInterface:
    def __init__(self, user_id: int) -> None:
        self.user_id = user_id
        self.vk = BotAPI()
        self.IDB = InternalDB()

    def preview(self) -> None:
        self.vk.message_send(
            getMessage('current_mode').format(
                mode=self.IDB.get_user(self.user_id)["current_mode"]),
            self.user_id, getKeyboard('4way'))

    def change(self, mode: str) -> None:
        self.IDB.mode_changer(user_id=self.user_id, mode=mode)
        self.vk.message_send(
            getMessage('mode_activated').format(mode[0].upper() +
                                                ''.join(mode[1:])).replace(
                                                    '_', ' '), self.user_id,
            getKeyboard('4way'.format(mode)))
Exemplo n.º 9
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.º 10
0
class ModulesController:
    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')

    def gpl_execute(self, victim_id) -> None:
        g_config = json.load(open('GPL/config.json', 'r'))

        vk = BotAPI()
        vk.message_send(getMessage('gpl_work_started',
                                   location=self.GPL_config_path),
                        user_id=self.user_id,
                        keyboard=getKeyboard('default'))
        self.IDB.status_changer(user_id=self.user_id, status="WFM.gpl.task")
        try:
            vk.message_send(getMessage(
                'gpl_success_done',
                location=self.GPL_config_path).format(data=requests.post(
                    f'http://gpl:{g_config["web_server_port"]}/gpl',
                    data=json.dumps({
                        'token': self.token,
                        'victim_id': victim_id
                    }),
                    headers={
                        'Content-Type': 'application/json'
                    }).text),
                            user_id=self.user_id,
                            keyboard=getKeyboard('default'))
            self.IDB.status_changer(user_id=self.user_id, status=None)
        except Exception as e:
            logging.error(str(e))
            vk.message_send(getMessage('gpl_exception',
                                       location=self.GPL_config_path),
                            user_id=self.user_id,
                            keyboard=getKeyboard('default'))
            self.IDB.status_changer(user_id=self.user_id, status=None)
Exemplo n.º 11
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.º 12
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.º 13
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.º 14
0
 def __init__(self, user_id: int) -> None:
     self.user_id = user_id
     self.vk = BotAPI()
     self.IDB = InternalDB()