Ejemplo n.º 1
0
def start(bot, update):
    c_id = update.message.chat_id
    global msg, image, buttons
    msg = ''
    image = None
    buttons = None

    statistics.track(c_id, update.message, 'Start')

    def rep(txt, btns=None, photo=None):
        global msg, image, buttons

        if len(msg) + len(txt) + 2 >= 4096:
            reply(c_id, bot, msg, buttons, image)

            msg = ''
            image = None
            buttons = None

        msg += '\n\n'
        msg += txt

        if btns:
            buttons = btns
        if photo:
            image = photo

    username = ''
    try:
        username = bot.getChat(uid)['username']
    except:
        pass
    usermanager.new_user(c_id, username if len(username) > 0 else None, rep)
    if len(msg) > 0 or image:
        reply(c_id, bot, msg, buttons, image)
Ejemplo n.º 2
0
def start(bot, update):
    reply(update.message.chat_id, bot, constants.HELLO_MESSAGE)

    nickname = bot.getChat(update.message.chat_id)['username']
    if len(nickname) == 0:
        nickname = None

    usermanager.new_user(update.message.chat_id, nickname)
    logger.info('New user with id {0}'.format(update.message.chat_id))
Ejemplo n.º 3
0
def new_message(event):
	text = event[6]
	c_id = event[3]
	uid = 'vk' + str(c_id)

	if text == '/start':
		reply(c_id, 'Теперь скажи мне свое имя')
		usermanager.new_user(uid)
	else:
		usermanager.message(uid, lambda *a, **kw: reply(c_id, *a, **kw), event[6])
Ejemplo n.º 4
0
def handle_dialog(req, res):
    user_id = 'alice' + req['session']['user_id']
    global text, buttons_list
    text = ''
    buttons_list = [ ]

    def reply(txt, buttons=None, photo=None):
        global text, buttons_list
        text = text + '\n\n' + txt

        if buttons is None:
            return

        for btn in buttons:
            if isinstance(btn, list):
                buttons_list.extend(btn)
            else:
                buttons_list.append(btn)
    
    if req['session']['new']:
        if not usermanager.new_user(user_id, reply=reply):
            text = 'Теперь скажи мне свое имя'
    else:
        usermanager.message(user_id, reply, req['request']['command'])
        
    res['response']['text'] = text.strip()

    res['response']['buttons'] = [
        {'title': btn, 'hide': False}
        for btn in buttons_list
    ]
Ejemplo n.º 5
0
def handle_dialog(req, res):
    user_id = 'alice' + req['session']['user_id']
    global text, buttons_list
    text = ''
    buttons_list = []

    def reply(txt, buttons=None, photo=None):
        global text, buttons_list
        text = text + '\n\n' + txt

        if buttons is None:
            return

        for btn in buttons:
            if isinstance(btn, list):
                buttons_list.extend(btn)
            else:
                buttons_list.append(btn)

    if req['session']['new']:
        if not usermanager.new_user(user_id, reply=reply):
            text = 'Теперь скажи мне свое имя'
    else:
        usermanager.message(user_id, reply, req['request']['command'])

    res['response']['text'] = text.strip()

    res['response']['buttons'] = [{
        'title': btn,
        'hide': False
    } for btn in buttons_list]
Ejemplo n.º 6
0
def start(bot, update):
	c_id = update.message.chat_id
	global msg, image, buttons
	msg = ''
	image = None
	buttons = None

	statistics.track(c_id, update.message, 'Start')

	def rep(txt, btns=None, photo=None):
		global msg, image, buttons

		if len(msg) + len(txt) + 2 >= 4096:
			reply(c_id, bot, msg, buttons, image)

			msg = ''
			image = None
			buttons = None


		msg += '\n\n'
		msg += txt

		if btns:
			buttons = btns
		if photo:
			image = photo

	username = ''
	try:
		username = bot.getChat(uid)['username']
	except:
		pass
	usermanager.new_user(c_id, username if len(username) > 0 else None, rep)
	if len(msg) > 0 or image:
		reply(c_id, bot, msg, buttons, image)
Ejemplo n.º 7
0
def start(bot, update):
    bot.sendMessage(update.message.chat_id, text='Теперь скажи мне свое имя.')
    usermanager.new_user(update.message.chat_id)