Exemplo n.º 1
0
def send_message(user_id, token, message, attachment=""):
    logger.info('send \"' + message.encode().decode("utf-8", 'replace') +
                ' \" to ' + str(user_id))

    print(getDEBUG())
    if (getDEBUG()):
        print(message)
        global sended_message
        sended_message = message
        # api.messages.send(access_token=token, user_id=str(user_id), message=message, attachment=attachment)
    else:
        api.messages.send(access_token=token,
                          user_id=str(user_id),
                          message=message,
                          attachment=attachment)
Exemplo n.º 2
0
def to_vkid(scr_name):
    if getDEBUG():
        if scr_name == 'thrash_yura':
            return 142872618
        elif scr_name == 'konstantinleladze':
            return 209780589
        elif scr_name == 'paulpalich':
            return 159817977
        elif scr_name == 'id481116745':
            return 481116745
        elif scr_name == 'patlin':
            return 69337293
        elif scr_name == 'tatbottoo':
            return 168619478
        elif scr_name == 'id280679710':
            return 280679710

    print(scr_name)

    response = api.utils.resolveScreenName(screen_name=scr_name,
                                           access_token=get_token())

    if response == []:
        raise ManualException(
            'Кажется вы дали неверную ссылку, я не нашел такого пользователя!')
    # elif response['type'] != 'user':
    #     raise ManualException('Вы прислали ссылку не на пользователя. Админом может быть только пользователь.')
    # надо делать проверку в методах добавления админа

    return response['object_id']
Exemplo n.º 3
0
def processing():
    if debug_module.getDEBUG():
        logger.info('Run in debug.')

    logger.info('URL: {0}'.format(request.url_root))
    logger.info('in processing')

    bindata = request.data
    # logger.info('data = {0}'.format(bindata))

    data = json.loads(bindata)

    # Вконтакте в своих запросах всегда отправляет поле типа
    if 'type' not in data.keys():
        logger.info('not vk')
        return 'not vk'

    if data['type'] == 'confirmation':
        logger.info('confirmation')
        return confirmation_token

    elif data['type'] == 'message_new' or data['type'] == 'service_reply':
        logger.info('pulled message: ' + str(data['object']))

        vkbot.reply_to_message(data)
        return 'ok'

    return 'ok'
Exemplo n.º 4
0
def processing():
    # Распаковываем json из пришедшего POST-запроса

    logger.info('processing')
    logger.info(g.todoist_state_pull)

    if debug_module.getDEBUG():
        logger.info('Run in debug')

    logger.info(request.data)
    data = json.loads(request.data)
    logger.info(data)

    # Вконтакте в своих запросах всегда отправляет поле типа
    if 'type' not in data.keys():
        return 'not vk'

    if data['type'] == 'confirmation':
        return confirmation_token

    elif data['type'] == 'message_new' or data['type'] == 'service_reply':
        logger.info('pulled message: ' + str(data['object']))

        from tools.constants import Messenger
        data['messenger'] = Messenger.VK.name

        current_app.bot.reply_to_message(data)
        return 'ok'

    return 'ok'
Exemplo n.º 5
0
def get_token():
    if getDEBUG():
        logger.info('DEBUG = True')
        return 'bddeddc0f08b56addc83768d464cea4246ecb5e1b2c9b5df894900aeb84dcec396cc77eae7a5b6062bd6f'

    logger.info('URL: {0}'.format(request.url_root))
    if request.url_root == 'http://tattoo-release.herokuapp.com/':
        logger.info('Я взял этот токен - 41da...')
        return '41da46788fcebab7d73426c8a015f829ec9b21b6680136e4e474df7dc980d4219c66eebcb6292c5ec405b'
    else:
        logger.info('Я взял этот токен - bdde...')
        return 'bddeddc0f08b56addc83768d464cea4246ecb5e1b2c9b5df894900aeb84dcec396cc77eae7a5b6062bd6f'
Exemplo n.º 6
0
def get_group_memb(group_id, moderator_token):
    if getDEBUG():
        return [159817977, 481116745, 280679710]

    # response = api.utils.resolveScreenName(screen_name=scr_name, access_token=token)
    # if response['type'] != 'group':
    #     raise ManualException('Данная ссылка не является ссылкой на группу!')

    try:
        return api.groups.getMembers(group_id=group_id,
                                     sort='time_desc',
                                     access_token=moderator_token)['items']
    except vk.exceptions.VkAPIError as ex:
        if str(ex).find('Access denied: you should be group moderator.') != -1:
            raise ManualException(
                'Отклонено. Вы должны являться модератором сообщества, которое добавляете.'
            )
        else:
            raise ex
Exemplo n.º 7
0
def get_debug():
    print(debug_module.getDEBUG())
    return 'DEBUG = {0}'.format(debug_module.getDEBUG())
Exemplo n.º 8
0
def get_debug():
    logger.info(debug_module.getDEBUG())
    return 'DEBUG = {0}'.format(debug_module.getDEBUG())