Exemple #1
0
 def test_auth_with_2factor(self):
     s = ImplicitSession(login=USER_LOGIN,
                         password=USER_PASSWORD,
                         app_id=APP_ID)
     with self.assertRaises(VkTwoFactorCodeNeeded):
         yield from s.authorize()
     s.close()
Exemple #2
0
 def test_auth_without_2factor(self):
     s = ImplicitSession(login=USER_LOGIN,
                         password=USER_PASSWORD,
                         app_id=APP_ID)
     yield from s.authorize()
     s.close()
     self.assertIsNotNone(s.access_token)
Exemple #3
0
 def test_auth_with_invalid_password(self):
     s = ImplicitSession(login=USER_LOGIN,
                         password='******',
                         app_id=APP_ID)
     with self.assertRaises(VkAuthError):
         yield from s.authorize()
     s.close()
Exemple #4
0
 def test_auth_process_captcha_without_2factor(self):
     s = ImplicitSession(login=USER_LOGIN,
                         password=USER_PASSWORD,
                         app_id=APP_ID)
     for i in range(10):
         with self.assertRaises(VkCaptchaNeeded):
             yield from s.authorize()
     s.close()
Exemple #5
0
    async def init_vk(self):
        vk_session = None
        if self.config['IMPLICIT']:
            vk_session = ImplicitSession(self.config['USER_LOGIN'], self.config['USER_PASSWORD'],
                                         self.config['APP_ID'], ['messages', 'wall'])
        else:
            # TODO(spark): implement TokenSession
            pass

        self.logger.info('Auth in VK...')
        await vk_session.authorize()

        self.vk_api = vk_api = API(vk_session)
        vk_lp = LongPoll(vk_api, mode=2)

        while self.running:
            # Main working loop
            response = await vk_lp.wait()

            for action in response['updates']:
                if action[0] is 4:
                    message_id = action[1]
                    sender = action[3]
                    sender_id = sender
                    message = str(action[6])
                    attachment = action[7]
                    self.logger.debug('Got message: {}'.format(message))

                    if sender > 2000000000:
                        # Groupchat
                        sender_id = int(attachment['from'])

                    f_flag = False
                    for f in self.filters:
                        f_res = await f(sender, sender_id, message, attachment)
                        if f_res is False:
                            f_flag = True
                            continue

                    if f_flag:
                        continue

                    if message.startswith(self.config['COMMAND_SYMBOL']) and message[1] is not ' ':
                        message = message[1:]
                        flag = False
                        for c in self.commands:
                            if message.startswith(c) and not flag:
                                flag = True
                                command = message.split(' ')[0]
                                if command in self.admin_commands and sender_id not in self.config['ADMINS']:
                                    await self.send_message(sender, 'Access denied')
                                else:
                                    await self.commands[command](sender, sender_id, message, attachment)
                        if flag is False:
                            await self.send_message(sender, 'Command not found')

        vk_session.close()
Exemple #6
0
 def test_auth_with_app_id(self):
     s = ImplicitSession(login='', password='', app_id=APP_ID)
     with self.assertRaises(VkAuthError):
         yield from s.authorize()
     s.close()
Exemple #7
0
 def test_auth_without_2factor(self):
     s = ImplicitSession(login=USER_LOGIN, password=USER_PASSWORD, app_id=APP_ID)
     yield from s.authorize()
     s.close()
     self.assertIsNotNone(s.access_token)
Exemple #8
0
 def test_auth_with_2factor(self):
     s = ImplicitSession(login=USER_LOGIN, password=USER_PASSWORD, app_id=APP_ID)
     with self.assertRaises(VkTwoFactorCodeNeeded):
         yield from s.authorize()
     s.close()
Exemple #9
0
 def test_auth_with_invalid_password(self):
     s = ImplicitSession(login=USER_LOGIN, password='******', app_id=APP_ID)
     with self.assertRaises(VkAuthError):
         yield from s.authorize()
     s.close()
Exemple #10
0
 def test_auth_with_app_id(self):
     s = ImplicitSession(login='', password='', app_id=APP_ID)
     with self.assertRaises(VkAuthError):
         yield from s.authorize()
     s.close()
Exemple #11
0
 def test_auth_process_captcha_without_2factor(self):
     s = ImplicitSession(login=USER_LOGIN, password=USER_PASSWORD, app_id=APP_ID)
     for i in range(10):
         with self.assertRaises(VkCaptchaNeeded):
             yield from s.authorize()
     s.close()