Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS users (" +
- "vk_id int(11) NOT NULL," +
- "group int(11) NOT NULL, " +
- "curr_path varchar(255) NOT NULL,"
- "karma int(11) NOT NULL, " +
- "PRIMARY KEY (vk_id)"
- ") DEFAULT CHARSET=utf8;")
- self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS subjects (" +
- "id int AUTO_INCREMENT, "
- "name varchar(255) NOT NULL, " +
- "PRIMARY KEY (id)"
- ") DEFAULT CHARSET=utf8;")
- self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS points (" +
- "vk_id int NOT NULL, " +
- "subject_id int NOT NULL, "
- "value int NOT NULL"
- ") DEFAULT CHARSET=utf8;")
- import mysql.connector
- import traceback
- class DB:
- def __init__(self):
- self.botDB = mysql.connector.connect(host="localhost", user="breezequeue", password="8C9v87FTTHsMw9b6",
- db="breezequeue",
- charset="utf8")
- self.botDB.autocommit = True
- self.botDBCursor = self.botDB.cursor(buffered=True)
- self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS users (" +
- "vk_id int(11) NOT NULL," +
- "group int(11) NOT NULL, " +
- "curr_path varchar(255) NOT NULL,"
- "karma int(11) NOT NULL, " +
- "PRIMARY KEY (vk_id)"
- ") DEFAULT CHARSET=utf8;")
- self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS subjects (" +
- "id int AUTO_INCREMENT, "
- "name varchar(255) NOT NULL, " +
- "PRIMARY KEY (id)"
- ") DEFAULT CHARSET=utf8;")
- self.botDBCursor.execute("CREATE TABLE IF NOT EXISTS points (" +
- "vk_id int NOT NULL, " +
- "subject_id int NOT NULL, "
- "value int NOT NULL"
- ") DEFAULT CHARSET=utf8;")
- def updateUser(self, user):
- self.botDBCursor.execute("UPDATE users SET curr_path = %s WHERE vk_id = %s;", (user.currPath, user.vkId))
- self.botDB.commit()
- def getAllUsers(self):
- self.botDBCursor.execute("SELECT vk_id, curr_path FROM users")
- return self.botDBCursor.fetchall()
- def getSubjects(self):
- self.botDBCursor.execute("SELECT id, name FROM subjects;")
- return self.botDBCursor.fetchall()
- def addPointsToUser(self, user, subjectId, points):
- self.botDBCursor.execute("UPDATE points SET points = points + %s WHERE subject_id = %s AND vk_id = %s", (points, subjectId, user.vkId))
- self.botDB.commit()
- def close(self):
- self.botDB.close()
- import arg_parser
- def handle(user, req, db):
- res = db.siteDBCursor.fetchone()
- if not res:
- user.writeMsg("Тебя не нашли в базе")
- return "index.json" # перенаправление в главное меню
- db.addPointsToUser(user, 1, 10) # добавить 10 баллов юзеру на 1-й предмет
- if not user.args.requireArg("name", "Введи логин:", confirmationRequired=False,
- isOptional=False): # потребовать логин
- return
- # если управление перешло сюда - значит юзер ввел логин успешно
- userName = user.args.getArgValueByKey("name") # получить аргумент, который ты потребовал(-а)
- db.addPointsToUser(user, 1, 10) # добавить 10 баллов юзеру на 1-й предмет
- user.writeMsg("FSDFDSFDS пРИВЕТ! \n")
- if not res:
- arg_parser.clearUserArgs(user) # очистить кэш аргументов
- return "index.json"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement