Exemplo n.º 1
0
# Example of sending and receiving an event after pressing the Callback button
# Documentation: https://vk.cc/aC9JG2

import os
import logging

from vkbottle import Keyboard, Callback, GroupTypes, GroupEventType
from vkbottle.bot import Bot, Message

bot = Bot(os.environ["TOKEN"])
logging.basicConfig(level=logging.INFO)

KEYBOARD = (Keyboard(one_time=False).add(
    Callback("Callback-кнопка", payload={"cmd": "callback"})).get_json())


@bot.on.private_message(text="/callback")
async def send_callback_button(message: Message):
    await message.answer("Лови!", keyboard=KEYBOARD)


@bot.on.raw_event(GroupEventType.MESSAGE_EVENT,
                  dataclass=GroupTypes.MessageEvent)
async def handle_message_event(event: GroupTypes.MessageEvent):
    # event_data parameter accepts three object types
    # "show_snackbar" type

    await bot.api.messages.send_message_event_answer(
        event_id=event.object.event_id,
        user_id=event.object.user_id,
        peer_id=event.object.peer_id,
Exemplo n.º 2
0
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
"""VK Elements"""

import json

from vkbottle import Keyboard, Callback, KeyboardButtonColor, TemplateElement, template_gen

from bot.base_vocabulary import r_link
from bot.classes_vocabulary import *
from bot.exams_vocabulary import *

bt_cl_td = Callback(label=v_classes_today[3:], payload={'bt_id': 'today'})
bt_cl_tmrw = Callback(label=v_classes_tomorrow[3:],
                      payload={'bt_id': 'tomorrow'})
bt_cl_now = Callback(label=v_class_now[3:], payload={'bt_id': 'now'})
bt_cl_next = Callback(label=v_class_next[3:], payload={'bt_id': 'next'})
bt_week = Callback(label=v_current_week[3:], payload={'bt_id': 'week'})
bt_timetable = Callback(label=v_class_timetable[3:],
                        payload={'bt_id': 'timetable'})
bt_exam = Callback(label=v_closest_exam[3:], payload={'bt_id': 'exam'})

kbrd = (Keyboard().add(bt_cl_td).add(bt_cl_tmrw).row().add(
    bt_cl_now, color=KeyboardButtonColor.PRIMARY).add(
        bt_cl_next, color=KeyboardButtonColor.PRIMARY).row().add(bt_week).add(
            bt_timetable).add(bt_exam))

no_kbrd = Keyboard()
Exemplo n.º 3
0
# Example of sending and receiving an event after pressing the Callback button
# Documentation: https://vk.com/dev/bots_docs_5?f=4.4.%20Callback-кнопки

import logging
import os

from vkbottle import Callback, GroupEventType, Keyboard
from vkbottle.bot import Bot, Message, MessageEvent, rules

bot = Bot(os.environ["TOKEN"])
logging.basicConfig(level=logging.INFO)

KEYBOARD = (Keyboard(one_time=False, inline=True).add(
    Callback("Показать текст", payload={"cmd": "snackbar"})).row().add(
        Callback("Дата регистрации (tool42)",
                 payload={"cmd": "app"})).row().add(
                     Callback("Закрыть", payload={"cmd": "close"})).get_json())


@bot.on.private_message(text="/callback")
async def send_callback_button(message: Message):
    await message.answer("Лови!", keyboard=KEYBOARD)


@bot.on.raw_event(
    rules.PayloadRule({"cmd": "snackbar"}),
    event=GroupEventType.MESSAGE_EVENT,
    dataclass=MessageEvent,
)
async def show_snackbar(event: MessageEvent):
    await event.show_snackbar("Сейчас я исчезну")
Exemplo n.º 4
0
# Example of sending and receiving an event after pressing the Callback button
# Documentation: https://vk.cc/aC9JG2

import logging
import os

from vkbottle import Callback, GroupEventType, GroupTypes, Keyboard
from vkbottle.bot import Bot, Message

bot = Bot(os.environ["TOKEN"])
logging.basicConfig(level=logging.INFO)

KEYBOARD = (
    Keyboard(one_time=False)
    .add(Callback("Callback-кнопка", payload={"cmd": "callback"}))
    .get_json()
)


@bot.on.private_message(text="/callback")
async def send_callback_button(message: Message):
    await message.answer("Лови!", keyboard=KEYBOARD)


@bot.on.raw_event(GroupEventType.MESSAGE_EVENT, dataclass=GroupTypes.MessageEvent)
async def handle_message_event(event: GroupTypes.MessageEvent):
    # event_data parameter accepts three object types
    # "show_snackbar" type

    await bot.api.messages.send_message_event_answer(
        event_id=event.object.event_id,
Exemplo n.º 5
0
from vkbottle import Keyboard, Callback, Text, KeyboardButtonColor

PREDMETS = (Keyboard(one_time=False, inline=False).add(
    Callback('Русск. яз. (база)', payload={
        'cmd': 'rusyas'
    })).add(Callback('Русск. яз. (профиль)', payload={
        'cmd': 'rusyas_p'
    })).row().add(Callback('Русск. лит.', payload={
        'cmd': 'ruslit'
    })).add(Callback('Бел. яз.', payload={
        'cmd': 'belyas'
    })).row().add(Callback('Бел. лит.', payload={
        'cmd': 'bellit'
    })).add(Callback('Математ. (база)', payload={
        'cmd': 'mat'
    })).row().add(Callback('Математ. (профиль)', payload={
        'cmd': 'mat_p'
    })).add(Callback('Биолог.', payload={
        'cmd': 'bio'
    })).row().add(Callback('Всем. истор.', payload={
        'cmd': 'vistor'
    })).add(Callback('Истор. Бел.', payload={
        'cmd': 'bistor'
    })).row().add(Callback('Обществ.', payload={
        'cmd': 'obsch'
    })).add(Callback('Информат.', payload={
        'cmd': 'info'
    })).row().add(Callback('Астроном.', payload={
        'cmd': 'astro'
    })).add(Callback('Физ.', payload={
        'cmd': 'phys'