コード例 #1
0
def TransferMessageToVK(chatid, text, Attachment):

    if Attachment is None:

        try:
            module.vk.messages.send(chat_id=config.getCell('t_' + chatid),
                                    message=text)
        except vk_api.ApiError as error_msg:
            module.vk.messages.send(user_id=config.getCell('t_' + chatid),
                                    message=text)
        #print( 'Сообщение успешно отправлено! ( ' + text + ' )' )

    else:

        GetSticker = db.CheckSticker(Attachment)

        # Если стикер не найден в БД
        if GetSticker is None:
            StickerURL = 'https://api.telegram.org/file/bot{0}/{1}'.format(
                config.getCell('telegram_token'), Attachment)
            SaveSticker(StickerURL, Attachment)
            GetSticker = db.CheckSticker(Attachment)

        #print( GetSticker )

        try:
            module.vk.messages.send(chat_id=config.getCell('t_' + chatid),
                                    message="",
                                    attachment=GetSticker)
        except vk_api.ApiError as error_msg:
            module.vk.messages.send(user_id=config.getCell('t_' + chatid),
                                    message="",
                                    attachment=GetSticker)

    return False
コード例 #2
0
def TransferMessageToVK(chatid, text, fromUser, Attachment):

    if (config.getCell('telegram_SendName')):
        time = current_time()
        text = str(time + ' | ' + fromUser + ': ' + text)

    randid = random.randint(-9223372036854775808, +9223372036854775807)  #int64

    if Attachment is None:

        try:
            module.vk.messages.send(chat_id=config.getCell('t_' + chatid),
                                    message=text,
                                    random_id=randid)
        except vk_api.ApiError as error_msg:
            module.vk.messages.send(user_id=config.getCell('t_' + chatid),
                                    message=text,
                                    random_id=randid)
        #print( 'Сообщение успешно отправлено! ( ' + text + ' )' )

    else:

        GetSticker = db.CheckSticker(Attachment)

        # Если стикер не найден в БД
        if GetSticker is None:
            StickerURL = 'https://api.telegram.org/file/bot{0}/{1}'.format(
                config.getCell('telegram_token'), Attachment)
            SaveSticker(StickerURL, Attachment)
            GetSticker = db.CheckSticker(Attachment)

        #print( GetSticker )

        try:
            module.vk.messages.send(chat_id=config.getCell('t_' + chatid),
                                    message="",
                                    attachment=GetSticker,
                                    random_id=randid)
        except vk_api.ApiError as error_msg:
            module.vk.messages.send(user_id=config.getCell('t_' + chatid),
                                    message="",
                                    attachment=GetSticker,
                                    random_id=randid)

    return False