コード例 #1
0
async def delete_exam(r: str, u: int):
    """Delete exam from database

    :param r: Request
    :param u: User ID who added the exam
    :return: Result of operation. Success or fail as string
    """
    sql = db.cursor().execute(
        "DELETE FROM exams WHERE examId = ? AND examUser = ?", (r, u)).rowcount
    db.commit()
    return r_exam_delete_success if (sql != 0) else r_exam_delete_fail
コード例 #2
0
async def get_group_by_user(user_id: int):
    """Gets name of the group of a specific user

    :param user_id: UserID (peer id for group chats)
    :return: Name of the group
    """
    u = await get_user(user_id)
    if u:
        g = db.cursor().execute("SELECT * FROM groups WHERE groupId=?", (u.group_peer_id,)).fetchone()
        return GroupClass(group_id=g['groupId'],
                          name=g['groupName'],
                          admin_id=g['groupAdmin'])
コード例 #3
0
ファイル: teachers.py プロジェクト: sadellie/sadBot
def add_teacher(req: str, user_id: int):
    """
    Add teacher to database
    
    :param user_id: User id, who is adding
    :param req: Request
    :return: Result
    """
    if req.lower() == "имя=предмет":
        return "🤬 Чел, ты... [Имя=Предмет это лишь пример]"
    # We create list, where 0 is Teacher, and 1 is Class
    try:
        req = req.split("=")
        req = (req[0], req[1], req[1].lower(), user_id
               )  # Teacher, Class, Searchable(we search in this column), User
    except IndexError:
        return r_teacher_add_help
    sql = "INSERT INTO teachers (teacherName, teacherClass, teacherClassSearchable, userId) VALUES (?, ?, ?, ?)"
    db.cursor().execute(sql, req)
    db.commit()
    return r_teacher_add_success.format(req[0], req[1])
コード例 #4
0
ファイル: teachers.py プロジェクト: sadellie/sadBot
def delete_teacher(req: int, user_id: int):
    """
    Delete teacher from database

    :param req: Request, class name
    :param user_id: User id
    :return: Result (success or fail)
    """
    sql = db.cursor().execute(
        "DELETE FROM teachers WHERE teacherId = ? AND userId = ?",
        (req, user_id)).rowcount
    db.commit()
    return r_teacher_delete_success if (
        sql != 0) else r_teacher_delete_fail  # Not 0 means deleted
コード例 #5
0
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
"""Exams functions"""

from datetime import datetime

from bot.base import db
from bot.exams_vocabulary import *
from bot.user_functions import get_user

cur = db.cursor()


async def add_exam(r: str, u: int):
    """Add exam to database

    :param r: Request
    :param u: User ID who added the exam.
    :return: Operation result. Success or fail (with error description)
    """
    user = await get_user(u)
    if not user:  # This is case is mostly impossible but still there
        return r_exam_add_fail_not_reg

    # Must be 2 parameters examDate and examGroup
    request = r.split('=')