Exemplo n.º 1
0
def user_list(message):
    try:
        if functions.admincheck(message):
            conn = functions.start_sql()
            cursor = conn.cursor(buffered=True)
            cursor.execute("SELECT id, klass FROM known_users ORDER BY klass")
            num = 1
            text = ""
            for id, klass in functions.iter_row(cursor, 50):
                msg = "{0}--{1}\n".format(id, klass)
                text += msg
                if num % 50 == 0:
                    bot.send_message(message.chat.id, text, disable_notification=True)
                    text = ""
                num += 1
            if text != "":
                bot.send_message(message.chat.id, text, disable_notification=True)
            bot.send_message(message.chat.id, "{0} записей в базе".format(num - 1), disable_notification=True)
            cursor.close()
            conn.close()
    except:
        traceback.print_exc()
        ei = "".join(traceback.format_exception(*sys.exc_info()))
        name = message.from_user.first_name + ' ' + message.from_user.last_name + ' ' + message.from_user.username + ' ' + str(message.from_user.id) + '\n'
        log('user list ', name + ei)
Exemplo n.º 2
0
def ras_init(message):
    if functions.admincheck(message):
        query = message.text.replace('/ras ', '')
        if query != message.text:
            functions.set_next_step("ras_" + query, message.from_user.id)
            bot.send_message(message.chat.id, "Запрос:\nSELECT id FROM known_users WHERE " + query + "\n\nОтправьте сообщение для рассылки")
        else:
            bot.reply_to(message, "Команды работает так:\n/ras {expression}.\nSELECT id,name FROM known_users WHERE {expression}")
Exemplo n.º 3
0
def admcmd(message):
    if functions.admincheck(message):
        bot.send_message(message.chat.id, "/ras {exp} - рассылка по сравнению. SELECT id from known_users WHERE {exp}\n"
                                          "/list - Показать список зафиксированных пользователей\n"
                                          "/fblist - Показать список всех фидбэков\n"
                                          "/answer {fb_id} {текст} - Ответить на фидбэк\n"
                                          "/background - Установить фон на следующий месяц (если нет фона - на этот) (нужно делать КАЖДЫЙ месяц!)\n"
                                          "/webhook - Просмотреть информацию о webhook-е\n"
                                          "/sql {query} - Выполнить SQL-запрос в БД\n"
                                          "/addrasp - Загрузить таблицу с расписанием\n"
                                          "/addtest - Загрузить docx-файл с вопросами")
Exemplo n.º 4
0
def feedback_list(message):
    try:
        if functions.admincheck(message):
            conn = functions.start_sql()
            cursor = conn.cursor()
            cursor.execute("SELECT id, text FROM feedback ORDER BY id DESC")  # Сортировка в обратном порядке, чтобы старые фидбэки было удобнее смотреть
            for num, text in functions.iter_row(cursor, 10):
                bot.send_message(message.chat.id, text + '\n/answer ' + str(num) + ' текст')
            bot.send_message(message.chat.id, "Все фидбэки отправлены")
    except:
        traceback.print_exc()
        ei = "".join(traceback.format_exception(*sys.exc_info()))
        name = message.from_user.first_name + ' ' + message.from_user.last_name + ' ' + message.from_user.username + ' ' + str(message.from_user.id) + '\n'
        log('fb list ', name + ei)
Exemplo n.º 5
0
def test(message):
    """
    :param message:
    :type message: telebot.types.Message
    """
    try:
        if functions.admincheck(message):
            bot.send_message(message.chat.id, "url: {0}\nlogin: {1}\npass: {2}\nDB: {3}".format(
                constants.sql_url, constants.sql_log, constants.sql_pass, constants.sql_db
            ))
            bot.send_message(message.chat.id, 'Server time ' + str(datetime.datetime.now()))
    except:
        traceback.print_exc()
        ei = "".join(traceback.format_exception(*sys.exc_info()))
        log('test', ei)
Exemplo n.º 6
0
def webhook_info(message):
    if functions.admincheck(message):
        try:
            global tz
            info = bot.get_webhook_info()
            msg = "URL: _{0}_\n" \
                  "Custom certificate: _{1}_\n" \
                  "Pending update count: _{2}_\n" \
                  "Last error date: _{3}_\n" \
                  "Last error message: _{4}_".format(info.url, info.has_custom_certificate, info.pending_update_count,
                                                     str(datetime.datetime.fromtimestamp(info.last_error_date, tz)),
                                                     info.last_error_message)
            bot.send_message(message.chat.id, msg, parse_mode="Markdown")
        except:
            traceback.print_exc()
            ei = "".join(traceback.format_exception(*sys.exc_info()))
            name = message.from_user.first_name + ' ' + message.from_user.last_name + ' ' + message.from_user.username + ' ' + str(message.from_user.id) + '\n'
            log('Webhook', name + ei)
Exemplo n.º 7
0
def answer(message):
    try:
        if functions.admincheck(message):
            msg = message.text.replace("/answer ", "")
            if msg != message.text:  # Проверка на случайное нажатие /answer
                conn = functions.start_sql()
                cursor = conn.cursor(buffered=True)
                cursor.execute("SELECT u_id, m_id FROM feedback WHERE id = {0} ".format(msg[0:msg.find(" ")]))  # Вырежет из сообщения номер
                for u_id, m_id in cursor.fetchmany(1):  # Если получать кортеж через fetchone, то вернет итерируемый лист, тогда не будет работать цикл
                    bot.send_message(u_id, "Ответ разработчика:\n" + msg[msg.find(" ") + 1:], reply_to_message_id=m_id)
                    cursor.execute("DELETE FROM feedback WHERE id = {0}".format(msg[0:msg.find(" ")]))  # Удаляет фидбэк, на который был получен ответ, из бд
                    conn.commit()
                cursor.close()
                conn.close()
                bot.reply_to(message, "Сообщение отправлено")
            else:
                bot.reply_to(message, "Команда работает так:\n/answer {fb_id} {text}")
    except:
        traceback.print_exc()
        ei = "".join(traceback.format_exception(*sys.exc_info()))
        name = message.from_user.first_name + ' ' + message.from_user.last_name + ' ' + message.from_user.username + ' ' + str(message.from_user.id) + '\n'
        log('answer ', name + ei)
Exemplo n.º 8
0
def sql(message):
    if functions.admincheck(message):
        try:
            conn = functions.start_sql()
            cursor = conn.cursor()
            cmd = message.text.replace("/sql ", "")  # type: str
            if cmd:
                mul = bool(cmd.count(';'))
                cursor.execute(cmd, multi=mul)
                report = ""
                for elem in functions.iter_row(cursor, 20):
                    report += str(elem) + ' '
                report = "done" if report == '' else report
                bot.reply_to(message, report)
                conn.commit()
                cursor.close()
                conn.close()
            else:
                bot.reply_to(message, "Команда работает так:\n/sql {sql query}")
        except:
            traceback.print_exc()
            ei = "".join(traceback.format_exception(*sys.exc_info()))
            name = message.from_user.first_name + ' ' + message.from_user.last_name + ' ' + message.from_user.username + ' ' + str(message.from_user.id) + '\n'
            log('sql', name + ei)
Exemplo n.º 9
0
def background(message):
    if functions.admincheck(message):
        functions.set_next_step('background-in', message.from_user.id)
        bot.send_message(message.chat.id, "Отправьте фотографию на фон размером ~1280*800")
Exemplo n.º 10
0
def add_test(message):
    if functions.admincheck(message):
        functions.set_next_step('addtest', message.from_user.id)
        bot.send_message(message.from_user.id, "Можете отправлять docx-файл.")