Beispiel #1
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
    ]
Beispiel #2
0
def msg(bot, update):
	c_id = update.message.chat_id
	statistics.track(c_id, update.message)

	global msg, image, buttons
	msg = ''
	image = None
	buttons = None

	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

	usermanager.message(c_id, rep, update.message.text)

	if len(msg) > 0 or image:
		global updater

		_reply(c_id, bot, msg, buttons, image)
Beispiel #3
0
def msg(bot, update):
	c_id = update.message.chat_id
	statistics.track(c_id, update.message)

	global msg, image, buttons
	msg = ''
	image = None
	buttons = None

	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

	usermanager.message(c_id, rep, update.message.text)

	if len(msg) > 0 or image:
		global updater

		_reply(c_id, bot, msg, buttons, image)
Beispiel #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]
Beispiel #5
0
def msg(bot, update):
    c_id = update.message.chat_id

    def rep(txt, btns=None, uid=c_id):
        reply(uid, bot, txt, btns)

    try:
        usermanager.message(c_id, rep, update.message.text)
    except Exception as e:
        logger.warn(str(e))
Beispiel #6
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])
Beispiel #7
0
def msg(bot, update):
	c_id = update.message.chat_id

	global msg, image, buttons
	msg = ''
	image = None
	buttons = None

	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

	usermanager.message(c_id, rep, update.message.text)

	if len(msg) > 0 or image:
		global updater

		send_job = Job(reply_job,
						0.040,
						repeat=False,
						context=(c_id, bot, msg, buttons, image))
		reply(c_id, bot, msg, buttons, image)