Ejemplo n.º 1
0
def sql_delete_user(user_id):
    con = sql_connection()
    cur = con.cursor()
    cur.execute("DELETE FROM users WHERE user_id ='%s'" % int(user_id))
    logging.info("User %s deleted from DB" % user_id)
    con.commit()
    cur.close()
Ejemplo n.º 2
0
def sql_count_users():
    con = sql_connection()
    cur = con.cursor()
    count = cur.execute("SELECT COUNT(*) FROM users").fetchone()[0]
    con.commit()
    cur.close()
    return count
Ejemplo n.º 3
0
def sql_show_users():
    con = sql_connection()
    cur = con.cursor()
    users = cur.execute("SELECT user_id, user_name FROM users").fetchall()
    con.commit()
    cur.close()
    return users
Ejemplo n.º 4
0
def sql_update_name(username, user_id):
    con = sql_connection()
    cur = con.cursor()
    data = (username, user_id)
    with con:
        cur.execute("UPDATE users SET user_name = ? WHERE user_id = ?", data)
    logging.info(f"User's ({user_id}) name update")
    con.commit()
    con.close()
Ejemplo n.º 5
0
def sql_init_user(user_id):
    con = sql_connection()
    cur = con.cursor()
    db_user = cur.execute("SELECT user_id, admin_check FROM users").fetchall()
    con.commit()
    cur.close()
    for row in db_user:
        if row[0] == int(user_id):
            return {'verif': True, 'admin': row[1]}
    return False
Ejemplo n.º 6
0
def sql_new_user(user_id):
    con = sql_connection()
    cur = con.cursor()
    now_date = datetime.now()
    data = ('None', user_id, now_date, False)
    with con:
        cur.execute(
            "INSERT INTO users(user_name, user_id, date_registration, admin_check) VALUES(?, ?, ?, ?)",
            data)
    logging.info("User %s added in DB" % user_id)
    con.commit()
    con.close()
Ejemplo n.º 7
0
def sql_create_user_table():
    con = sql_connection()
    cur = con.cursor()
    with con:
        cur.execute("CREATE TABLE IF NOT EXISTS users ("
                    "user_name TEXT, "
                    "user_id INTEGER PRIMARY KEY, "
                    "date_registration DATETIME, "
                    "admin_check BOOL);")
        data = ('@janki_wtf', 199225478, None, True)
        cur.execute(
            "INSERT INTO users(user_name, user_id, date_registration, admin_check) VALUES(?, ?, ?, ?)",
            data)
    con.commit()
    cur.close()
Ejemplo n.º 8
0
import logging
from aiogram import types
from aiogram.dispatcher import FSMContext

import bot
import url_db, user_db, url_library
from bot import SelectMenu
# Connect to DB
con = url_db.sql_connection()

commands_admin = ['Добавить юзера', 'Показать юзеров', 'Удалить юзера']


# Admin panel
async def admin_menu(message: types.Message):
    user = user_db.sql_init_user(message.from_user.id)
    if user['admin']:
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
        cancel_but = types.KeyboardButton(text='Back')
        keyboard.add(cancel_but)
        for command in commands_admin:
            keyboard.add(command)
        await message.answer('Admin commands:', reply_markup=keyboard)


# Add new user
async def add_user(message: types.Message):
    user = user_db.sql_init_user(message.from_user.id)
    if user['admin']:
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
        cancel_but = types.KeyboardButton(text='Back')