예제 #1
0
def getUser(user_id):
    db = connect()
    cursor = db.cursor(prepared=True)
    query = "SELECT * FROM members WHERE chat_id = ?"

    try:
        cursor.execute(query, (str(user_id), ))
    except:
        print("query failed")
        return

    result = cursor.fetchall()

    try:
        person = result[0]

        chat_id = person[0]
        name = person[1]
        surname = person[2]
        nickname = person[3]
        number = person[4]
        bday = person[5]
        delays = person[6]
        absences = person[7]
        fines0 = person[8]
        fines1 = person[9]
        active = person[10]

    except IndexError:
        print("can not create user bean")
        return

    return User(chat_id, name, surname, nickname, number, bday, delays,
                absences, fines0, fines1, active)
예제 #2
0
def get_id_active():
    db = connect()
    cursor = db.cursor(prepared=True)
    query = "SELECT chat_id, active FROM members"

    try:
        cursor.execute(query)
    except:
        print("query failed")
        return

    result = cursor.fetchall()

    people = []
    for person in result:
        try:
            chat_id = person[0]
            active = person[1]

            user = User(chat_id=chat_id, active=active)
            people.append(user)

        except IndexError:
            print("can not create user bean")

    return people
예제 #3
0
파일: Blog.py 프로젝트: poznas/OpenX
 def load_users(self, link):
     with urllib.request.urlopen(link) as url:
         users_data = json.loads(url.read().decode('utf8'))
         for user in users_data:
             self.users.append(
                 User(user["id"], user["username"],
                      user["address"]["geo"]["lat"],
                      user["address"]["geo"]["lng"]))
예제 #4
0
def getUserBday():
    db = connect()
    cursor = db.cursor(prepared=True)
    query = "SELECT surname, nickname, bday, active " \
            "FROM members " \
            "WHERE DATE_FORMAT(bday, '%m-%d') = DATE_FORMAT(NOW(), '%m-%d')"

    cursor.execute(query)

    result = cursor.fetchall()

    people = []
    for person in result:
        people.append(
            User(surname=person[0],
                 nickname=person[1],
                 bday=person[2],
                 active=person[3]))

    return people
예제 #5
0
def register(update, context):
    save_command(update, "register")
    if check_permission(update.message.chat_id) > 0:
        context.bot.send_message(text=text.unauthorized,
                                 chat_id=update.message.chat_id)
        return

    try:
        chat_id = context.args[0]
        name = context.args[1]
        surname = context.args[2]
        bday = context.args[3]

        bday_array = bday.split("-")
        bday_year = int(bday_array[0])
        bday_month = int(bday_array[1])
        bday_day = int(bday_array[2])
    except IndexError:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=text.wrong_args_new_user)
        return

    try:
        bday_date = datetime.date(year=bday_year,
                                  month=bday_month,
                                  day=bday_day)
    except:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=text.wrong_data_format)
        return

    result = userDao.create_new_user(
        User(chat_id=chat_id, name=name, surname=surname, bday=bday_date))

    if result == 0:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=text.insert_success)
    elif result == 1:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=text.chat_id_already_exist)
예제 #6
0
def getUserByFullName(name, surname):
    db = connect()
    cursor = db.cursor(prepared=True)
    query = "SELECT * FROM members WHERE name = ? && surname = ?"

    try:
        cursor.execute(query, (str(name), str(surname)))
    except:
        print("query failed")
        return

    result = cursor.fetchall()

    people = []
    for person in result:
        try:
            chat_id = person[0]
            name = person[1]
            surname = person[2]
            nickname = person[3]
            number = person[4]
            bday = person[5]
            delays = person[6]
            absences = person[7]
            fines0 = person[8]
            fines1 = person[9]
            active = person[10]

            user = User(chat_id, name, surname, nickname, number, bday, delays,
                        absences, fines0, fines1, active)
            people.append(user)

        except IndexError:
            print("can not create user bean")

    return people
예제 #7
0
파일: UserEnum.py 프로젝트: Meldanen/bonko
class UserEnum(Enum):
    GIANNAKIS = User(294577564603645952, RoleEnum.PLEB)

    BONKO = User(842351473408344064, RoleEnum.ADMIN)

    ANTI_BONKO = User(879640212697931786, RoleEnum.ADMIN)

    MELDANEN = User(164447968332611584, RoleEnum.MEGUS)

    MELON = User(186521813285601280, RoleEnum.ADMIN)

    JOSEPH = User(173766017258881024, RoleEnum.ADMIN)

    SIBLING = User(319171521354530818, RoleEnum.RESTRICTED)

    CON = User(318437163169611776, RoleEnum.RESTRICTED)

    SIBLINGS_SIBLING = User(181353937662771200, RoleEnum.PLEB)

    NYROID = User(318425980073148418, RoleEnum.PLEB)

    QUILLBOT = User(570689271514660881, RoleEnum.PLEB)

    @staticmethod
    def is_good_person(id: int) -> bool:
        return id in [
            UserEnum.MELDANEN.value.id, UserEnum.JOSEPH.value.id,
            UserEnum.MELON.value.id
        ]

    @staticmethod
    def is_giannakis(id: int) -> bool:
        return id == UserEnum.GIANNAKIS.value.id

    @staticmethod
    def is_megus(id: int) -> bool:
        return id == UserEnum.MELDANEN.value.id

    @staticmethod
    def is_bonko(id: int) -> bool:
        return id == UserEnum.BONKO.value.id

    @staticmethod
    def is_melon(id: int) -> bool:
        return id == UserEnum.MELON.value.id

    @staticmethod
    def is_nyroid(id: int) -> bool:
        return id == UserEnum.NYROID.value.id

    @staticmethod
    def is_anti_bonko(id: int) -> bool:
        return id == UserEnum.ANTI_BONKO.value.id

    @staticmethod
    def is_quillbot(id: int) -> bool:
        return id == UserEnum.QUILLBOT.value.id

    @staticmethod
    def get_from_id(id):
        for user in UserEnum:
            if user.value.id == id:
                return user.value
        return None

    @staticmethod
    async def get_user_id(members: List, username: str) -> int:
        for member in members:
            if username.lower() in member.name.lower():
                return member.id

    @staticmethod
    async def get_user(members: List, username: str, mention: bool) -> str:
        if mention:
            user_id = await UserEnum.get_user_id(members, username)
            return UserEnum.format_user_id_for_mention(str(user_id))
        else:
            return username

    @staticmethod
    async def get_giannakis(mention: bool) -> str:
        if mention:
            return UserEnum.format_user_id_for_mention(
                str(UserEnum.GIANNAKIS.value))
        else:
            return "giannaki"

    @staticmethod
    def format_user_id_for_mention(user_id: str) -> str:
        return "<@!" + user_id + ">"