Exemple #1
0
def clbck(c):
    chat_id = cid(c)
    u = User.cog(user_id=cid(c))
    Message.create(sender=cid(c),
                   sender_type="user",
                   receiver=bot_id,
                   text=c.data,
                   msg_type='text')
    try:
        r = Routing.get(state=u.state, decision=c.data)
        keyboard = types.InlineKeyboardMarkup()
        bot.edit_message_reply_markup(chat_id=cid(c),
                                      message_id=c.message.message_id,
                                      reply_markup=keyboard)
        bot.answer_callback_query(callback_query_id=c.id, show_alert=True)

        try:  # на случай если action не определён в таблице роутинга
            if u.state != s.stop:
                eval(r.action)(u=u, c=c)
        except Exception as e:
            Error.create(message=c.data, state=u.state, exception=e)
            print(e)
            print(s.action_not_defined)
    except Exception as e:
        Error.create(message=c.data, state=u.state, exception=e)
        log_routing_error(e)
Exemple #2
0
def photo(m):
    photo_name = save_photo(m)
    Message.create(sender=uid(m),
                   sender_type="user",
                   receiver=bot_id,
                   text=photo_name,
                   msg_type='photo')
    photo = Photo.create(user_id=uid(m), message_id=m.message_id)
    u = User.cog(user_id=uid(m))
    try:
        r = Routing.get(state=u.state, decision='photo')
        try:  # на случай если action не определён в таблице роутинга
            if u.state != s.stop:
                eval(r.action)(u=u, m=m)
        except Exception as e:
            Error.create(message=m.text, state=u.state, exception=e)
    except Exception as e:
        print(e)
Exemple #3
0
def action(m):
    chat_id = sid(m)
    u = User.cog(user_id=uid(m))
    Message.create(sender=uid(m),
                   sender_type="user",
                   receiver=bot_id,
                   text=m.text)
    if u.state == s.canceled:
        return False
    try:
        r = Routing.get(state=u.state, decision='text')
        try:  # на случай если action не определён в таблице роутинга
            if u.state != s.stop:
                eval(r.action)(u=u, m=m)
        except Exception as e:
            Error.create(message=m.text, state=u.state, exception=e)
            # print(e)
            # print(m)
    except Exception as e:
        Error.create(message=m.text, state=u.state, exception=e)
        log_routing_error(e)
Exemple #4
0
def start(m):
    # print(u, m)
    u = User.cog(user_id=uid(m),
                 username=m.from_user.username,
                 first_name=m.from_user.first_name,
                 last_name=m.from_user.last_name)
    u.clear()
    u.state = s.default
    u.save()
    keyboard = types.InlineKeyboardMarkup()
    agree_btn = types.InlineKeyboardButton(text=s.agree_btn,
                                           callback_data=s.agree)
    disagree_btn = types.InlineKeyboardButton(text=s.disagree_btn,
                                              callback_data=s.disagree)
    more_btn = types.InlineKeyboardButton(text=s.more_btn,
                                          url="http://1fitchat.ru")
    keyboard.add(agree_btn)
    keyboard.add(disagree_btn)
    keyboard.add(more_btn)
    bot.send_message(uid(m),
                     s.greeting,
                     reply_markup=keyboard,
                     parse_mode="Markdown")