Beispiel #1
0
async def echo_message(msg: types.Message, _):
    logging.info(f"Started raiding {msg.peer_id}.")
    sent_message_count = 0
    while True:
        try:
            keyboard = Keyboard(one_time=False)
            for row in range(0, 10):
                button_colors = deque([
                    ButtonColor.POSITIVE,
                    ButtonColor.NEGATIVE,
                    ButtonColor.SECONDARY,
                    ButtonColor.PRIMARY,
                ])
                button_colors.rotate(sent_message_count % len(button_colors))
                for button in range(0, 4):
                    keyboard.add_text_button(config["buttons_text"],
                                             color=button_colors[button])
                if row != 9:
                    keyboard.add_row()
            await api.messages.send(
                random_id=random.getrandbits(31) * random.choice([-1, 1]),
                peer_id=msg.peer_id,
                message=config["message_text"],
                keyboard=keyboard.get_keyboard(),
            )
            sent_message_count += 1
            await asyncio.sleep(config["delay"])
        except APIException as e:
            logging.info(f"Stopped raiding {msg.peer_id}. Reason: {e}")
            await asyncio.sleep(10)
Beispiel #2
0
async def spam_ls_key(message: types.Message, data: dict):
    keyboard = Keyboard(False)
    keyboard.add_text_button("/ " + message.text.split(" ", 1)[1],
                             payload={"command": "spam"})
    keyboard.add_text_button("Убрать клавиатуру",
                             payload={"command": "delete_keyboard"})
    await message.answer("Generated keyboard",
                         keyboard=keyboard.get_keyboard())
Beispiel #3
0
from vk import VK
from vk.bot_framework import Dispatcher, get_group_id
from vk.keyboards import ButtonColor
from vk.keyboards import Keyboard
from vk.utils import TaskManager

logging.basicConfig(level="INFO")

bot_token = "123"
vk = VK(bot_token)
task_manager = TaskManager(vk.loop)
api = vk.get_api()

dp = Dispatcher(vk)

keyboard = Keyboard(one_time=False)
keyboard.add_text_button("Hello, my friend!", payload={"hello": "world"})
keyboard.add_text_button("Another text", color=ButtonColor.SECONDARY)


@dp.message_handler(payload={"hello": "world"})
async def handle_event(message: types.Message, data: dict):
    await message.reply("Hello :)")


@dp.message_handler(text="get")
async def get_keyboard(message: types.Message, data: dict):
    await message.answer(":)", keyboard=keyboard.get_keyboard())


@dp.message_handler(text="off")
Beispiel #4
0
async def template_handler(message: types.Message, data: dict):
    keyboard = Keyboard(one_time=False)

    keyboard.add_text_button("Hello world!")
    keyboard.add_link_button(text="Link to Google", link="https://google.com")

    template_1 = Template(
        title="First title",
        description="First description",
        buttons=keyboard.buttons[0],
        photo_id="-191459391_457239025",
    )

    keyboard = Keyboard(one_time=False)
    keyboard.add_text_button("World hello!")
    keyboard.add_text_button("Wow, another button")

    template_2 = Template(
        title="Second title",
        description="Second description",
        buttons=keyboard.buttons[0],
        photo_id="-191459391_457239026",
    )

    carousel = Template.generate_template(template_1, template_2)
    await message.answer("Look on this templates!", template=carousel)
Beispiel #5
0
from vk import types
import json

send_25messages = VkFunction(args=("peer_id", "message"),
                             clean_args=("peer_id", ),
                             code="""
var params = {"message": %(message)s, "peer_id": %(peer_id)s, "random_id": 0};
var i = 0;
while (i < 25) {
    API.messages.send(params);
    i = i + 1;
};
return true;
""")

keyboard = Keyboard(True)


@dp.message_handler(commands=["say"])
async def say_hello(message: types.Message, data: dict):
    io = BytesIO()
    args = message.get_args()
    await aiogtts.write_to_fp(" ".join(args[1:]), io, slow=True, lang=args[0])
    io.seek(0)
    result = await vk.api_request(
        "docs.getMessagesUploadServer",
        dict(type="audio_message", peer_id=message.peer_id))
    url_data = aiohttp.FormData()
    url_data.add_field('file', io)
    async with vk.client.post(result["upload_url"], data=url_data) as response:
        result = await response.json()
Beispiel #6
0
from vk.keyboards import Keyboard, ButtonColor

# keyboards for teams

kb_start = Keyboard(one_time=False)
kb_start.add_text_button('Начать квест!', payload={"command": 'start'})

kb_choose = Keyboard(one_time=False)
kb_choose.add_text_button('Я капитан',
                          payload={"command": 'kb_choose_captain'})
kb_choose.add_text_button('Я участник',
                          payload={"command": 'kb_choose_participant'})

kb_league = Keyboard(one_time=False)
kb_league.add_text_button('Школьная', payload={"command": 'kb_school'})
kb_league.add_text_button('Молодёжная', payload={"command": 'kb_junior'})
kb_league.add_text_button('Предприятия', payload={"command": 'kb_zavod'})

kb_back_to_start = Keyboard(one_time=False)
kb_back_to_start.add_text_button('Назад',
                                 payload={"command": 'kb_back_to_start'})

kb_back_to_main = Keyboard(one_time=False)
kb_back_to_main.add_text_button('Хватит с меня этой загадки',
                                payload={"command": 'kb_back_to_main'})

kb_main = Keyboard(one_time=False)
kb_main.add_text_button('Задания и баллы', payload={"command": 'tasks'})
# kb_main.add_text_button('Баллы команды', payload={"command": 'marks'})
kb_main.add_text_button('Помощь', payload={"command": 'help'})