Ejemplo n.º 1
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def repeat_all_messages(
        message):  # Название функции не играет никакой роли, в принципе
    print(message)
    if True:
        # try:
        if message.reply_to_message == None:
            if message.chat.type == 'supergroup' or message.chat.type == 'group':
                print("effort to speak in group with id = {}".format(
                    message.chat.id))
                return True
            cor = core(message.chat.id, message.from_user.id)
            send, sendtome, mess, messout = cor.ans(message.text,
                                                    message.message_id,
                                                    1,
                                                    entities=message.entities)
        else:
            cor = core(message.chat.id, message.from_user.id)
            send, sendtome, mess, messout = cor.reply(
                message.text, message.message_id,
                message.reply_to_message.message_id, 1)

        sendmessage(cor,
                    send,
                    startmess=mess,
                    chatid=message.chat.id,
                    chattype=message.chat.type,
                    message_id=message.message_id,
                    sendtome=sendtome,
                    messbeta=messout)
        cor.close()
Ejemplo n.º 2
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def handle_hello(message):
    if message.chat.type == 'supergroup' or message.chat.type == 'group':
        return True
    cor = core(message.chat.id, message.from_user.id)
    cor.db.setMode_person()
    bot.send_message(message.chat.id, "Ваш person_mode = 0")
    cor.close()
Ejemplo n.º 3
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def posts_from_channels(message):
    try:
        print("Channel message in {}({}); id={}".format(
            message.chat.title, message.chat.username, message.chat.id))
        cor = core()
        cor.newsletters_channel_post(chatId=message.chat.id,
                                     messId=message.message_id)

    except Exception as e:
        print(e)
        bot.send_message(config.admin_chat, e)
Ejemplo n.º 4
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def handle_start(message):
    if message.chat.type == 'supergroup' or message.chat.type == 'group':
        return True
    print(message)
    mess = "Hi"
    cor = core(message.chat.id, message.from_user.id)
    if cor.db.person['id'] == 0:
        cor.db.add_person_byTL(
            message.from_user.id, message.from_user.username,
            message.from_user.first_name +
            ("" if message.from_user.last_name == None else
             message.from_user.last_name))
        bot.send_message(message.chat.id, mess)
    else:
        bot.send_message(message.chat.id, "Hi again")
    cor.close()
Ejemplo n.º 5
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def handle_signup(message):
    if message.chat.type == 'supergroup' or message.chat.type == 'group':
        return True  #bot.reply_to(message, "Эта команда невозможна в группе")
    try:
        cor = core(message.chat.id, message.from_user.id)
        send, sendtome, mess, messbeta = cor.signup(message.text,
                                                    message.message_id, 1)
        sendmessage(cor,
                    send,
                    startmess=mess,
                    chatid=message.chat.id,
                    chattype=message.chat.type,
                    message_id=message.message_id,
                    sendtome=sendtome,
                    messbeta=messbeta)
    except Exception as e:
        print(e)
        bot.reply_to(message, e)
Ejemplo n.º 6
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def nickname_info(message):
    if message.chat.type == 'supergroup' or message.chat.type == 'group':
        return True
    try:
        cor = core(message.chat.id, message.from_user.id)
        send, sendtome, mess, messout = cor.nickname_new(
            message.text, message.message_id, 1)
        sendmessage(cor,
                    send,
                    startmess=mess,
                    chatid=message.chat.id,
                    chattype=message.chat.type,
                    message_id=message.message_id,
                    sendtome=sendtome,
                    messbeta=messout)
    except Exception as e:
        print(e)
        bot.reply_to(message, e)
Ejemplo n.º 7
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def handle_docs(message):
    try:
        if message.chat.type == 'supergroup' or message.chat.type == 'group':
            return True

        cor = core(message.chat.id, message.from_user.id)
        file_info = bot.get_file(message.document.file_id)
        # print(message.document)
        downloaded_file = bot.download_file(file_info.file_path)
        #print(message.document.thumb)

        file_name_orig = message.document.file_name  # чтобы получить формат файла
        if '.' in file_name_orig and len(
                file_name_orig
        ) < 200 and message.document.file_size < 10000000:
            extension = file_name_orig[file_name_orig.rfind('.') + 1:]
            file_name = funcs.keyGenerator(message.from_user.id,
                                           length=20) + "-" + str(
                                               message.date) + "." + extension
            halfday = int(time.gmtime().tm_hour / 12)
            path = "{}/{}".format(halfday, file_name)
            with open(cor.BASE_DIR + '/doc/{}'.format(path), 'wb') as new_file:
                new_file.write(downloaded_file)

            send, sendtome, mess, messout = cor.file(
                (4, [(file_name, path, extension, file_name_orig)]),
                message.message_id, 1)
        else:
            send, sendtome, mess, messout = [[
                0, "Файлы должны быть с понятным расширением и не больше 10Mb"
            ]], [], "", ""
        sendmessage(cor,
                    send,
                    startmess=mess,
                    chatid=message.chat.id,
                    chattype=message.chat.type,
                    message_id=message.message_id,
                    sendtome=sendtome,
                    messbeta=messout)
    except Exception as e:
        print(e)
        bot.reply_to(message, e)
Ejemplo n.º 8
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def handle_photo(message):
    try:
        if message.chat.type == 'supergroup' or message.chat.type == 'group':
            return True
        cor = core(message.chat.id, message.from_user.id)
        files = []
        ph = message.photo[-1]
        print(message.photo[-1])
        halfday = int(time.gmtime().tm_hour / 12)
        if True:
            file_info = bot.get_file(ph.file_id)
            time_now = time.localtime()
            file_name_orig = "photo-{}-{:2.0f}-{:2.0f}".format(
                config.name_of_week_days[time_now.tm_wday], time_now.tm_hour,
                time_now.tm_min).replace(' ', '0')
            extension = 'png'
            file_name_orig = '{}.{}'.format(file_name_orig, extension)
            downloaded_file = bot.download_file(file_info.file_path)

            file_name = funcs.keyGenerator(message.from_user.id) + "-" + str(
                message.date) + '.png'
            path = "{}/{}".format(halfday, file_name)
            with open(cor.BASE_DIR + '/doc/{}'.format(path), 'wb') as new_file:
                new_file.write(downloaded_file)
            files.append((file_name, path, extension, file_name_orig))

        send, sendtome, mess, messout = cor.file((3, files),
                                                 message.message_id, 1)
        sendmessage(cor,
                    send,
                    startmess=mess,
                    chatid=message.chat.id,
                    chattype=message.chat.type,
                    message_id=message.message_id,
                    sendtome=sendtome,
                    messbeta=messout)

    except Exception as e:
        print(e)
        bot.reply_to(message, e)
Ejemplo n.º 9
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def callback_inline(call):
    print("Call back query")
    try:
        if call.message:
            if call.data == "test":
                bot.edit_message_text(chat_id=call.message.chat.id,
                                      message_id=call.message.message_id,
                                      text="Пыщь")
            if call.data == "ok":
                bot.edit_message_text(chat_id=call.message.chat.id,
                                      message_id=call.message.message_id,
                                      text="Ok")
            if call.data == "del":
                bot.edit_message_text(
                    chat_id=call.message.chat.id,
                    message_id=call.message.message_id,
                    text="Тут был секретик (но это не точно. тссс)")
            if call.data == "delpass":
                bot.edit_message_text(
                    chat_id=call.message.chat.id,
                    message_id=call.message.message_id,
                    text=
                    "Тут был секретик. Используйте /myinfo чтобы снова получить эту информацию"
                )
            if call.data == "signupremove":
                cor = core(call.message.chat.id, call.from_user.id)
                mess = cor.signupremove()
                print("out: {}".format(mess))
                bot.edit_message_text(chat_id=call.message.chat.id,
                                      message_id=call.message.message_id,
                                      text=mess)

        # Если сообщение из инлайн-режима
        elif call.inline_message_id:
            if call.data == "test":
                bot.edit_message_text(inline_message_id=call.inline_message_id,
                                      text="Бдыщь")

        dd = funcs.strtojson(call.data)
        if len(dd) == 0: return True
        cor = core(call.message.chat.id, call.from_user.id)
        print(call.data)
        if dd.get('mode') == 'edit3':
            mess = cor.edit_phase2(dd)
            print("out: {}".format(mess))
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text=mess)

        if dd.get('mode') == 'nl_remove':
            mess = cor.newsletters_remove(dd)
            print("out: {}".format(mess))
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text=mess)

        if dd.get('mode') == 'nl_add':
            mess = cor.newsletters_add(dd)
            print("out: {}".format(mess))
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text=mess)

        if dd.get('mode') == 'send3':
            mess = cor.send2(dd)
            print("out: {}".format(mess))
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text=mess)

        if dd.get('mode') == 'easyfile':
            mess = cor.easyspeak_file_update(
                dd, message_id=call.message.message_id)
            print("out: {}".format(mess))
            if mess:
                sendmessage(cor,
                            mess,
                            chatid=call.message.chat.id,
                            chattype=call.message.chat.type,
                            message_id=call.message.message_id,
                            editmessage=True)

        cor.close()
    except Exception as e:
        print(e)
        bot.edit_message_text(chat_id=call.message.chat.id,
                              message_id=call.message.message_id,
                              text=e)

    return False
Ejemplo n.º 10
0
Archivo: bot.py Proyecto: 4cd87a/ftfbot
def handle_test(message):
    if message.chat.type == 'supergroup' or message.chat.type == 'group':
        return True
    cor = core(message.chat.id, message.from_user.id)
    cor.close()
    bot.send_message(config.help_chat, "test")