コード例 #1
0
        async def test():
            ctrl = VKController(self.conf["vk_token"])

            async with ctrl:
                results.append(await ctrl.raw_request("users.get"))

                self.assertEqual(len(ctrl.subsessions), 1)
                self.assertIsNone(ctrl.subsessions[0])

                async with ctrl:
                    results.append(await ctrl.raw_request("users.get"))

                    self.assertEqual(len(ctrl.subsessions), 2)
                    self.assertIsNone(ctrl.subsessions[0])

                    session_m2 = ctrl.subsessions[-1]

                    async with ctrl:
                        self.assertEqual(len(ctrl.subsessions), 3)
                        self.assertIsNone(ctrl.subsessions[0])

                        results.append(await ctrl.raw_request("users.get"))

                        session_m1 = ctrl.subsessions[-1]

                    self.assertEqual(len(ctrl.subsessions), 2)
                    self.assertEqual(ctrl.session, session_m1)
                    self.assertIsNone(ctrl.subsessions[0])

                self.assertEqual(ctrl.session, session_m2)

            self.assertIsNone(ctrl.session)
            self.assertFalse(ctrl.subsessions)
コード例 #2
0
ファイル: video.py プロジェクト: lordralinc/honkbot
async def video(message, attachments, env):
    privs = await priviligeshelper.getUserPriviliges(env, message.from_id)
    if not (privs & priviligeshelper.USER_VIP > 0):
        return await env.reply(need_vip)

    if not env['args']:
        return await env.reply('Какое видео вас интересует?')

    query = ' '.join(env['args'])
    async with VKController(
            "0688302a8de51d784afafd73c761069978850c88f6c54ffbf28acd5aed42dd8f81fb59aa0e7d28b7f3f52"
    ) as user_api:
        data = await user_api.raw_request('video.search',
                                          q=query,
                                          sort=2,
                                          adult=1,
                                          count=5)
        resp = data.response

    vids = resp.get('items')
    # Если не нашли ни одного видео
    if not vids:
        return await env.reply('Ничего не найдено')
    resp = ','.join(f"video{vid['owner_id']}_{vid['id']}" for vid in vids)
    return await env.reply('Приятного просмотра!', attachment=resp)
コード例 #3
0
async def get_posts(group_id, count, offset):
    async with VKController(
            'f68c8bdf80628aff5e02739338f8c8fd948b6c05dd7b89f731739819c30137e5508ca323f34789c01d155'
    ) as group:
        result = await group.raw_request('wall.get',
                                         count=count,
                                         offset=offset,
                                         owner_id=group_id)
        return result.response
コード例 #4
0
    def setUpClass(cls):
        try:
            with open("configuration_test.json") as o:
                cls.conf = json.load(o)

        except FileNotFoundError:
            cls.conf = {}

        if "vk_token" not in cls.conf:
            cls.conf["vk_token"] = os.environ.get("TEST_TOKEN", "")

        if "vk_utoken" not in cls.conf:
            cls.conf["vk_utoken"] = os.environ.get("TEST_UTOKEN", "")

        cls.messages_to_delete = set()

        if not cls.conf["vk_token"] or not cls.conf["vk_utoken"]:
            raise unittest.SkipTest("No authorization found for this tests.")

        async def get_receiver_coroutine_function(self):
            actual_reci = await self.original_get_receiver_coroutine_function()

            empty_if_done = [1]

            async def reci():
                if not empty_if_done:
                    raise ExitException

                empty_if_done.pop(0)

                cls.ureq("messages.setActivity",
                         type="typing",
                         peer_id=-self.group_id)

                cls.messages_to_delete.add(
                    str(
                        cls.ureq("messages.send",
                                 message="echo message",
                                 peer_id=-self.group_id,
                                 attachment="photo-164328508_456239017," * 2)))

                return await actual_reci()

            return reci

        VKController.original_get_receiver_coroutine_function = VKController.get_receiver_coroutine_function
        VKController.get_receiver_coroutine_function = get_receiver_coroutine_function

        cls.kutana = Kutana()

        cls.kutana.add_controller(
            VKController(token=cls.conf["vk_token"],
                         longpoll_settings={"message_typing_state": 1}))
コード例 #5
0
ファイル: run.py プロジェクト: OLEG4506/BOTDDOS
from kutana import Kutana, VKController, load_plugins, load_configuration


# Create engine
kutana = Kutana()

# Create VKController
kutana.add_controller(
    VKController(token = "d6842a32a19fefc24f1ac19b17cba1c9243f4bf1ecdf426215d193d96135a111d0d537f6e2df8f1452482")
)

# Load and register plugins
kutana.executor.register_plugins(*load_plugins("/root/bot/example/"))

# Run engine
kutana.run()
コード例 #6
0
 async def test():
     async with VKController("token") as ctrl:
         return await ctrl.raw_request("any.method", a1="v1", a2="v2")
コード例 #7
0
 def test_vk_exceptions(self):
     with self.assertRaises(ValueError):
         VKController("")
コード例 #8
0
from kutana import Kutana, VKController, load_plugins, load_configuration

# Create engine
kutana = Kutana()

# Create VKController
kutana.add_controller(VKController(token="Сюда напиши свой токен API"))

# Load and register plugins
kutana.executor.register_plugins(*load_plugins("/root/bot/example/plugins"))

# Run engine
kutana.run()
コード例 #9
0
ファイル: run.py プロジェクト: PythonerMMM/kutana
from kutana import Kutana, VKController, load_plugins, \
    load_configuration

# Create engine
kutana = Kutana()

# Create VKController
controller = VKController(load_configuration("vk_token", "configuration.json"))

# Add controller to engine
kutana.add_controller(controller)

# Load and register plugins
kutana.executor.register_plugins(*load_plugins("example/plugins/"))

# Run engine
kutana.run()